NLP chapter 3 question


i tried import adam_v2, as well as just opt object but getting error

ValueError: Could not interpret optimizer identifier: <keras.src.optimizers.adam.Adam object at 0x78d78061c650>

1 Like

Apparently, there is a version incompatibility issue between Keras and TensorFlow that has been around for a long time. The solution differs for each version…

For more information, search for the version you want to use…

it works for me now after

“”"

setting these to tackle:

ValueError: Could not interpret optimizer identifier: <keras.src.optimizers.adam.Adam object at 0x7cc289675050>

“”"

!pip install --upgrade transformers

!pip install tf-keras

import os

os.environ[‘TF_USE_LEGACY_KERAS’] = ‘1’

1 Like

ValueError Traceback (most recent call last)
in <cell line: 2>()
1 optimizer = Adam(learning_rate=2e-5)
----> 2 model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
3 optimizer=opt,
4 metrics=[“accuracy”])
5 tf.keras.backend.set_value(model.optimizer.learning_rate, 2e-5)

/usr/local/lib/python3.10/dist-packages/transformers/modeling_tf_utils.py in compile(self, optimizer, loss, metrics, loss_weights, weighted_metrics, run_eagerly, steps_per_execution, **kwargs)
1561 # This argument got renamed, we need to support both versions
1562 if “steps_per_execution” in parent_args:
→ 1563 super().compile(
1564 optimizer=optimizer,
1565 loss=loss,

/usr/local/lib/python3.10/dist-packages/tf_keras/src/utils/traceback_utils.py in error_handler(*args, **kwargs)
68 # To get the full stack trace, call:
69 # tf.debugging.disable_traceback_filtering()
—> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb

/usr/local/lib/python3.10/dist-packages/tf_keras/src/optimizers/init.py in get(identifier, **kwargs)
333 )
334 else:
→ 335 raise ValueError(
336 f"Could not interpret optimizer identifier: {identifier}"
337 )

ValueError: Could not interpret optimizer identifier: <keras.src.optimizers.adam.Adam object at 0x7e17b44e89d0>

i am also facing a similiar kind of error

1 Like

It seems that there are different errors for each version…

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.