Downloads · 30 days
78
60% of all-time downloads
Carlo88/qwen05b-sentiment-lora-imdb
qwen05b-sentiment-lora-imdb is a text generation model from Carlo88. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
This is a LoRA adapter for Qwen/Qwen2.5-0.5B-Instruct, fine-tuned with QLoRA for binary sentiment classification on the Stanford IMDB movie review dataset.
Downloads · 30 days
78
60% of all-time downloads
All-time downloads
131
Public
Repo size
15.8 MB
Likes
1
Public
Click a slice to open those files.
.json11.4 MB · 72%
From the Hugging Face model README
This is a LoRA adapter for Qwen/Qwen2.5-0.5B-Instruct, fine-tuned with QLoRA for binary sentiment classification on the Stanford IMDB movie review dataset.
This adapter is part of an end-to-end MLOps portfolio project demonstrating the full lifecycle of LLM fine-tuning: data preparation, QLoRA training, experiment tracking with MLflow, evaluation, and deployment.
q_proj, k_proj, v_proj, o_projstanfordnlp/imdb), 25,000 labeled movie reviews in the original train splitassistant_only_loss=True); system and user tokens are maskedEvaluated on a stratified sample of 1,000 examples from the held-out IMDB test set (seed=42), using true autoregressive generation (no teacher forcing) — the model receives only the system and user turns and must generate its own response.
| Metric | Value |
|---|---|
| Accuracy | 0.9176 |
| Precision | 0.9314 |
| Recall | 0.9014 |
| F1 | 0.9162 |
Confusion matrix (995 valid responses; 5 out of 1,000 generations were not recognized as either label):
| Predicted: negative | Predicted: positive | |
|---|---|---|
| True: negative | 465 | 33 |
| True: positive | 49 | 448 |
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
BASE_MODEL = "Qwen/Qwen2.5-0.5B-Instruct"
ADAPTER_REPO = "Carlo88/qwen05b-sentiment-lora-imdb"
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
base_model = AutoModelForCausalLM.from_pretrained(
BASE_MODEL,
quantization_config=bnb_config,
device_map="auto",
dtype=torch.float16,
)
model = PeftModel.from_pretrained(base_model, ADAPTER_REPO)
model.eval()
review = "This movie was a complete waste of time, the plot made no sense."
messages = [
{"role": "system", "content": "Sei un classificatore di sentiment. Rispondi solo con 'positive' o 'negative'."},
{"role": "user", "content": review},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=5, do_sample=False)
response = tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(response) # -> "negative"
<br /><br />) which were not cleaned during preprocessing. This did not appear to harm performance but is worth noting for anyone extending this work.transformers, peft, trl, bitsandbytesIf you use this adapter, please also cite the base model and dataset: