text_plain_output_1.png
from sklearn.metrics import classification_report

from transformers import DistilBertTokenizerFast

from transformers import TFDistilBertForSequenceClassification, TFTrainer, TFTrainingArguments

import tensorflow as tf

from transformers import DistilBertTokenizerFast
tokenizer = DistilBertTokenizerFast.from_pretrained('distilbert-base-uncased')

train_encodings = tokenizer(X_train, truncation=True, padding=True)
test_encodings = tokenizer(X_test, truncation=True, padding=True)

import tensorflow as tf
train_dataset = tf.data.Dataset.from_tensor_slices((dict(train_encodings), y_train))
test_dataset = tf.data.Dataset.from_tensor_slices((dict(test_encodings), y_test))

from transformers import TFDistilBertForSequenceClassification, TFTrainer, TFTrainingArguments
training_args = TFTrainingArguments(output_dir='./results', num_train_epochs=5, per_device_train_batch_size=8, per_device_eval_batch_size=16, warmup_steps=500, weight_decay=0.01, logging_dir='./logs', logging_steps=10)

with training_args.strategy.scope():
    model = TFDistilBertForSequenceClassification.from_pretrained('distilbert-base-uncased')
trainer = TFTrainer(model=model, args=training_args, train_dataset=train_dataset, eval_dataset=test_dataset)
trainer.train()

trainer.evaluate(test_dataset)

trainer.predict(test_dataset)

from sklearn.metrics import classification_report
print(classification_report(y_test, trainer.predict(test_dataset)[1]))