Downloads · 30 days
18
8% of all-time downloads
zhezhou1106/political-leaning-classifier-v2
political-leaning-classifier-v2 is a text classification model from zhezhou1106. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as apache-2.0.
This repository is a merged (full-weight) fine-tune of Qwen/Qwen3.5-4B for English news-style text. It assigns a single integer score from 0 to 4 describing estimated political leaning along a left–right spectrum.
Downloads · 30 days
18
8% of all-time downloads
All-time downloads
214
Public
Parameters
5.2B
10.4 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors10.4 GB · 100%
How the weights are stored.
BF165.2B · 100%
From the Hugging Face model README
This repository is a merged (full-weight) fine-tune of Qwen/Qwen3.5-4B for English news-style text. It assigns a single integer score from 0 to 4 describing estimated political leaning along a left–right spectrum.
Support automated triage and analysis of large text collections (e.g. monitoring relative slant in news-like passages). The model is trained as a causal LM that completes a fixed instruction prompt and is scored by the probability it assigns to the digit tokens "0" … "4" at the final position—not by a separate classification head in the Hugging Face sense.
| Score | Meaning (training prompt) |
|---|---|
| 0 | Extremely left (far left) |
| 1 | Lean left |
| 2 | Center / neutral |
| 3 | Lean right |
| 4 | Extremely right (far right) |
Labels are ordinal in prompt wording only; training optimizes categorical next-token prediction over the five digit tokens.
{0,…,4}, combined and shuffled.Dataset names and exact row counts can differ if you re-export CSVs; keep the same split logic if you want to reproduce reported validation numbers.
q/k/v/o, gate/up/down) plus a trimmed lm_head (see below).0–4 are kept for the trainable head slice, to reduce memory and stabilize the classification signal; after training, weights are merged back into a full-vocabulary head for standard transformers loading.from_pretrained—no PEFT merge step.Training used Unsloth and TRL SFTTrainer.
| Setting | Value |
|---|---|
LoRA rank r | 16 |
| LoRA alpha | 16 |
| LoRA dropout | 0 |
| RSLoRA | enabled |
| LoRA targets | lm_head, q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Max sequence length | 8192 tokens (article truncated in tokens if needed; prompt + answer must fit) |
| Precision | bfloat16 training, TF32 matmul where applicable |
| Optimizer | AdamW (PyTorch fused implementation) |
| Learning rate | 1e-4 |
| LR schedule | Cosine |
| Warmup | 20 steps |
| Weight decay | 0.01 |
| Epochs | 2 |
| Per-device batch size | 8 |
| Gradient accumulation | 4 (effective batch 32) |
| Gradient checkpointing | on |
| Random seed | 3407 |
On the fixed 10% stratified validation split from the training pipeline (exact size depends on the cleaned union of the two CSVs), one reference run reported:
Treat these as internal sanity metrics on a specific news/bias-oriented mixture, not a guarantee on other domains, languages, or time periods.
The implementation loads the model class appropriate for Qwen3.5 multimodal checkpoints (AutoModelForImageTextToText when available, else causal LM). Use text-only prompts.
Recommended decoding: build the prompt through the supervised prefix ending at "... class " (see your training/inference scripts), tokenize with left padding for batches, take last-token logits, then take a softmax only over the five tokenizer IDs for "0" … "4" and choose argmax as the predicted class index 0–4. This matches training and avoids unnecessary full-vocabulary work.
Dependencies: recent torch, transformers, accelerate; optional quantization stacks (e.g. HQQ) if you shrink memory at inference—expect small metric drift.
Minimal pattern:
import torch
import torch.nn.functional as F
from transformers import AutoTokenizer
try:
from transformers import AutoModelForImageTextToText as AutoModelCls
except ImportError:
from transformers import AutoModelForCausalLM as AutoModelCls
MODEL_ID = "zhezhou1106/political-leaning-classifier-v2" # or a local folder
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
model = AutoModelCls.from_pretrained(
MODEL_ID,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
model.eval()
number_token_ids = []
for digit in range(5):
ids = tokenizer.encode(str(digit), add_special_tokens=False)
assert len(ids) == 1, "Tokenizer must encode digits 0–4 as a single token each."
number_token_ids.append(ids[0])
def classify(article_text: str) -> int:
prompt = """You are an expert media bias analyst. Read the following news article and classify its political leaning on a 0-4 scale.
Article:
{article}
Scale:
class 0: extremely left (far left)
class 1: lean left
class 2: center / neutral
class 3: lean right
class 4: extremely right (far right)
SOLUTION
The correct answer is: class """.format(
article=article_text.strip()
)
tokenizer.padding_side = "left"
enc = tokenizer([prompt], return_tensors="pt", padding=True).to(model.device)
with torch.inference_mode():
out = model(**enc, logits_to_keep=1)
last = out.logits[:, -1, :]
digit_logits = last[:, number_token_ids]
probs = F.softmax(digit_logits, dim=-1)
return int(probs.argmax(dim=-1).item())
Adapt the prompt string exactly to what you used in training if you need strict reproducibility.
For questions about the upstream base model capabilities, licensing nuances, or safety tooling, consult the Qwen3.5-4B model card.
If you use this fine-tuned checkpoint, cite the upstream Qwen model appropriately and cite or link this Hugging Face repository. You may also cite Unsloth/TRL depending on academic conventions.