Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load merged model (LoRA already merged)
5model_id = "textdetox/Llama-pairwise-content-evaluator_merged"
6
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 device_map="auto",
10 torch_dtype=torch.bfloat16
11)
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13
14model.eval()
15
16# Prompt with example + test pair
17messages = [
18 {
19 "role": "user",
20 "content": '''You are given with two texts. Your task is to compare the meaning of them and decide whether they mean the same or not.
21
22Options:
23- yes (both texts have the same meaning)
24- no (there is significant difference in meaning between the two texts)
25
26Examples:
27text1: "Why do you behave like an asshole?"
28text2: "Why do you act so bad?"
29Answer: yes
30
31text1: "This political party is a gang of idiots"
32text2: "They just don’t know their stuff"
33Answer: no
34
35text1: "There is nothing dangerous here. People like Abraham Desta who try to create chaos are just opponents of the old system."
36text2: "Nothing dangerous is happening. People like Abraham Desta who try to stir things up are just enemies of the previous regime."
37Answer:'''
38 }
39]
40
41# Apply chat template
42prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
43
44# Tokenize
45inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
46
47# Generate
48with torch.no_grad():
49 outputs = model.generate(**inputs, max_new_tokens=5, temperature=0.15)
50 result = tokenizer.decode(
51 outputs[0][inputs["input_ids"].shape[1]:],
52 skip_special_tokens=True
53 )
54
55print("Model prediction:", result.strip())
56
57