2017-09-07 10 views
0

Gensim의 'Word2Vec'에 새로 왔습니다. 나는 텍스트 (Wikipedia : Machine Learning에서 추출한)에 대한 Word2Vec 모델을 구축하고 과 유사한 단어을 '기계 학습'으로 찾고 싶습니다.Gensim의 Word2Vec에서 model.most_similar를 사용합니다.

현재 코드는 다음과 같습니다.

# import modules & set up logging 
from gensim.models import Word2Vec 

sentences = "Machine learning is the subfield of computer science that, according to Arthur Samuel, gives computers the ability to learn without being explicitly programmed.[1][2][verify] Samuel, an American pioneer in the field of computer gaming and artificial intelligence, coined the term machine learning in 1959 while at IBM. Evolved from the study of pattern recognition and computational learning theory in artificial intelligence,[3] machine learning explores the study and construction of algorithms that can learn from and make predictions on data[4] – such algorithms overcome following strictly static program instructions by making data-driven predictions or decisions,[5]:2 through building a model from sample inputs. Machine learning is employed in a range of computing tasks where designing and programming explicit algorithms with good performance is difficult or infeasible; example applications include email filtering, detection of network intruders or malicious insiders working towards a data breach,[6] optical character recognition (OCR),[7] learning to rank, and computer vision." 
# train word2vec on the sentences 
model = Word2Vec(sentences, min_count=1) 
vocab = list(model.wv.vocab.keys()) 
print(vocab[:10]) 

그러나 vocab의 경우 한 문자 출력이 표시됩니다.

['M', 'a', 'c', 'h', 'i', 'n', 'e', ' ', 'l', 'r'] 

model.most_similar

답변

1

Word2Vec 클래스는 sentences 자사의 신체는 각각 개별 항목의 반복 가능한 원천이 될 것으로 예상 목록 외 사용하여 사용하여 most_similar_words를 얻기 위해 제발 도와주세요 단어 토큰.

단일 문자열을 제공합니다. 그것을 반복하면 개별 문자를 얻습니다. 그런 다음 개별 문자를 토큰 목록으로 해석하려고하면 여전히 단일 문자를 가져옵니다. 따라서 유일한 '단어'는 단일 문자입니다. 최소한

, 당신은 당신의 신체가 더 같이 구성 할 수 싶어 :

여전히 하나의 '문장', 그러나 그것은 분할에 공백이됩니다 않은 워드로
sentences = [ 
    "Machine learning is the subfield of computer science that, according to Arthur Samuel, gives computers the ability to learn without being explicitly programmed.[1][2][verify] Samuel, an American pioneer in the field of computer gaming and artificial intelligence, coined the term machine learning in 1959 while at IBM. Evolved from the study of pattern recognition and computational learning theory in artificial intelligence,[3] machine learning explores the study and construction of algorithms that can learn from and make predictions on data[4] – such algorithms overcome following strictly static program instructions by making data-driven predictions or decisions,[5]:2 through building a model from sample inputs. Machine learning is employed in a range of computing tasks where designing and programming explicit algorithms with good performance is difficult or infeasible; example applications include email filtering, detection of network intruders or malicious insiders working towards a data breach,[6] optical character recognition (OCR),[7] learning to rank, and computer vision.".split(), 
] 

토큰.

유용한 word2vec 결과에는 크고 다양한 텍스트 샘플이 필요하다는 점에 유의하십시오. 장난감 크기의 예제는 일반적으로 word2vec가 만드는 것으로 유명한 단어 유사성 또는 단어 상대 정렬 유형을 표시하지 않습니다.

+0

답변 해 주셔서 감사합니다. 모델은 "기계 학습"을 "기계", "학습"으로 보는 단어를 분리함으로써 하나의 해결책으로는 바이 그램을 사용할 수 있지만 그 다음에 3 단어의 단어를 놓칠 수 있습니까? 그런데이 단어 구문은 무엇입니까? –

+0

그런데 split()을 시도했지만 문자 출력으로 문자를 얻습니다. ( –

+1

예, 간단한 토큰 화로 '기계'와 '학습'이 분리됩니다. 'Word2Vec'에 전달되는 토큰을 결정하기 위해 데이터를 사전 처리하는 방법 Gensim은 통계적 빈도에 따라 쌍을 이루는 토큰을 바이그램으로 승격시킬 수있는'Phrases' 클래스를 포함하고 있습니다. 그러나 이것은 Word2Vec 조작과는 별개의 문제입니다 – gojomo