首页 > 解决方案 > 如何使用 BERT 判断本站的文档相似度

问题描述

我想用 BERT 和这个站点脚本来做文档相似性。

from sentence_transformers import SentenceTransformer

def process_bert_similarity():
    # This will download and load the pretrained model offered by UKPLab.
    model = SentenceTransformer('bert-base-nli-mean-tokens')

    sentences = sent_tokenize(base_document)
    base_embeddings_sentences = model.encode(sentences)
    base_embeddings = np.mean(np.array(base_embeddings_sentences), axis=0)

但是,我无法理解如何使用此功能。

例如,当我想比较两个文本时,

aaa = 'Hello my friends'
bbb = 'Cannot buy me love'

aaa哪里是插入和的最佳位置bbb

标签: pythonnlpbert-language-model

解决方案


推荐阅读