解決策。AttributeError: module 'tensorflow.keras.optimizers' has no attribute 'experimental'
環境
windows10 python3.7.2 GPUなしpc
エラー
Traceback (most recent call last): File "Fine_Tune_BERT_for_Text_Classification_with_TensorFlow.py", line 118, in <module> from official.nlp import optimization File "C:\Users\XYZZ0\AppData\Local\Programs\Python\Python37\lib\site-packages\official\nlp\optimization.py", line 21, in <module> from official.modeling.optimization import legacy_adamw File "C:\Users\XYZZ0\AppData\Local\Programs\Python\Python37\lib\site-packages\official\modeling\optimization\__init__.py", line 23, in <module> from official.modeling.optimization.optimizer_factory import OptimizerFactory File "C:\Users\XYZZ0\AppData\Local\Programs\Python\Python37\lib\site-packages\official\modeling\optimization\optimizer_factory.py", line 36, in <module> 'adamw_experimental': tf.keras.optimizers.experimental.AdamW, AttributeError: module 'tensorflow.keras.optimizers' has no attribute 'experimental'
対象プログラム
https://github.com/shrikantnaidu/BERT-for-Text-Classification-with-TensorFlow Fine_Tune_BERT_for_Text_Classification_with_TensorFlow.ipynbをpyファイルに変換
解決策
python -m pip install "tf-models-official<2.4"
上記の前の状態。tensorflow と tf-models-officialのバージョンが不一致でした。
tensorflow 2.3.0 tf-models-official 2.10.1
コメント
ensorflow と tf-models-officialのバージョンは、一致させるのが、基本だと思います。