【发布时间】:2020-07-02 22:40:18
【问题描述】:
我该如何改变:
BERT_MODEL = "https://tfhub.dev/google/bert_multi_cased_L-12_H-768_A-12/1"
def create_tokenizer_from_hub_module():
"""Get the vocab file and casing info from the Hub module."""
with tf.Graph().as_default():
bert_module = hub.Module(BERT_MODEL)
tokenization_info = bert_module(signature="tokenization_info", as_dict=True)
with tf.Session() as sess:
vocab_file, do_lower_case = sess.run([tokenization_info["vocab_file"],
tokenization_info["do_lower_case"]])
return bert.tokenization.FullTokenizer(
vocab_file=vocab_file, do_lower_case=do_lower_case)
tokenizer = create_tokenizer_from_hub_module()
这样我就可以在没有 hub.Module() 调用的情况下加载本地 BERT 模型,因为它不适用于本地路径。
我从不同的网站下载了一个不同的 TF1 预训练模型,解压缩并存储在 /test/module/。
如果我在BERT_MODEL = "/test/module" 以上更改,我需要如何更改其余部分?我现在收到字符串错误,因为tokenization_info = bert_module(signature="tokenization_info", as_dict=True) 不起作用。
请帮助我是 TF 新手 - 请注意我需要使用 TF1,而不是 TF2。
注意:根据以下建议,我得到:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-11-a98e44536f87> in <module>()
9 return vocab_file, do_lower_case
10
---> 11 print(get_bert_tokenizer_info("/tmp/local_copy"))
12 # Will print: (b'/tmp/local_copy/assets/vocab.txt', False)
4 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_hub/registry.py in __call__(self, *args, **kwargs)
43 raise RuntimeError(
44 "Missing implementation that supports: %s(*%r, **%r)" % (
---> 45 self._name, args, kwargs))
46
47
RuntimeError: Missing implementation that supports: loader(*('/tmp/local_copy',), **{})
【问题讨论】: