removeNgrams
bag-of-n-grams 모델에서 n-gram 제거
구문
설명
예제
Bag-of-N-Grams 모델에서 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)
bag = bagOfNgrams with properties: Counts: [154×8799 double] Vocabulary: [1×3092 string] Ngrams: [8799×2 string] NgramLengths: 2 NumNgrams: 8799 NumDocuments: 154
상위 5개의 n-gram을 표시합니다.
topkngrams(bag,5)
ans=5×3 table
Ngram Count NgramLength
________________ _____ ___________
"thou" "art" 34 2
"mine" "eye" 15 2
"thy" "self" 14 2
"thou" "dost" 13 2
"mine" "own" 13 2
n-gram ["thou" "art"]
및 ["thou" "dost"]
를 모델에서 제거합니다. 새로운 상위 5개의 n-gram을 표시합니다.
ngrams = [... "thou" "art" "thou" "dost"]; bag = removeNgrams(bag,ngrams); topkngrams(bag,5)
ans=5×3 table
Ngram Count NgramLength
_________________ _____ ___________
"mine" "eye" 15 2
"thy" "self" 14 2
"mine" "own" 13 2
"thy" "sweet" 12 2
"thy" "love" 11 2
인덱스를 사용하여 Bag-of-N-Grams 모델에서 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)
bag = bagOfNgrams with properties: Counts: [154x8799 double] Vocabulary: ["fairest" "creatures" "desire" "increase" "thereby" "beautys" "rose" "might" "never" "die" "riper" "time" "decease" "tender" "heir" "bear" "memory" "thou" ... ] (1x3092 string) Ngrams: [8799x2 string] NgramLengths: 2 NumNgrams: 8799 NumDocuments: 154
모델에 있는 처음 10개의 n-gram을 표시합니다.
bag.Ngrams(1:10,:)
ans = 10x2 string
"fairest" "creatures"
"creatures" "desire"
"desire" "increase"
"increase" "thereby"
"thereby" "beautys"
"beautys" "rose"
"rose" "might"
"might" "never"
"never" "die"
"die" "riper"
9번째와 10번째 n-gram을 모델에서 제거합니다. 처음 10개의 n-gram의 새로운 목록을 표시합니다.
idx = [9 10]; bag = removeNgrams(bag,idx); bag.Ngrams(1:10,:)
ans = 10x2 string
"fairest" "creatures"
"creatures" "desire"
"desire" "increase"
"increase" "thereby"
"thereby" "beautys"
"beautys" "rose"
"rose" "might"
"might" "never"
"riper" "time"
"time" "decease"
입력 인수
bag
— 입력 bag-of-n-grams 모델
bagOfNgrams
객체
입력 bag-of-n-grams 모델로, bagOfNgrams
객체로 지정됩니다.
ngrams
— 제거할 n-gram
string형 배열 | 문자형 벡터 | 문자형 벡터로 구성된 셀형 배열
제거할 n-gram으로, string형 배열, 문자형 벡터 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다.
ngrams
가 string형 배열 또는 셀형 배열인 경우 크기는 NumNgrams
×maxN
입니다. 여기서 NumNgrams
는 n-gram의 개수이고, maxN
은 가장 큰 n-gram의 길이입니다. ngrams
가 문자형 벡터인 경우 이는 단일 단어(유니그램(unigram))를 나타냅니다.
ngrams(i,j)
의 값은 i
번째 n-gram 중 j
번째 단어입니다. i
번째 n-gram의 단어 수가 maxN
보다 작은 경우 ngrams
의 i
번째 행의 나머지 요소는 비어 있습니다.
예: ["An" ""; "An example"; "example" ""]
데이터형: string
| char
| cell
idx
— 제거할 n-gram의 인덱스
숫자형 인덱스로 구성된 벡터 | 논리형 인덱스로 구성된 벡터
제거할 n-gram의 인덱스로, 숫자형 인덱스로 구성된 벡터 또는 논리형 인덱스로 구성된 벡터로 지정됩니다. idx
의 인덱스는 bag.Ngrams
의 행에 해당합니다.
예: [1 5 10]
버전 내역
R2018a에 개발됨
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)