Downloads · 30 days
12
1% of all-time downloads
mohammadtaghizadeh/flan-t5-base-imdb-text-classification
flan-t5-base-imdb-text-classification is a machine learning model from mohammadtaghizadeh. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
should probably proofread and complete it, then remove this comment. --
Downloads · 30 days
12
1% of all-time downloads
All-time downloads
849
Public
Repo size
3 GB
Likes
0
Public
Click a slice to open those files.
.bin990 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of google/flan-t5-base on the IMDB dataset. It achieves the following results on the evaluation set:
precision recall f1-score support
0 0.97 0.88 0.92 12500
1 0.89 0.97 0.93 12500
accuracy 0.93 25000
macro avg 0.93 0.93 0.93 25000
weighted avg 0.93 0.93 0.93 25000
In this implementation, using the Flan T5 large language model, we performed the Text Classification task on the IMDB dataset and obtained a very good accuracy of 93%.
This model was trained on the imdb train dataset with 25,000 data and then tested and evaluated on the imdb test dataset with 25,000 data.
!pip install transformers==4.28.1 datasets
from datasets import load_dataset
dataset_id = "imdb"
# Load dataset from the hub
dataset = load_dataset(dataset_id)
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("mohammadtaghizadeh/flan-t5-base-imdb-text-classification")
model = AutoModelForSeq2SeqLM.from_pretrained("mohammadtaghizadeh/flan-t5-base-imdb-text-classification")
model.to('cuda')
from tqdm.auto import tqdm
samples_number = len(dataset['test'])
progress_bar = tqdm(range(samples_number))
predictions_list = []
labels_list = []
for i in range(samples_number):
text = dataset['test']['text'][i]
inputs = tokenizer.encode_plus(text, padding='max_length', max_length=512, return_tensors='pt').to('cuda')
outputs = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'], max_length=150, num_beams=4, early_stopping=True)
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True)
predictions_list.append(prediction)
labels_list.append(dataset['test']['label'][i])
progress_bar.update(1)
from sklearn.metrics import classification_report
str_labels_list = []
for i in range(len(labels_list)): str_labels_list.append(str(labels_list[i]))
report = classification_report(str_labels_list, predictions_list)
print(report)
Output
precision recall f1-score support
0 0.97 0.88 0.92 12500
1 0.89 0.97 0.93 12500
accuracy 0.93 25000
macro avg 0.93 0.93 0.93 25000
weighted avg 0.93 0.93 0.93 25000
The following hyperparameters were used during training:
| Training Loss | Epoch | Step |
|---|---|---|
| 0.100500 | 1.0 | 3125 |
| 0.043600 | 2.0 | 6250 |