Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

extractSummary

문서에서 요약 추출

R2020a 이후

설명

예제

summary = extractSummary(documents)는 입력 문서 중에서 요약으로 사용할 문서를 일부 선택한 후 tokenizedDocument 배열로 반환합니다.

예제

[summary,scores] = extractSummary(documents)는 요약 문서를 선택하는 데 사용된 중요도 점수도 반환합니다. 이 경우 scores(i)summary(i)의 점수를 나타냅니다.

예제

[summary,scores] = extractSummary(documents,Name,Value)는 하나 이상의 이름-값 쌍의 인수를 사용하여 옵션을 추가로 지정합니다.

예제

모두 축소

토큰화된 문서로 구성된 배열을 만듭니다.

str = [
    "The quick brown fox jumped over the lazy dog."
    "The fox jumped over the dog."
    "The lazy dog saw a fox jumping."
    "There seem to be animals jumping other animals."
    "There are quick animals and lazy animals"];
documents = tokenizedDocument(str);

extractSummary 함수를 사용하여 문서 요약을 추출합니다. 기본적으로 이 함수는 입력 문서의 1/10만큼을 올림한 양을 선택합니다.

summary = extractSummary(documents)
summary = 
  tokenizedDocument:

   10 tokens: The quick brown fox jumped over the lazy dog .

더 많은 양의 요약을 지정하려면 'SummarySize' 옵션을 사용하십시오. 3개 문서 분량의 요약을 추출합니다.

summary = extractSummary(documents,'SummarySize',3)
summary = 
  3x1 tokenizedDocument:

    10 tokens: The quick brown fox jumped over the lazy dog .
     7 tokens: The fox jumped over the dog .
     9 tokens: There seem to be animals jumping other animals .

토큰화된 문서로 구성된 배열을 만듭니다.

str = [
    "The quick brown fox jumped over the lazy dog."
    "The fox jumped over the dog."
    "The lazy dog saw a fox jumping."
    "There seem to be animals jumping over other animals."
    "There are quick animals and lazy animals"];
documents = tokenizedDocument(str);

3개 문서 분량의 요약을 추출합니다. 두 번째 출력값 scores에 요약 문서의 중요도 점수가 들어 있습니다.

[summary,scores] = extractSummary(documents,'SummarySize',3)
summary = 
  3x1 tokenizedDocument:

    10 tokens: The quick brown fox jumped over the lazy dog .
    10 tokens: There seem to be animals jumping over other animals .
     7 tokens: The fox jumped over the dog .

scores = 3×1

    0.2426
    0.2174
    0.1911

점수를 막대 차트로 시각화합니다.

figure
bar(scores)
xlabel("Summary Document")
ylabel("Score")
title("Summary Document Importance")

Figure contains an axes object. The axes object with title Summary Document Importance, xlabel Summary Document, ylabel Score contains an object of type bar.

단일 문서를 요약하려면 그 문서를 문장으로 구성된 배열로 분할한 다음 extractSummary 함수를 사용해야 합니다.

문서를 포함하는 string형 스칼라를 만듭니다.

str = ...
    "There is a quick fox. The fox is brown. There is a dog which " + ...
    "is lazy. The dog is very lazy. The fox jumped over the dog. " + ...
    "The quick brown fox jumped over the lazy dog.";

splitSentences 함수를 사용하여 문자열을 문장으로 분할합니다.

str = splitSentences(str)
str = 6x1 string
    "There is a quick fox."
    "The fox is brown."
    "There is a dog which is lazy."
    "The dog is very lazy."
    "The fox jumped over the dog."
    "The quick brown fox jumped over the lazy dog."

문장들을 포함하는 토큰화된 문서 배열을 만듭니다.

documents = tokenizedDocument(str)
documents = 
  6x1 tokenizedDocument:

     6 tokens: There is a quick fox .
     5 tokens: The fox is brown .
     8 tokens: There is a dog which is lazy .
     6 tokens: The dog is very lazy .
     7 tokens: The fox jumped over the dog .
    10 tokens: The quick brown fox jumped over the lazy dog .

extractSummary 함수를 사용하여 문장에서 요약을 추출합니다. 3개 문서 분량의 요약을 반환하기 위해 'SummarySize' 옵션을 3으로 설정하고, 요약 문서가 입력 문서와 동일한 순서로 표시되도록 하기 위해 'OrderBy' 옵션을 'position'으로 설정합니다.

