cornell-movie-review-data/rotten_tomatoes
Viewer • Updated • 10.7k • 73.6k • 132
How to use Marwanpng/MovieSentimentLM with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM3-3B")
model = PeftModel.from_pretrained(base_model, "Marwanpng/MovieSentimentLM")This is a 4-bit quantized QLoRA adapter for HuggingFaceTB/SmolLM3-3B, fine-tuned to classify the sentiment of movie reviews into positive or negative using the Rotten Tomatoes dataset.
HuggingFaceTB/SmolLM3-3Bbitsandbytes, adapter rank = 8, alpha = 16)[[501, 32],
[ 51, 482]]
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
base_model_name = "HuggingFaceTB/SmolLM3-3B"
adapter_name = "Marwanpng/MovieSentimentLM"
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
model = AutoModelForCausalLM.from_pretrained(
base_model_name,
torch_dtype=torch.float16,
device_map="auto"
)
model = PeftModel.from_pretrained(model, adapter_name)
system_prompt = "You are a movie review sentiment classifier. Respond with exactly one lowercase word: positive or negative."
review = "The acting was fantastic and the story was moving."
messages = [
{'role': 'system', 'content': system_prompt},
{'role': 'user', 'content': f"Classify the sentiment of this movie review:\n{review}"}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=4)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))