我正在尝试从bertseq2seq/roberta24_bbc运行示例代码:
import tensorflow.compat.v1 as tf
import tensorflow_hub as hub
import sentencepiece
text_generator = hub.Module(
'https://tfhub.dev/google/bertseq2seq/roberta24_bbc/1')
input_documents = ['This is text from the first document.',
'This is text from the second document.']
output_summaries = text_generator(input_documents)
print(output_summaries)
我使用Python v3.7.4创建了一个虚拟环境,并按照网站上的说明安装了TFv1:
pip install "tensorflow>=1.15,<2.0"
pip install --upgrade tensorflow-hub
但是当我执行时,我得到以下错误:
Exception has occurred: NotFoundError
Graph ops missing from the python registry ({'SentencepieceOp', 'SentencepieceDetokenizeOp', 'SentencepieceTokenizeOp'})
are also absent from the c++ registry.
有没有办法解决这个问题
更新:myrequirements.txt
absl-py==0.10.0
astor==0.8.1
astunparse==1.6.3
cachetools==4.1.1
certifi==2020.6.20
chardet==3.0.4
gast==0.2.2
google-auth==1.21.2
google-auth-oauthlib==0.4.1
google-pasta==0.2.0
grpcio==1.32.0
h5py==2.10.0
idna==2.10
importlib-metadata==1.7.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
Markdown==3.2.2
mock==4.0.2
numpy==1.18.5
oauthlib==3.1.0
opt-einsum==3.3.0
protobuf==3.13.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
requests==2.24.0
requests-oauthlib==1.3.0
rsa==4.6
scipy==1.4.1
sentencepiece==0.1.92
six==1.15.0
tensorboard==1.15.0
tensorboard-plugin-wit==1.7.0
tensorflow==1.15.3
tensorflow-estimator==1.15.1
tensorflow-hub==0.9.0
tensorflow-text==1.15.1
termcolor==1.1.0
tf-sentencepiece==0.1.92
urllib3==1.25.10
Werkzeug==1.0.1
wrapt==1.12.1
zipp==3.1.0
Sentencepiece
操作已移动到单独的包^{如果脚本无法完全工作,您可能还必须在脚本开始时手动导入它
我的问题与您完全相同,但在Tensorflow 2.6.0和Python3.9.1中得到了解决。下面的解决方案同时适用于CPU和GPU
使用修改后的TF1示例
以下步骤使TensorFlow Hub示例工作:
pip install tensorflow-text
import tensorflow_text as text
添加到Python导入中tf.disable_eager_execution()
整个程序如下所示:
使用KerasLayer(TF2)
尽管文档没有提到它,但它实际上似乎与用于TF2模型的
KerasLayer
一起工作。如果您可以接受在控制台中获得大量的警告,那么这应该可以做到:注意,文档需要包装在
tf.constant
中才能在这种情况下工作注意:您需要更长的文档文本才能获得有意义的摘要。这两个示例(例如,“这是第一份文件中的文本”)未进行总结
相关问题 更多 >
编程相关推荐