簡體   English   中英

平均來自文檔的向量

[英]Averaging Vectors from Documents

如何使用中等大小的spaCy模型en_core_web_md解析文檔文件夾,以從每個單詞文檔中獲取單個矢量,然后將它們平均在一起?

import spacy
nlp = spacy.load("en_core_web_md")

首先,您必須使用python文件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)

讓我知道您是否需要任何澄清。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM