Downloads · 30 days
4
4% of all-time downloads
shreevershith/emotion-qwen3-label-gen
emotion-qwen3-label-gen is a machine learning model from shreevershith. 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 peft.
A PEFT (LoRA) adapter for Qwen/Qwen3-0.6B that generates multi-label emotion tags from short text (e.g. tweets). Given a tweet, the model outputs a comma-separated list of emotions from a fixed set of 11 labels.
Downloads · 30 days
4
4% of all-time downloads
All-time downloads
103
Public
Repo size
31.7 MB
Likes
0
Public
Click a slice to open those files.
.safetensors20.2 MB · 56%
From the Hugging Face model README
A PEFT (LoRA) adapter for Qwen/Qwen3-0.6B that generates multi-label emotion tags from short text (e.g. tweets). Given a tweet, the model outputs a comma-separated list of emotions from a fixed set of 11 labels.
QLoRA_Qwen3_Label_Generation_InstructModel_Final.ipynbUse this model to predict which emotions (from a fixed set of 11) are present in a short English text. Input: tweet or similar text. Output: comma-separated emotion labels, which you can map to a binary vector over the 11 emotions.
Emotion labels: anger, anticipation, disgust, fear, joy, love, optimism, pessimism, sadness, surprise, trust.
Suitable for dashboards, APIs, or pipelines that need emotion tags from user-generated text (e.g. social media, feedback). Parse the generated string into the 11-dimensional binary vector for scoring or visualization.
The model was fine-tuned on tweet-style data and may not generalize well to formal text, other domains, or other languages. Predictions can be subjective and should not be used as the sole basis for high-stakes decisions.
Use for exploration and demos; validate on your own data before production use.
Install dependencies:
pip install torch transformers peft
Load the base model and adapter, then run generation:
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# ----------------------
# Setup
# ----------------------
MODEL_NAME = "Qwen/Qwen3-0.6B"
ADAPTER_NAME = "shreevershith/emotion-qwen3-label-gen"
device = "cuda" if torch.cuda.is_available() else "cpu"
# Load base model and adapter
base_model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
model = PeftModel.from_pretrained(base_model, ADAPTER_NAME)
tokenizer = AutoTokenizer.from_pretrained(ADAPTER_NAME)
# Make sure we have a pad token
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
model.eval()
model.to(device)
label_cols = [
"anger", "anticipation", "disgust", "fear", "joy", "love",
"optimism", "pessimism", "sadness", "surprise", "trust",
]
def extract_emotions(text: str):
return list({
e.strip().lower()
for e in text.lower().split(",")
if e.strip() in label_cols
})
# ----------------------
# Example inference
# ----------------------
test_tweet = "I'm so happy and grateful today!"
prompt = f"Tweet: {test_tweet}\n### LABEL:"
inputs = tokenizer(
prompt,
return_tensors="pt",
truncation=True,
max_length=384,
).to(device)
with torch.no_grad():
# IMPORTANT: use sampling; Qwen3 docs say don't use greedy
outputs = model.generate(
**inputs,
max_new_tokens=20,
pad_token_id=tokenizer.pad_token_id,
do_sample=True,
temperature=0.7,
top_p=0.8,
top_k=20,
)
# Only decode the newly generated tokens
input_len = inputs["input_ids"].shape[1]
new_tokens = outputs[0][input_len:]
generated_text = tokenizer.decode(new_tokens, skip_special_tokens=True)
print("Full generated continuation:", repr(generated_text))
label_str = generated_text.split("### LABEL:")[-1].strip()
print("Label string:", repr(label_str))
emotions = extract_emotions(label_str)
binary_labels = [1 if label in emotions else 0 for label in label_cols]
print("Detected emotions:", emotions)
print("Binary vector:", dict(zip(label_cols, binary_labels)))
train.csv with tweet text and 11 binary emotion columns.@user; hashtag symbol removed (text kept); optional synonym-based data augmentation (nlpaug) for minority classes.joy, optimism).max_length=384.r=8, lora_alpha=16, lora_dropout=0.05; target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj.| Hyperparameter | Value |
|---|---|
| Epochs | 4 |
| Per-device train batch size | 4 |
| Per-device eval batch size | 16 |
| Gradient accumulation steps | 4 (effective batch 16) |
| Learning rate | 8e-5 |
| Warmup ratio | 0.1 |
| Weight decay | 0.02 |
| Precision | bf16 |
| Eval / save strategy | Every epoch |
| Save total limit | 2 |
| Load best model at end | Yes (metric: F1) |
| Early stopping | Patience 2 |
| Logging | wandb, every 50 steps |
adapter_model.safetensors).Validation per-class F1 (from threshold optimization in the notebook):
| Emotion | F1 | Emotion | F1 |
|---|---|---|---|
| anger | 0.809 | love | 0.664 |
| anticipation | 0.430 | optimism | 0.754 |
| disgust | 0.751 | pessimism | 0.480 |
| fear | 0.769 | sadness | 0.686 |
| joy | 0.816 | surprise | 0.412 |
| — | — | trust | 0.315 |
Submissions were made to Kaggle Emotion Detection Spring 2025; this instruction-tuned adapter produced more calibrated, selective predictions than the base-model adapter.
The model performs best on high-frequency emotions (e.g. joy, anger, fear, disgust) and weaker on rarer ones (e.g. trust, surprise, anticipation), consistent with class imbalance in the training data.
CAUSAL_LMIf you use this model, please cite the base model (Qwen3) and the PEFT library as appropriate.
For questions or issues, open a discussion on the Hugging Face model page or an issue in the project repository.