Main Content

removeWords

문서 또는 bag-of-words 모델에서 선택한 단어 제거

설명

예제

newDocuments = removeWords(documents,words)는 지정된 단어를 documents에서 제거합니다. 이 함수는 기본적으로 대/소문자를 구분합니다.

예제

newBag = removeWords(bag,words)는 지정된 단어를 bag-of-words 모델 bag에서 제거합니다. 이 함수는 기본적으로 대/소문자를 구분합니다.

newDocuments = removeWords(___,'IgnoreCase',true)는 위에 열거된 구문 중 하나를 사용하여 단어를 제거하며 대/소문자를 무시합니다.

예제

newDocuments = removeWords(documents,idx)documents.Vocabulary에 있는 단어의 숫자형 또는 논리형 인덱스 idx를 지정하여 단어를 제거합니다. 이 구문은 newDocuments = removeWords(documents,documents.Vocabulary(idx))와 동일합니다.

예제

newBag = removeWords(bag,idx)bag.Vocabulary에 있는 단어의 숫자형 또는 논리형 인덱스 idx를 지정하여 단어를 제거합니다. 이 구문은 newBag = removeWords(bag,bag.Vocabulary(idx))와 동일합니다.

예제

모두 축소

단어로 구성된 string형 배열을 removeWords에 입력하여 문서로 구성된 배열에서 단어를 제거합니다.

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

documents = tokenizedDocument([
    "an example of a short sentence" 
    "a second short sentence"]);

단어 "short" 및 "second"를 제거합니다.

words = ["short" "second"];
newDocuments = removeWords(documents,words)
newDocuments = 
  2x1 tokenizedDocument:

    5 tokens: an example of a sentence
    2 tokens: a sentence

문서의 언어 세부 정보를 사용하여 디폴트 목록에 있는 불용어를 제거하려면 removeStopWords를 사용하십시오.

사용자 지정 목록에 있는 불용어를 제거하려면 removeWords 함수를 사용하십시오. stopWords 함수에서 반환된 불용어 목록을 시작점으로 사용할 수 있습니다.

예제 데이터를 불러옵니다. 파일 sonnetsPreprocessed.txt에는 셰익스피어 소네트의 전처리된 버전이 들어 있습니다. 파일에는 한 줄에 하나씩 소네트가 들어 있으며 단어가 공백으로 구분되어 있습니다. sonnetsPreprocessed.txt에서 텍스트를 추출하고, 추출한 텍스트를 새 줄 문자에서 문서로 분할한 후 그 문서를 토큰화합니다.

filename = "sonnetsPreprocessed.txt";
str = extractFileText(filename);
textData = split(str,newline);
documents = tokenizedDocument(textData);

처음 몇 개의 문서를 표시합니다.

documents(1:5)
ans = 
  5x1 tokenizedDocument:

    70 tokens: fairest creatures desire increase thereby beautys rose might never die riper time decease tender heir might bear memory thou contracted thine own bright eyes feedst thy lights flame selfsubstantial fuel making famine abundance lies thy self thy foe thy sweet self cruel thou art worlds fresh ornament herald gaudy spring thine own bud buriest thy content tender churl makst waste niggarding pity world else glutton eat worlds due grave thee
    71 tokens: forty winters shall besiege thy brow dig deep trenches thy beautys field thy youths proud livery gazed tatterd weed small worth held asked thy beauty lies treasure thy lusty days say thine own deep sunken eyes alleating shame thriftless praise praise deservd thy beautys thou couldst answer fair child mine shall sum count make old excuse proving beauty succession thine new made thou art old thy blood warm thou feelst cold
    65 tokens: look thy glass tell face thou viewest time face form another whose fresh repair thou renewest thou dost beguile world unbless mother fair whose uneard womb disdains tillage thy husbandry fond tomb selflove stop posterity thou art thy mothers glass thee calls back lovely april prime thou windows thine age shalt despite wrinkles thy golden time thou live rememberd die single thine image dies thee
    71 tokens: unthrifty loveliness why dost thou spend upon thy self thy beautys legacy natures bequest gives nothing doth lend frank lends free beauteous niggard why dost thou abuse bounteous largess thee give profitless usurer why dost thou great sum sums yet canst live traffic thy self alone thou thy self thy sweet self dost deceive nature calls thee gone acceptable audit canst thou leave thy unused beauty tombed thee lives th executor
    61 tokens: hours gentle work frame lovely gaze every eye doth dwell play tyrants same unfair fairly doth excel neverresting time leads summer hideous winter confounds sap checked frost lusty leaves quite gone beauty oersnowed bareness every summers distillation left liquid prisoner pent walls glass beautys effect beauty bereft nor nor remembrance flowers distilld though winter meet leese show substance still lives sweet

stopWords 함수의 출력값으로 시작하는 불용어 목록을 만듭니다.

customStopWords = [stopWords "thy" "thee" "thou" "dost" "doth"];

문서에서 사용자 지정 불용어를 제거하고 처음 몇 개의 문서를 표시합니다.