summary = extractSummary(documents,'SummarySize',3,'OrderBy','position')
summary = 
  3x1 tokenizedDocument:

     6 tokens: There is a quick fox .
     7 tokens: The fox jumped over the dog .
    10 tokens: The quick brown fox jumped over the lazy dog .

joinWords 함수를 사용해 문서를 문자열로 변환한 후 join 함수를 사용해 문장을 연결하여 문장을 단일 문서로 재구성합니다.

sentences = joinWords(summary);
summaryStr = join(sentences)
summaryStr = 
"There is a quick fox . The fox jumped over the dog . The quick brown fox jumped over the lazy dog ."

replace 함수를 사용하여 주위에 있는 문장 부호 문자를 제거합니다.

punctuationRight = ["." "," "’" ")" ":" "?" "!"];
summaryStr = replace(summaryStr," " + punctuationRight,punctuationRight);

punctuationLeft = ["(" "‘"];
summaryStr = replace(summaryStr,punctuationLeft + " ",punctuationLeft)
summaryStr = 
"There is a quick fox. The fox jumped over the dog. The quick brown fox jumped over the lazy dog."

입력 인수

모두 축소

입력 문서로, tokenizedDocument 배열로 지정됩니다.

이름-값 인수

선택적 인수 쌍을 Name1=Value1,...,NameN=ValueN으로 지정합니다. 여기서 Name은 인수 이름이고 Value는 대응값입니다. 이름-값 인수는 다른 인수 뒤에 와야 하지만, 인수 쌍의 순서는 상관없습니다.

R2021a 이전 릴리스에서는 각 이름과 값을 쉼표로 구분하고 Name을 따옴표로 묶으십시오.

예: extractSummary(documents,'ScoringMethod','lexrank')documents에서 요약을 추출하고 점수화 방법 옵션을 'lexrank'로 설정합니다.

발췌 요약에 사용되는 점수화 방법으로, 'ScoringMethod'와 함께 다음 중 하나가 쉼표로 구분되어 지정됩니다.

  • 'textrank' – TextRank 알고리즘을 사용합니다.

  • 'lexrank' – LexRank 알고리즘을 사용합니다.

  • 'mmr' – MMR 알고리즘을 사용합니다.

MMR 점수화에 대한 쿼리 문서로, 'Query'와 함께 tokenizedDocument 스칼라, 단어로 구성된 string형 배열 또는 문자형 벡터로 구성된 셀형 배열이 쉼표로 구분되어 지정됩니다. 'Query'tokenizedDocument 스칼라가 아닌 경우 이는 단일 문서를 나타내고 각 요소가 단어인 행 벡터여야 합니다.

이 옵션은 'ScoringMethod''mmr'인 경우에만 효력이 있습니다.

요약 크기로, 'SummarySize'와 함께 다음 중 하나가 쉼표로 구분되어 지정됩니다.

  • (0,1) 범위의 스칼라 – 지정된 비율에 해당하는 분량을 올림한 만큼의 입력 문서를 추출합니다. 이 경우 요약 문서의 개수는 ceil(SummarySize*numDocuments)입니다. 여기서 numDocuments는 입력 문서의 개수입니다.

  • 양의 정수 – 지정된 개수만큼의 문서로 구성된 요약을 추출합니다. SummarySize가 입력 문서 수보다 크거나 같으면 이 함수는 'OrderBy' 옵션에 따라 정렬된 입력 문서를 반환합니다.

    Inf'OrderBy' 옵션에 따라 정렬된 입력 문서를 반환합니다.

데이터형: double

요약 문서의 순서로, 'OrderBy'와 함께 다음 중 하나가 쉼표로 구분되어 지정됩니다.

  • 'score''ScoringMethod' 옵션에 따라 점수순으로 문서를 정렬합니다.

  • 'position' – 입력 문서의 문서 순서를 유지합니다.

출력 인수

모두 축소

추출된 요약으로, tokenizedDocument 배열로 반환됩니다. 요약은 documents의 일부이며, 'OrderBy' 옵션에 따라 정렬됩니다.

요약 문서 점수로, 벡터로 반환됩니다. 여기서 scores(i)'ScoringMethod' 옵션에 따른 j번째 요약 문서의 점수입니다. 점수는 'OrderBy' 옵션에 따라 정렬됩니다.

버전 내역

R2020a에 개발됨