NLP 계산 문서 유사도 doc2vec

1908 단어 NLP
import gensim

outp1 = 'D:\python_noweightpathway\TIA\docmodel'
file = open(u'D:\python_noweightpathway\TIA\TIAxmmc.txt', encoding='utf-8')
# fileghdjid = open(u'D:\python_noweightpathway\TIA\TIA.txt', encoding='utf-8')
# ghdjids = []
# for ghdjid in fileghdjid:
#     ghdjids.append(ghdjid)
# i = 0
# for line in file:
#     LabeledSentence(words=line.split(), labels=['SENT_%s' % ghdjids[i]])
#     i = i + 1
documents = gensim.models.doc2vec.TaggedLineDocument(file)
model = gensim.models.Doc2Vec(documents, size=100, window=8, min_count=100, workers=8)
model.save(outp1)

모델 읽기
import gensim

model=gensim.models.Doc2Vec.load("D:\python_noweightpathway\TIA\docmodel")
print(model.docvecs.most_similar(4))
print(model.docvecs.similarity(2,12))

문방향량은 사실 단어방향량의 모델과 같다. 단지 훈련할 때 문서 id도 하나의 단어로 훈련한다. 그러면 문서 id는 문서 아래의 모든 단어의 정보를 배워서 하나의 문방향량을 만들 수 있다.

좋은 웹페이지 즐겨찾기