我正在尝试从英国广播公司运行示例代码
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)我使用Pythonv3.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.有什么解决办法吗?
更新: my requirements.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发布于 2021-10-03 09:10:12
我遇到了与您完全相同的问题,但在Tensorflow 2.6.0和Python3.9.1中使用。下面的解决方案同时适用于CPU和GPU。
使用修改后的TF1示例
以下步骤使TensorFlow集线器示例工作:
pip install tensorflow-textimport tensorflow_text as text添加到Pythontf.disable_eager_execution()整个程序如下所示:
import tensorflow.compat.v1 as tf
import tensorflow_hub as hub
import tensorflow_text as text
tf.disable_eager_execution()
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_documents = text_generator(input_documents)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.tables_initializer())
final_output = sess.run(output_documents)
print(final_output)与KerasLayer (TF2)
尽管文档没有提到这一点,但它实际上似乎适用于用于TF2模型的TF2。如果您可以接受在控制台中收到大量警告,则应该这样做:
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_text as text
text_generator = hub.KerasLayer('https://tfhub.dev/google/bertseq2seq/roberta24_bbc/1')
input_documents = tf.constant(['This is text from the first document.',
'This is text from the second document.'])
output_documents = text_generator(input_documents)
print(output_documents)请注意,在这种情况下,文档需要包装在tf.constant中才能工作。
注意事项:您需要更长的文档文本才能得到有意义的摘要。这两个例子(例如:“这是第一份文件的案文”)没有摘要。
发布于 2020-09-19 13:57:58
Sentencepiece操作系统已被移动到单独的包tf_sentencepiece中。
pip install tf_sentencepiece如果脚本没有完全工作,您可能还必须在脚本开始时手动导入它。
https://stackoverflow.com/questions/63962563
复制相似问题