-
Notifications
You must be signed in to change notification settings - Fork 676
/
NLP WORD2VEC
36 lines (26 loc) · 1.29 KB
/
NLP WORD2VEC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gensim, logging
from gensim.models import Word2Vec
from nltk import sent_tokenize, word_tokenize, pos_tag
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
documents = ["Human machine interface for lab abc computer applications",
"A survey of user opinion of computer system response time",
"The EPS user interface management system",
"System and human system engineering testing of EPS",
"Relation of user perceived response time to error measurement",
"The generation of random binary unordered trees",
"The intersection graph of paths in trees",
"Graph minors IV Widths of trees and well quasi ordering",
"Graph minors A survey"]
sentences=[]
for i in range(0,len(documents)):
sentences.append(word_tokenize(str(documents[i])))
import numpy as np
len(np.unique(np.concatenate(sentences)))
model = Word2Vec(sentences, size=10,min_count=1,window=5)
model.save('Word2Vec2.dict')
new_model = Word2Vec.load('Word2Vec2.dict')
print(new_model)
array=[np.ndarray.flatten(new_model[sentences[i]]) for i in range(0,len(documents))]
array
model.most_similar(positive=['Human', 'error'], negative=['trees'], topn=4)
new_model.similarity('computer', 'system')