stanfordnlp/sst2
Viewer • Updated • 70k • 52.4k • 172
How to use artyomboyko/qwen3.5-2b-sst2-prompt-tuning with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-2B-Base")
model = PeftModel.from_pretrained(base_model, "artyomboyko/qwen3.5-2b-sst2-prompt-tuning")Prompt Tuning adapter for
Qwen/Qwen3.5-2B-Base,
fine-tuned on
stanfordnlp/sst2
for binary sentiment classification.
The adapter predicts positive or negative.
| Property | Value |
|---|---|
| Base model | Qwen/Qwen3.5-2B-Base |
| Method | Prompt Tuning |
| Dataset | stanfordnlp/sst2 |
| Task | Sentiment classification |
| Labels | negative, positive |
| Virtual tokens | 16 |
| Prompt initialization | Classify the sentiment of the movie review as positive or negative. |
| Adapter size | 0.13 MiB |
Evaluation scope: full SST-2 validation split.
| Metric | Base model | Prompt Tuning |
|---|---|---|
| Generation accuracy | 3.10% | 94.27% |
| Forced-choice accuracy | 51.49% | 94.27% |
| Generation Macro F1 | 0.0573 | 0.9427 |
| Forced-choice Macro F1 | 0.3502 | 0.9427 |
| Perplexity | — | 1.0869 |
import torch
from peft import PeftModel
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
)
BASE_MODEL_ID = "Qwen/Qwen3.5-2B-Base"
ADAPTER_ID = "artyomboyko/qwen3.5-2b-sst2-prompt-tuning"
tokenizer = (
AutoTokenizer.from_pretrained(
BASE_MODEL_ID
)
)
if tokenizer.pad_token_id is None:
tokenizer.pad_token = (
tokenizer.eos_token
)
base_model = (
AutoModelForCausalLM
.from_pretrained(
BASE_MODEL_ID,
dtype="auto",
)
)
model = PeftModel.from_pretrained(
base_model,
ADAPTER_ID,
)
device = torch.device(
"cuda"
if torch.cuda.is_available()
else "cpu"
)
model = model.to(device)
model.eval()
review = (
"a wonderfully acted "
"and moving story"
)
prompt = (
"Classify the sentiment of this movie review as positive or negative.\n"
f"Review: {review}\n"
"Sentiment:"
)
inputs = tokenizer(
prompt,
return_tensors="pt",
).to(device)
with torch.inference_mode():
outputs = model.generate(
**inputs,
max_new_tokens=4,
do_sample=False,
pad_token_id=(
tokenizer.eos_token_id
),
)
generated = outputs[
:,
inputs["input_ids"].shape[1]:,
]
prediction = tokenizer.decode(
generated[0],
skip_special_tokens=True,
).strip()
print(prediction)
Qwen/Qwen3.5-2B-Base.Base model
Qwen/Qwen3.5-2B-Base