Bert: AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Optimizer'

Created on 19 Aug 2020  路  5Comments  路  Source: google-research/bert

Hello! I runed this source code but I have an issue.
Traceback (most recent call last):
File "f:\studying\Artificial Intelligence\tensorflow\overimagination\bert\bert-master\run_classifier.py", line 25, in
import optimization
File "f:\studying\Artificial Intelligence\tensorflow\overimagination\bert\bert-master\optimization.py", line 87, in
class AdamWeightDecayOptimizer(tf.train.Optimizer):
AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Optimizer'

Most helpful comment

I finally figured it out. It seems that the Optimizer class has been deprecated in the 2.x versions of Tensorflow. As this issue can attest, you will need to install an older version of Python too (I used 3.7). You can then run python3.7 -m pip install tensorflow-gpu==1.15.0 (or just tensorflow==1.15.0 for the CPU version) and you should have the correct version installed. That fixed it for me.

All 5 comments

Same here. Using Ubuntu 20.04, Python 3.8.2 and Tensorflow-GPU 2.3.0.

I'm having this error as well.
Does anyone have an idea to resolve this issue?
Thanks

I finally figured it out. It seems that the Optimizer class has been deprecated in the 2.x versions of Tensorflow. As this issue can attest, you will need to install an older version of Python too (I used 3.7). You can then run python3.7 -m pip install tensorflow-gpu==1.15.0 (or just tensorflow==1.15.0 for the CPU version) and you should have the correct version installed. That fixed it for me.

@miutamihai worked for me too

Hi, raised a PR #1155 to resolve this issue for tf versions greater than 2.0.
Thanks

Was this page helpful?
0 / 5 - 0 ratings