python - 使用 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'
解决方案
推荐阅读
- javascript - 如何从ajax成功访问json键值?
- selenium-webdriver - 引起:gherkin.parser.ParseError:解析错误在期望以下之一时找到scenario_outline:comment,row,tag。(当前 getState:示例
- sql - ORACLE中如何仅按一个字段分组?
- algorithm - 快速访问满足条件的第 n 个元素的数据结构
- laravel - 使用 Laravel 后端部署 Vue Cli 3 SPA
- excel - WinHttpRequest 因自动化错误而失败,但 XMLHTTP60 有效
- java - 并行运行两个单曲并处理场景
- nativescript-vue - 如何使用 JavaScript 在 NativeScript 中读取 CSS 变量
- c# - 从数据库中获取日期到 DateTimePicker
- c# - C# 更新 CA 颁发的证书