Main Content

removeInfrequentNgrams

bag-of-n-grams 모델에서 낮은 빈도로 나오는 n-gram 제거

설명

예제

newBag = removeInfrequentNgrams(bag,count)는 bag-of-n-grams 모델 bag에서 최대 count번 나오는 n-gram을 제거합니다. 이 함수는 기본적으로 대/소문자를 구분합니다.

예제

newBag = removeInfrequentNgrams(bag,count,'NgramLengths',lengths)lengths로 지정된 길이의 n-gram만 제거합니다. 이 함수는 기본적으로 대/소문자를 구분합니다.

newBag = removeInfrequentNgrams(___,'IgnoreCase',true)는 대/소문자를 구분하지 않고 최대 count번 나오는 n-gram을 제거합니다. n-gram이 대/소문자만 다른 경우 개수가 합산됩니다.

예제

모두 축소

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

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

bag-of-n-grams 모델을 만듭니다. 바이그램(두 개의 단어) 및 트라이그램(세 개의 단어) 개수를 계산하도록 지정합니다.

bag = bagOfNgrams(documents,'NgramLengths',[2 3])
bag = 
  bagOfNgrams with properties:

          Counts: [154x18022 double]
      Vocabulary: ["fairest"    "creatures"    "desire"    "increase"    "thereby"    "beautys"    "rose"    "might"    "never"    "die"    "riper"    "time"    "decease"    "tender"    "heir"    "bear"    "memory"    "thou"    ...    ] (1x3092 string)
          Ngrams: [18022x3 string]
    NgramLengths: [2 3]
       NumNgrams: 18022
    NumDocuments: 154

총 2번 이하로 나오는 임의 길이의 n-gram을 제거합니다.

bag = removeInfrequentNgrams(bag,2)
bag = 
  bagOfNgrams with properties:

          Counts: [154x103 double]
      Vocabulary: ["thine"    "thy"    "self"    "sweet"    "thou"    "time"    "why"    "dost"    "upon"    "eye"    "thee"    "ten"    "beauty"    "love"    "wilt"    "dear"    "truth"    "own"    "yet"    "hast"    "mens"    ...    ] (1x73 string)
          Ngrams: [103x3 string]
    NgramLengths: [2 3]
       NumNgrams: 103
    NumDocuments: 154

총 4번 이하로 나오는 바이그램을 제거합니다.

bag = removeInfrequentNgrams(bag,4,'NgramLengths',2)
bag = 
  bagOfNgrams with properties:

          Counts: [154x41 double]
      Vocabulary: ["thine"    "thy"    "sweet"    "thou"    "dost"    "upon"    "why"    "thee"    "ten"    "love"    "dear"    "hast"    "true"    "mine"    "beauty"    "fair"    "own"    "self"    "art"    "times"    "shouldst"    ...    ] (1x30 string)
          Ngrams: [41x3 string]
    NgramLengths: [2 3]
       NumNgrams: 41
    NumDocuments: 154

입력 인수

모두 축소

입력 bag-of-n-grams 모델로, bagOfNgrams 객체로 지정됩니다.

개수 임계값으로, 양의 정수로 지정됩니다. 이 함수는 총 count번 이하로 나오는 n-gram을 제거합니다.

n-gram 길이로, 양의 정수 또는 양의 정수로 구성된 벡터로 지정됩니다.

lengths를 지정하면, 함수는 빈도가 낮으면서 지정된 길이를 갖는 n-gram을 제거합니다. lengths를 지정하지 않으면, 함수는 길이에 관계없이 빈도가 낮은 n-gram을 제거합니다.

예: [1 2 3]

출력 인수

모두 축소

출력 bag-of-n-grams 모델로, bagOfNgrams 객체로 반환됩니다.

버전 내역

R2018a에 개발됨