gpt4 book ai didi

python - 为什么pip install bert后不能导入bert中的函数

转载 作者:太空宇宙 更新时间:2023-11-04 08:26:31 25 4
gpt4 key购买 nike

我是 bert 的初学者,我正在尝试使用 GitHub 上提供的 bert 文件:https://github.com/google-research/bert

但是在终端使用pip install bert安装bert后,我无法从bert导入文件(如run_classifier、optimization等)。我尝试在 jupiter notebook 中运行以下代码:

import bert
from bert import run_classifier

错误是:

ImportError: cannot import name 'run_classifier'

然后我在\anaconda3\lib\python3.6\site-packages中找到名为'bert'的文件,里面没有'run_classifier','optimization'等python文件.所以我从 GitHub 下载了这些文件,并自己将它们放入文件“bert”中。完成此操作后,我可以导入 run_classifier。

然而,另一个问题出现了。尽管我可以导入它们,但我无法使用文件中的函数。比如tokenization.py中有一个函数convert_to_unicode:

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.

然后我试了一下:

import tokenization from bert
convert_to_unicode('input.txt')

错误是:

NameError: name 'convert_to_unicode' is not defined

然后我尝试了:

from tokenization import convert_to_unicode

错误是:

ModuleNotFoundError: No module named 'tokenization'

我真的很困惑。

最佳答案

您要查找的软件包是 bert-tensorflow,而不是 bert

bert-tensorflow是 Google 的 BERT 实现的 Python 包。
bert是一个序列化库。

关于python - 为什么pip install bert后不能导入bert中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56554380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com