Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Using device: cpu
Training set size: 25000
Test set size: 25000

Sample review (truncated):
I rented I AM CURIOUS-YELLOW from my video store because of all the controversy that surrounded it when it was first released in 1967. I also heard that at first it was seized by U.S. customs if it ev...
Label: 0 (Negative)
Training subset size: 1000
Test subset size: 200
Loading...
Training set distribution:
Negative          512 (51.2%)
Positive          488 (48.8%)

Total training samples: 1000
Total test samples: 200
Original text: This movie was absolutely fantastic! I loved every minute of it.

Tokenized input IDs shape: torch.Size([1, 15])
Input IDs: tensor([  101,  2023,  3185,  2001,  7078, 10392,   999,  1045,  3866,  2296,
         3371,  1997,  2009,  1012,   102])...

Attention mask shape: torch.Size([1, 15])
Attention mask: tensor([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])...

Decoded tokens: [CLS] this movie was absolutely fantastic! i loved every minute of it. [SEP]
Max sequence length: 128
Training dataset size: 1000
Test dataset size: 200

Sample input_ids shape: torch.Size([128])
Sample attention_mask shape: torch.Size([128])
Sample label: 1
Batch input_ids shape: torch.Size([16, 128])
Batch attention_mask shape: torch.Size([16, 128])
Batch labels shape: torch.Size([16])
Unique labels in batch: tensor([0, 1])
Some weights of DistilBertForSequenceClassification were not initialized from the model checkpoint at distilbert-base-uncased and are newly initialized: ['classifier.bias', 'classifier.weight', 'pre_classifier.bias', 'pre_classifier.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
DistilBertForSequenceClassification(
  (distilbert): DistilBertModel(
    (embeddings): Embeddings(
      (word_embeddings): Embedding(30522, 768, padding_idx=0)
      (position_embeddings): Embedding(512, 768)
      (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)
      (dropout): Dropout(p=0.1, inplace=False)
    )
    (transformer): Transformer(
      (layer): ModuleList(
        (0-5): 6 x TransformerBlock(
          (attention): DistilBertSdpaAttention(
            (dropout): Dropout(p=0.1, inplace=False)
            (q_lin): Linear(in_features=768, out_features=768, bias=True)
            (k_lin): Linear(in_features=768, out_features=768, bias=True)
            (v_lin): Linear(in_features=768, out_features=768, bias=True)
            (out_lin): Linear(in_features=768, out_features=768, bias=True)
          )
          (sa_layer_norm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)
          (ffn): FFN(
            (dropout): Dropout(p=0.1, inplace=False)
            (lin1): Linear(in_features=768, out_features=3072, bias=True)
            (lin2): Linear(in_features=3072, out_features=768, bias=True)
            (activation): GELUActivation()
          )
          (output_layer_norm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)
        )
      )
    )
  )
  (pre_classifier): Linear(in_features=768, out_features=768, bias=True)
  (classifier): Linear(in_features=768, out_features=2, bias=True)
  (dropout): Dropout(p=0.2, inplace=False)
)

Total number of trainable parameters: 66,955,010
Optimizer: AdamW
Learning rate: 2e-05
Epoch 1
------------------------------------------------------------
loss: 0.706619  [    0/ 1000]
loss: 0.706619  [    0/ 1000]
loss: 0.662974  [  160/ 1000]
loss: 0.662974  [  160/ 1000]
loss: 0.654089  [  320/ 1000]
loss: 0.654089  [  320/ 1000]
loss: 0.648575  [  480/ 1000]
loss: 0.648575  [  480/ 1000]
loss: 0.674853  [  640/ 1000]
loss: 0.674853  [  640/ 1000]
loss: 0.615691  [  800/ 1000]
loss: 0.615691  [  800/ 1000]
loss: 0.577467  [  960/ 1000]
loss: 0.577467  [  960/ 1000]
Train: Avg loss: 0.6429, Accuracy: 62.3%
Train: Avg loss: 0.6429, Accuracy: 62.3%
Test:  Avg loss: 0.5206, Accuracy: 76.0%

Epoch 2
------------------------------------------------------------
Test:  Avg loss: 0.5206, Accuracy: 76.0%

Epoch 2
------------------------------------------------------------
loss: 0.535371  [    0/ 1000]
loss: 0.535371  [    0/ 1000]
loss: 0.275484  [  160/ 1000]
loss: 0.419958  [  320/ 1000]
loss: 0.417217  [  480/ 1000]
loss: 0.228642  [  640/ 1000]
loss: 0.224788  [  800/ 1000]
loss: 0.336228  [  960/ 1000]
Train: Avg loss: 0.3819, Accuracy: 83.7%
Test:  Avg loss: 0.4497, Accuracy: 79.0%

Done!
Model saved as 'distilbert_sentiment.pth'
Some weights of DistilBertForSequenceClassification were not initialized from the model checkpoint at distilbert-base-uncased and are newly initialized: ['classifier.bias', 'classifier.weight', 'pre_classifier.bias', 'pre_classifier.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
Model loaded successfully
Loading...

Classification Report:
              precision    recall  f1-score   support

    Negative       0.84      0.73      0.78       104
    Positive       0.75      0.85      0.80        96

    accuracy                           0.79       200
   macro avg       0.79      0.79      0.79       200
weighted avg       0.80      0.79      0.79       200

Loading...

Overall Accuracy: 79.00%
Average Precision: 0.795
Average Recall: 0.792
Average F1-Score: 0.790
Custom Review Predictions:
================================================================================

Review: This movie was absolutely brilliant! Best film I've seen in years.
Predicted: Positive
Probabilities: Negative=0.072, Positive=0.928
--------------------------------------------------------------------------------

Review: This movie was absolutely brilliant! Best film I've seen in years.
Predicted: Positive
Probabilities: Negative=0.072, Positive=0.928
--------------------------------------------------------------------------------

Review: Terrible waste of time. The plot made no sense and the acting was awful.
Predicted: Negative
Probabilities: Negative=0.955, Positive=0.045
--------------------------------------------------------------------------------

Review: Terrible waste of time. The plot made no sense and the acting was awful.
Predicted: Negative
Probabilities: Negative=0.955, Positive=0.045
--------------------------------------------------------------------------------

Review: It was okay, nothing special but not bad either.
Predicted: Negative
Probabilities: Negative=0.764, Positive=0.236
--------------------------------------------------------------------------------

Review: It was okay, nothing special but not bad either.
Predicted: Negative
Probabilities: Negative=0.764, Positive=0.236
--------------------------------------------------------------------------------

Review: A masterpiece of cinema! Every scene was perfect.
Predicted: Positive
Probabilities: Negative=0.096, Positive=0.904
--------------------------------------------------------------------------------

Review: A masterpiece of cinema! Every scene was perfect.
Predicted: Positive
Probabilities: Negative=0.096, Positive=0.904
--------------------------------------------------------------------------------

Review: Boring and predictable. I fell asleep halfway through.
Predicted: Negative
Probabilities: Negative=0.922, Positive=0.078
--------------------------------------------------------------------------------

Review: Boring and predictable. I fell asleep halfway through.
Predicted: Negative
Probabilities: Negative=0.922, Positive=0.078
--------------------------------------------------------------------------------