通用句子编码器类型错误修剪(文本)预期张量

2024-09-28 20:48:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经将universal Session encoder 2下载到一台没有互联网接入的计算机上,并解压缩到一个目标文件夹:“data”

import tensorflow as tf
import tensorflow_hub as hub

USE_embedder = hub.load(r'data/')

如果我像往常一样运行USE_embedder(['test']),我会得到错误:TypeError: 'Autotrackable' object is not callable.但是按照tensorflow文档,我认为我可以运行:

USE_embedder.signatures['default'](['test'])

但是我得到了类型错误:

TypeError: pruned(text: expected argument #0(zero-based to be a Tensor; got list(['test'])

当我可以从联网的计算机上运行它,从https://tfhub.dev/google/universal-sentence-encoder/2加载而不是提取的下载,我就可以很好地运行这样的东西。如何使模型能够嵌入文档中通常显示的文本(例如,USE_embedder(['text'])返回向量)

使用:Python 3.6.7、Tensorflow 2.4.1、Tensorflow_hub 0.11.0


Tags: text文档testimportencoderdatausetensorflow