python - 如何使用 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
。
解决方案
推荐阅读
- redis - 后台匹配玩家
- java - 有没有办法用“限制性 API”实现构建器模式而不会太冗长
- android - firebase 函数输出(日志)与模拟器输出不同
- linux - Photon OS 4.0 作为 kubernets 节点 - 端口 10250 问题
- python - Pandas 在读取 .csv 文件时舍入高值
- vue.js - 作为道具传递的渲染组件
- css - flex-basis 的 auto 和 content 值有什么作用
- node.js - 在 Node.js 中合并多个二进制文件
- python - 迭代函数每次都会覆盖数据帧
- sql - 删除记录后 Postgres 查询变慢