AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'Optimizer' when importing BERT

限于喜欢 提交于 2021-02-11 14:44:14

问题


I'm am getting this error just in the being of importing my packages. I haven't been able to find the correct remedy to fix the issue. Any help is greatly appreciated.

From what I can tell it looks to maybe be a Tensorflow issue?

from sklearn.model_selection import train_test_split
import pandas as pd
import tensorflow as tf
import tensorflow_hub as hub
from datetime import datetime

import bert
from bert import run_classifier
from bert import optimization
from bert import tokenization

回答1:


You seem to have TensorFlow 2.x while the bert module uses TensorFlow 1.x. You can verify here that Tensorflow 1.x has the tf.train.Optimizer module while according to this, Tensorflow 2.x has no such module.

Make sure you install the Tensorflow version that bert requires



来源:https://stackoverflow.com/questions/60835983/attributeerror-module-tensorflow-core-api-v2-train-has-no-attribute-optimiz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!