【发布时间】:2021-10-11 14:59:55
【问题描述】:
我正在使用句子转换器进行语义搜索,但有时它不理解上下文含义并返回错误结果 例如。 BERT problem with context/semantic search in italian language
默认情况下,句子嵌入的向量边是78列,那么如何增加这个维度,以便它能够深入理解上下文的含义。
代码:
# Load the BERT Model
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('bert-base-nli-mean-tokens')
# Setup a Corpus
# A corpus is a list with documents split by sentences.
sentences = ['Absence of sanity',
'Lack of saneness',
'A man is eating food.',
'A man is eating a piece of bread.',
'The girl is carrying a baby.',
'A man is riding a horse.',
'A woman is playing violin.',
'Two men pushed carts through the woods.',
'A man is riding a white horse on an enclosed ground.',
'A monkey is playing drums.',
'A cheetah is running behind its prey.']
# Each sentence is encoded as a 1-D vector with 78 columns
sentence_embeddings = model.encode(sentences) ### how to increase vector dimention
print('Sample BERT embedding vector - length', len(sentence_embeddings[0]))
print('Sample BERT embedding vector - note includes negative values', sentence_embeddings[0])
【问题讨论】:
-
默认情况下,BERT(所谓的 BERT-base)词嵌入有 768 个维度,而不是 78 个。句子嵌入是句子中词向量的加权和。
标签: machine-learning nlp artificial-intelligence bert-language-model