首页 > 解决方案 > 使用 Bert 模型检查相似度 AttributeError: 'Embeddings' object has no attribute 'embed'

问题描述

我正在运行 Bert 模型来检查两个数据之间的相似性。但是我收到一个错误。

我正在使用的代码:

embeddings = TransformerWordEmbeddings('bert-base-multilingual-cased')
bert = Embeddings(bert)
models_bert = PolyFuzz(bert)
bert_match = models_bert.match(final_data12['Data'],data2['KPI - Extracted'])

我得到的错误如下:

AttributeError                            Traceback (most recent call last)
<ipython-input-23-5b43b8b3cc13> in <module>()
      2 bert = Embeddings(bert)
      3 models_bert = PolyFuzz(bert)
----> 4 bert_match = models_bert.match(final_data12['Data'],data2['KPI - Extracted'])

2 frames
/usr/local/lib/python3.7/dist-packages/polyfuzz/polyfuzz.py in match(self, from_list, to_list, top_n)
    134         # Custom models
    135         elif isinstance(self.method, BaseMatcher):
--> 136             self.matches = {self.method.model_id: self.method.match(from_list, to_list)}
    137             logging.info(f"Ran model with model id = {self.method.model_id}")
    138 

/usr/local/lib/python3.7/dist-packages/polyfuzz/models/_embeddings.py in match(self, from_list, to_list, embeddings_from, embeddings_to)
    108         """
    109         if not isinstance(embeddings_from, np.ndarray):
--> 110             embeddings_from = self._embed(from_list)
    111         if not isinstance(embeddings_to, np.ndarray):
    112             embeddings_to = self._embed(to_list)

/usr/local/lib/python3.7/dist-packages/polyfuzz/models/_embeddings.py in _embed(self, strings)
    125         for name in strings:
    126             sentence = Sentence(name)
--> 127             self.document_embeddings.embed(sentence)
    128             embeddings.append(sentence.embedding.cpu().numpy())
    129 

AttributeError: 'Embeddings' object has no attribute 'embed'

标签: pythonbert-language-model

解决方案


推荐阅读