FeelWise logo

Emotion classification with a Transformer encoder built from scratch

FeelWise Emotion

FeelWise Emotion is a lightweight text classification model that predicts the emotion expressed in a short English text. Its Transformer encoder (multi-head self-attention, feed-forward layers, residual connections and layer normalization) was implemented from scratch in PyTorch and trained from random initialization, with no pre-trained weights.

Model Details

Developed by Sanjith RJ and Shaik Bavikadi Al Hafeez
Model type Encoder-only Transformer for sequence classification
Language English
Training data dair-ai/emotion
Framework PyTorch, Hugging Face Transformers
License MIT
Pre-trained weights None (trained from scratch)

Architecture

Parameter Value
Encoder layers 1
Hidden size (d_model) 256
Attention heads 8
Feed-forward size (d_ff) 1024
Max sequence length 500
Vocabulary size 50,000
Dropout 0.1
Output classes 6

Pipeline: token embeddings + positional encoding β†’ multi-head self-attention β†’ Add & Norm β†’ feed-forward β†’ Add & Norm β†’ mean pooling β†’ linear classifier.

Labels

ID Label
0 sadness
1 joy
2 love
3 anger
4 fear
5 surprise

How to Use

pip install transformers torch
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

model_id = "sanjithrj/FeelWise"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id, trust_remote_code=True)
model.eval()

text = "I'm feeling really overwhelmed and anxious today."
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=500)

with torch.no_grad():
    logits = model(**inputs).logits

probs = logits.softmax(dim=-1)[0]
pred = probs.argmax().item()
print(f"Predicted emotion: {model.config.id2label[pred]} ({probs[pred]:.1%})")

trust_remote_code=True is required because FeelWise uses a custom architecture rather than a built-in Transformers model class.

Training Data

The model was trained on dair-ai/emotion, a dataset of English Twitter messages labeled with six emotions: sadness, joy, love, anger, fear and surprise.

Evaluation

Results on the

Downloads last month
57
Safetensors
Model size
13.6M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Dataset used to train sanjithrj/FeelWise