documents = removeWords(documents,customStopWords);
documents(1:5)
ans = 
  5x1 tokenizedDocument:

    62 tokens: fairest creatures desire increase thereby beautys rose might never die riper time decease tender heir might bear memory contracted thine own bright eyes feedst lights flame selfsubstantial fuel making famine abundance lies self foe sweet self cruel art worlds fresh ornament herald gaudy spring thine own bud buriest content tender churl makst waste niggarding pity world else glutton eat worlds due grave
    61 tokens: forty winters shall besiege brow dig deep trenches beautys field youths proud livery gazed tatterd weed small worth held asked beauty lies treasure lusty days say thine own deep sunken eyes alleating shame thriftless praise praise deservd beautys couldst answer fair child mine shall sum count make old excuse proving beauty succession thine new made art old blood warm feelst cold
    52 tokens: look glass tell face viewest time face form another whose fresh repair renewest beguile world unbless mother fair whose uneard womb disdains tillage husbandry fond tomb selflove stop posterity art mothers glass calls back lovely april prime windows thine age shalt despite wrinkles golden time live rememberd die single thine image dies
    52 tokens: unthrifty loveliness why spend upon self beautys legacy natures bequest gives nothing lend frank lends free beauteous niggard why abuse bounteous largess give profitless usurer why great sum sums yet canst live traffic self alone self sweet self deceive nature calls gone acceptable audit canst leave unused beauty tombed lives th executor
    59 tokens: hours gentle work frame lovely gaze every eye dwell play tyrants same unfair fairly excel neverresting time leads summer hideous winter confounds sap checked frost lusty leaves quite gone beauty oersnowed bareness every summers distillation left liquid prisoner pent walls glass beautys effect beauty bereft nor nor remembrance flowers distilld though winter meet leese show substance still lives sweet

숫자형 인덱스로 구성된 벡터를 removeWords에 입력하여 문서에서 단어를 제거합니다.

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

documents = tokenizedDocument([
    "I love MATLAB"
    "I love MathWorks"])
documents = 
  2x1 tokenizedDocument:

    3 tokens: I love MATLAB
    3 tokens: I love MathWorks

documents의 단어집을 표시합니다.

documents.Vocabulary
ans = 1x4 string
    "I"    "love"    "MATLAB"    "MathWorks"

숫자형 인덱스 [1 3]을 지정하여 문서에서 단어집의 첫 번째와 세 번째 단어를 제거합니다.

idx = [1 3];
newDocuments = removeWords(documents,idx)
newDocuments = 
  2x1 tokenizedDocument:

    1 tokens: love
    2 tokens: love MathWorks

또는 논리형 인덱스를 지정할 수 있습니다.

idx = logical([1 0 1 0]);
newDocuments = removeWords(documents,idx)
newDocuments = 
  2x1 tokenizedDocument:

    1 tokens: love
    2 tokens: love MathWorks

removeWords에 불용어 목록을 입력하여 bag-of-words 모델에서 불용어를 제거합니다. 불용어는 "a", "the", "in"과 같이 일반적으로 분석 전에 텍스트에서 제거되는 단어입니다.

documents = tokenizedDocument([
    "an example of a short sentence" 
    "a second short sentence"]);
bag = bagOfWords(documents);
newBag = removeWords(bag,stopWords)
newBag = 
  bagOfWords with properties:

          Counts: [2x4 double]
      Vocabulary: ["example"    "short"    "sentence"    "second"]
        NumWords: 4
    NumDocuments: 2

숫자형 인덱스로 구성된 벡터를 removeWords에 입력하여 bag-of-words 모델에서 단어를 제거합니다.

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

documents = tokenizedDocument([
    "I love MATLAB"
    "I love MathWorks"]);
bag = bagOfWords(documents)
bag = 
  bagOfWords with properties:

          Counts: [2x4 double]
      Vocabulary: ["I"    "love"    "MATLAB"    "MathWorks"]
        NumWords: 4
    NumDocuments: 2

bag의 단어집을 표시합니다.

bag.Vocabulary
ans = 1x4 string
    "I"    "love"    "MATLAB"    "MathWorks"

숫자형 인덱스 [1 3]을 지정하여 bag-of-words 모델에서 단어집의 첫 번째와 세 번째 단어를 제거합니다.

idx = [1 3];
newBag = removeWords(bag,idx)
newBag = 
  bagOfWords with properties:

          Counts: [2x2 double]
      Vocabulary: ["love"    "MathWorks"]
        NumWords: 2
    NumDocuments: 2

또는 논리형 인덱스를 지정할 수 있습니다.

idx = logical([1 0 1 0]);
newBag = removeWords(bag,idx)
newBag = 
  bagOfWords with properties:

          Counts: [2x2 double]
      Vocabulary: ["love"    "MathWorks"]
        NumWords: 2
    NumDocuments: 2

입력 인수

모두 축소

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

입력 bag-of-words 모델로, bagOfWords 객체로 지정됩니다.

제거할 단어로, string형 벡터, 문자형 벡터 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다. words를 문자형 벡터로 지정할 경우 이 함수는 해당 인수를 단일 단어로 처리합니다.

데이터형: string | char | cell

제거할 단어의 인덱스로, 숫자형 인덱스로 구성된 벡터 또는 논리형 인덱스로 구성된 벡터로 지정됩니다. idx의 인덱스는 입력 문서 또는 bag-of-words 모델의 Vocabulary 속성에서 단어의 위치에 해당합니다.

예: [1 5 10]

출력 인수

모두 축소

출력 문서로, tokenizedDocument 배열로 반환됩니다.

출력 bag-of-words 모델로, bagOfWords 객체로 반환됩니다.

버전 내역

R2017b에 개발됨