tensorflow: AttributeError: module 'tensorflow._api.v2.train' has no attribute 'FtrlOptimizer'
Thank you for submitting a TensorFlow documentation issue. Per our GitHub policy, we only address code/doc bugs, performance issues, feature requests, and build/installation issues on GitHub.
The TensorFlow docs are open source! To get involved, read the documentation contributor guide: https://www.tensorflow.org/community/contribute/docs
URL(s) with the issue:
Please provide a link to the documentation entry, for example: https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/estimator/LinearClassifier
Description of issue (what needs changing):
FtrlOptimizer is not accessible from tf.train:
# Or estimator using the FTRL optimizer with regularization.
estimator = LinearClassifier(
feature_columns=[categorical_column_a,
categorical_feature_a_x_categorical_feature_b],
optimizer=tf.train.FtrlOptimizer(
learning_rate=0.1,
l1_regularization_strength=0.001
)
### should be optimizer=tf.keras.optimizers.Ftrl(...)
)
> AttributeError: module 'tensorflow._api.v2.train' has no attribute 'FtrlOptimizer'
Clear description
N/A
Correct links
N/A
Parameters defined
N/A
Returns defined
N/A
Raises listed and defined
N/A
Usage example
N/A
Request visuals, if applicable
N/A
Submit a pull request?
N/A
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 16 (7 by maintainers)
I had the same problem here:
while using
I get a deprecation warning only
see this notebook: https://github.com/loretoparisi/bert-movie-reviews-sentiment-classifier/blob/master/src/bert_sentiment_classifier.ipynb
Are you in TF 1.x or TF 2.0? In general,
tf.train.Optimizerhas been deprecated in TF 2.0, and you need to usetf.compat.v1.Optimizer(then the deprecation message shows up but it’s a warning only). In TF 2.0, the Keras optimzierstf.keras.optimizers.*are recommended to use.@loretoparisi I’m getting a similar error trying to run the Bert example here in my own Jupyter notebook running on EC2 (using TF2.0 on an Ubuntu deep learning AMI):
https://colab.research.google.com/github/google-research/bert/blob/master/predicting_movie_reviews_with_bert_on_tf_hub.ipynb#scrollTo=IhJSe0QHNG7U
from bert import tokenizationEven running the code in the Colab notebook gives a similar warning (although not an error):
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/bert/optimization.py:87: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.