我是 bert 的初学者,我正在尝试使用 GitHub 上提供的 bert 文件:https : //github.com/google-research/bert
但是pip install bert在终端中安装bert后,我无法从bert导入文件(如run_classifier、优化等)。我尝试在 jupiter notebook 中运行以下代码:
import bert
from bert import run_classifier
Run Code Online (Sandbox Code Playgroud)
错误是:
ImportError: cannot import name 'run_classifier'
Run Code Online (Sandbox Code Playgroud)
然后我在中找到了名为“bert”的文件\anaconda3\lib\python3.6\site-packages,里面没有名为“run_classifier”、“optimization”等的python文件。所以我从 GitHub 下载了这些文件,并自己将它们放入文件 'bert' 中。完成此操作后,我可以导入 run_classifier。
然而,另一个问题出现了。尽管我可以导入它们,但我无法使用文件中的函数。例如,convert_to_unicodetokenization.py 中有一个函数:
Help on module bert.tokenization in bert:
NAME
bert.tokenization - Tokenization classes.
FUNCTIONS
convert_to_unicode(text)
Converts `text` to Unicode (if it's not already), assuming utf-8 input.
Run Code Online (Sandbox Code Playgroud)
然后我尝试了这个:
import tokenization from bert
convert_to_unicode('input.txt')
Run Code Online (Sandbox Code Playgroud)
错误是:
NameError: name 'convert_to_unicode' is not defined
Run Code Online (Sandbox Code Playgroud)
然后我尝试: …