【问题标题】:Document similarity in Spacy vs Word2VecSpacy 与 Word2Vec 中的文档相似性
【发布时间】:2018-04-11 05:37:30
【问题描述】:

我有一个大约 12k 文档的利基语料库,我想测试其中具有相似含义的近乎重复的文档 - 想想关于不同新闻机构报道的同一事件的文章。

我尝试过 gensim 的 Word2Vec,即使测试文档在语料库中,它也给了我可怕的相似度分数( 0.9。我测试了 SpaCy 最相似的文档,但大部分都没用。

这是相关代码。

tfidf = models.TfidfModel(corpus)
corpus_tfidf = tfidf[corpus]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
lsi = models.LsiModel(corpus, id2word=dictionary, num_topics=40)
doc = preprocess(query)
vec_bow = dictionary.doc2bow(doc)
vec_lsi_tfidf = lsi[tfidf[vec_bow]] # convert the query to LSI space
index = similarities.Similarity(corpus = corpus, num_features = len(dictionary), output_prefix = "pqr")
sims = index[vec_lsi_tfidf] # perform a similarity query against the corpus
most_similar = sorted(list(enumerate(sims)), key = lambda x:x[1])

for mid in most_similar[-100:]:
    print(mid, file_list[mid[0]])

使用 gensim,我找到了一种不错的方法,并进行了一些预处理,但相似度得分仍然很低。有没有人遇到过这样的问题,是否有一些有用的资源或建议?

【问题讨论】:

    标签: python-3.x nlp gensim spacy


    【解决方案1】:

    我会发表评论,但我没有足够的声誉!在 NLP 中,很容易陷入方法中而忘记预处理。

    1) 删除停用词/最常见的词

    2) 合并词对 - 查看 SpaCy 的文档

    即“New York City”代替“New”、“York”、“City”成为自己的独特代币

    https://spacy.io/usage/linguistic-features

    3) 使用 Doc2Vec 而不是 Word2Vec(由于您已经在使用 gensim,这应该不难弄清楚,它们有自己的实现)

    然后,一旦你完成了所有这些事情,你就会有文档向量,这可能会给你一个更好的分数。另外,请记住,您拥有的 12k 文档只是总体规划中的少量样本。

    【讨论】:

    • 感谢您的回复。我已经完成了 1 和 3,而 2 刚刚在我的待办事项上增加了 :)
    • 没问题我的朋友!除非其他人出现并给出更好的答案,否则您现在可以接受答案吗?
    猜你喜欢
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 2023-03-24
    • 2014-08-09
    • 2014-06-09
    相关资源
    最近更新 更多