# Load the pre-trained BERT model
model = TFAutoModelForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)
import tensorflow as tf
from tensorflow.keras.optimizers import Adam
# Instantiate the optimizer
optimizer = tf.keras.optimizers.Adam(learning_rate = 0.001)
# Compile the model
model.compile(
loss=model.compute_loss,
optimizer=optimizer,
metrics=['accuracy']
)
model.fit(train_dataset, validation_data=val_dataset, epochs=3)
I am creating an entity extraction model in PyTorch using bert-base-uncased but when I try to run the model I get this error:
ValueError Traceback (most recent call last)
Cell In[13], line 11
8 optimizer = tf.keras.optimizers.Adam(learning_rate = 0.001)
10 # Compile the model
---> 11 model.compile(
12 loss='sparse_categorical_crossentropy',
13 optimizer=Adam,
14 metrics=['accuracy']
15 )
20 # Train the model
21 model.fit(train_dataset, validation_data=val_dataset, epochs=3)
File c:UsersASUSanaconda3Libsite-packagestransformersmodeling_tf_utils.py:1563, in TFPreTrainedModel.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,
1566 metrics=metrics,
1567 loss_weights=loss_weights,
1568 weighted_metrics=weighted_metrics,
1569 run_eagerly=run_eagerly,
1570 steps_per_execution=steps_per_execution,
1571 **kwargs,
...
--> 335 raise ValueError(
336 f"Could not interpret optimizer identifier: {identifier}"
337 )
ValueError: Could not interpret optimizer identifier: <class 'keras.src.optimizers.adam.Adam'>
I have the latest version for transformers(4.40.1) and keras (2.16.0).
I also referred to this thread but am still getting the same error.
“Could not interpret optimizer identifier” error in Keras
New contributor
Sammit Dhadve is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.