Views
No views yet
Qwen/Qwen3.5-2B-Base,
fine-tuned on
stanfordnlp/sst2
for binary sentiment classification.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 |
| 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 |
1import torch
2from peft import PeftModel
3from transformers import (
4 AutoModelForCausalLM,
5 AutoTokenizer,
6)
7
8BASE_MODEL_ID = "Qwen/Qwen3.5-2B-Base"
9ADAPTER_ID = "artyomboyko/qwen3.5-2b-sst2-prompt-tuning"
10
11tokenizer = (
12 AutoTokenizer.from_pretrained(
13 BASE_MODEL_ID
14 )
15)
16
17if tokenizer.pad_token_id is None:
18 tokenizer.pad_token = (
19 tokenizer.eos_token
20 )
21
22base_model = (
23 AutoModelForCausalLM
24 .from_pretrained(
25 BASE_MODEL_ID,
26 dtype="auto",
27 )
28)
29
30model = PeftModel.from_pretrained(
31 base_model,
32 ADAPTER_ID,
33)
34
35device = torch.device(
36 "cuda"
37 if torch.cuda.is_available()
38 else "cpu"
39)
40
41model = model.to(device)
42model.eval()
43
44review = (
45 "a wonderfully acted "
46 "and moving story"
47)
48
49prompt = (
50 "Classify the sentiment of this movie review as positive or negative.\n"
51 f"Review: {review}\n"
52 "Sentiment:"
53)
54
55inputs = tokenizer(
56 prompt,
57 return_tensors="pt",
58).to(device)
59
60with torch.inference_mode():
61 outputs = model.generate(
62 **inputs,
63 max_new_tokens=4,
64 do_sample=False,
65 pad_token_id=(
66 tokenizer.eos_token_id
67 ),
68 )
69
70generated = outputs[
71 :,
72 inputs["input_ids"].shape[1]:,
73]
74
75prediction = tokenizer.decode(
76 generated[0],
77 skip_special_tokens=True,
78).strip()
79
80print(prediction)Qwen/Qwen3.5-2B-Base.