我如何使用中型spaCy模型en_core_web_md来解析文档文件夹,从每个单词文档中获取单个向量,然后将它们平均在一起?
import spacy
nlp = spacy.load("en_core_web_md")
答案 0 :(得分:1)
首先,您必须使用python file io / op。
将所有文档加载到列表中#documents loaded into the python list.
documents_list = ['Hello, world','Here are two sentences.']
#Iterate over each document and initiate nlp instance.
for doc in documents_list:
doc_nlp = nlp(doc)
#this gives the average vector of each document.
print(doc_nlp.vector)
for token in doc_nlp:
#this gives the text of each word in the doc and their vector.
print(token.text,token.vector)
如果您需要任何澄清,请告诉我。