krishnaik06 / Huggingfacetransformer

GNU General Public License v3.0
58 stars 97 forks source link

The TFTrainer class has been deprecated in the Hugging Face Transformers library. Instead you can use. #7

Open Nikhilltiwari opened 1 month ago

Nikhilltiwari commented 1 month ago

Compile the model

optimizer = tf.keras.optimizers.Adam(learning_rate=5e-5) loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True) model.compile(optimizer=optimizer, loss=loss, metrics=['accuracy'])

Train the model

model.fit(train_dataset.batch(8), epochs=2, validation_data=test_dataset.batch(16))

Evaluate the model

evaluation = model.evaluate(test_dataset.batch(16)) print(f"Loss: {evaluation[0]}, Accuracy: {evaluation[1]}")

Make predictions

predictions = model.predict(test_dataset.batch(16)) predicted_labels = tf.argmax(predictions.logits, axis=1).numpy()

Compute confusion matrix

cm = confusion_matrix(y_test, predicted_labels) print(cm)

Save the model

model.save_pretrained('senti_model')

iamdoublea commented 1 month ago

Hey Nikhil, can we use just Trainer from the same library?