CoolFace
Modelpublic

arnabdhar/tinybert-imdb

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes28downloads
Model Card

<!-- This model card has been generated automatically according to the information the Trainer had access to. You should probably proofread and complete it, then remove this comment. -->

bert-tiny-imdb

This model is a fine-tuned version of prajjwal1/bert-tiny on the imdb dataset. It achieves the following results on the evaluation set:

  • Loss: 0.2775
  • Accuracy: 0.8944
  • Matthews Correlation: 0.7888

Model description

This is the smallest version of BERT model suggested by Google in this GitHub Repo, this model contains 2 transformer layers and an a hidden layer output length of 128, ie _(L=2, H=128)_. There are a total 4.39 million paramteres in the model.

Intended uses & limitations

This model should be used for text classification tasks specifically on movie reviews or other such text data. Also you can use this model for other downstream tasks like:

  • Sentiment Analysis
  • Named Entity Recognition or Token Classification

This model should not be used for any tasks other than the above mentioned or any language other than English.

How to use the Model

_Pytorch Model_

python
from transformers import pipeline

# load pipeline
tiny_bert = pipeline("text-classification", "arnabdhar/tinybert-imdb")

# perform inference
results = pipeline(input_text, truncation=True, max_length=128)

_ONNX Model_

python
from transformers import AutoTokenizer, pipeline
from optimum.onnxruntime import ORTModelForSequenceClassification

# load tokenizer & model
model_name = "arnabdhar/tinybert-imdb"
tokenizer = AutoTokenizer.from_pretrained(model_name)
onnx_model = ORTModelForSequenceClassification.from_pretrained(model_name)

# build pipeline
tiny_bert_onnx = pipeline(
  task = "text-classification",
  tokenizer = tokenizer,
  model = onnx_model
)

# perform inference
results = tiny_bert_onnx(input_text, truncation=True, max_length=128)

Training

The model was finetuned on Google Colab using the NVIDIA V100 GPU and was trained for 9 epochs, it took around 12 minutes to finish finetuning.

This model has been trained on the imdb dataset which has 25,000 data text data for each training set and testing set, but I have combined both the partitions and then split the dataset in 80:20 ratio and used it for finetuning. This approach gave me a larger dataset to finetune the model.

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 5e-05
  • trainbatchsize: 32
  • evalbatchsize: 320
  • seed: 42
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lrschedulertype: cosine
  • lrschedulerwarmup_ratio: 0.1
  • num_epochs: 9

Training results

Training LossEpochStepValidation LossAccuracyMatthews Correlation
0.49271.012500.35570.84840.7016
0.2982.025000.28740.88660.7732
0.25553.037500.27990.89120.7828
0.21324.050000.27750.89440.7888
0.17795.062500.30650.8910.7835
0.15086.075000.33310.8890.7811
0.13047.087500.34510.89260.7870
0.1198.0100000.36700.89150.7852
0.11189.0112500.36550.8910.7840

Framework versions

  • Transformers 4.35.2
  • Pytorch 2.1.0+cu118
  • Datasets 2.15.0
  • Tokenizers 0.15.0