이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.
removeWords
문서 또는 bag-of-words 모델에서 선택한 단어 제거
구문
설명
는 지정된 단어를 newDocuments
= removeWords(documents
,words
)documents
에서 제거합니다. 이 함수는 기본적으로 대/소문자를 구분합니다.
는 위에 열거된 구문 중 하나를 사용하여 단어를 제거하며 대/소문자를 무시합니다.newDocuments
= removeWords(___,'IgnoreCase',true)
는 newDocuments
= removeWords(documents
,idx
)documents.Vocabulary
에 있는 단어의 숫자형 또는 논리형 인덱스 idx
를 지정하여 단어를 제거합니다. 이 구문은 newDocuments = removeWords(documents,documents.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
Bag-of-Words 모델에서 불용어 제거하기
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
인덱스를 사용하여 Bag-of-Words 모델에서 단어 제거하기
숫자형 인덱스로 구성된 벡터를 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
입력 인수
documents
— 입력 문서
tokenizedDocument
배열
입력 문서로, tokenizedDocument
배열로 지정됩니다.
bag
— 입력 bag-of-words 모델
bagOfWords
객체
입력 bag-of-words 모델로, bagOfWords
객체로 지정됩니다.
words
— 제거할 단어
string형 벡터 | 문자형 벡터 | 문자형 벡터로 구성된 셀형 배열
제거할 단어로, string형 벡터, 문자형 벡터 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다. words
를 문자형 벡터로 지정할 경우 이 함수는 해당 인수를 단일 단어로 처리합니다.
데이터형: string
| char
| cell
idx
— 단어집에 있는 제거할 단어의 인덱스
숫자형 인덱스로 구성된 벡터 | 논리형 인덱스로 구성된 벡터
제거할 단어의 인덱스로, 숫자형 인덱스로 구성된 벡터 또는 논리형 인덱스로 구성된 벡터로 지정됩니다. idx
의 인덱스는 입력 문서 또는 bag-of-words 모델의 Vocabulary
속성에서 단어의 위치에 해당합니다.
예: [1 5 10]
출력 인수
newDocuments
— 출력 문서
tokenizedDocument
배열
출력 문서로, tokenizedDocument
배열로 반환됩니다.
newBag
— 출력 bag-of-words 모델
bagOfWords
객체
출력 bag-of-words 모델로, bagOfWords
객체로 반환됩니다.
버전 내역
R2017b에 개발됨
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)