Views
No views yet
unsloth/gemma-3-12b-it for
binary polarization detection across 22 languages, trained for SemEval-2026 Task 9 Subtask 1."0" and "1") at a single <ANSWER> position, and the
softmax over just those two logits is the class probability. This makes inference one forward pass
per example and gives a calibrated probability you can threshold.<ANSWER> in an assistant turn, or skipping the 800-character truncation) shifts the
distribution away from what it saw.1import torch
2from unsloth import FastLanguageModel
3
4MAX_LENGTH, TEXT_MAX_LENGTH = 1024, 800
5
6TASK_TEMPLATE = """Does the following text contain polarization?
7A text is polarized if it incites division, hatred, or stereotyping towards other groups.
8
9Answer in format:
10<ANSWER>#Number</ANSWER>
11where the number is one of the following:
120 - No
131 - Yes
14
15The text:
16<TEXT>
17{text}
18</TEXT>
19"""
20
21model, tokenizer = FastLanguageModel.from_pretrained(
22 model_name="howarudo/gemma-3-12b-it-semeval2026-task9-polarization-lora",
23 max_seq_length=MAX_LENGTH,
24 dtype=None,
25 load_in_4bit=False,
26)
27FastLanguageModel.for_inference(model)
28
29def polarization_prob(text: str) -> float:
30 messages = [{"role": "user", "content": TASK_TEMPLATE.format(text=str(text)[:TEXT_MAX_LENGTH])}]
31 prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) + "<ANSWER>"
32 enc = tokenizer(prompt, return_tensors="pt", truncation=True,
33 max_length=MAX_LENGTH, add_special_tokens=False).to(model.device)
34
35 class_ids = torch.tensor([tokenizer.encode(c, add_special_tokens=False)[0] for c in ["0", "1"]],
36 device=model.device)
37 # Autocast is required: the Gemma3 attention path computes in fp32 and
38 # projects through bf16 weights.
39 with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
40 logits = model(**enc).logits[0, -1, :]
41 return torch.softmax(logits.index_select(0, class_ids).float(), dim=-1)[1].item()
42
43print(polarization_prob("Your text here.")) # P(polarized)