Views
No views yet
vi)1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, GenerationConfig
3from peft import PeftModel
4
5BASE_MODEL = "Qwen/Qwen2.5-7B-Instruct"
6ADAPTER_ID = "sunflowerbiii/infi-check-qwen25-7b-qlora-c"
7
8# Load with 4-bit quantization
9bnb_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.bfloat16,
13 bnb_4bit_use_double_quant=True,
14)
15
16tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
17base_model = AutoModelForCausalLM.from_pretrained(
18 BASE_MODEL, quantization_config=bnb_config, device_map="auto", trust_remote_code=True
19)
20model = PeftModel.from_pretrained(base_model, ADAPTER_ID)
21model.eval()
22
23# Build prompt
24document = "..." # Vietnamese news article
25summary = "..." # Summary sentence to verify
26
27instruction = (
28 "Your task is to evaluate a summary by comparing it to the original document "
29 "and identifying any errors present in the summary.\n\n"
30 "Possible error types:\n"
31 "- Predicate Error, Entity Error, Circumstance Error\n"
32 "- Co-reference Error, Discourse Link Error\n"
33 "- Extrinsic Error\n\n"
34 "For each error found, output:\n"
35 "- Location: the erroneous sentence\n"
36 "- Explanation: why it is wrong\n"
37 "- Correction: corrected version\n"
38 "- Error Type: one of the types above\n\n"
39 "Write analysis in Vietnamese. End with: 'Therefore, the answer is YES.' or 'Therefore, the answer is NO.'\n\n"
40 f"Document:\n{document}\n\nSummary:\n{summary}"
41)
42
43prompt = f"<|im_start|>user\n{instruction}<|im_end|>\n<|im_start|>assistant\n"
44
45im_end_id = tokenizer.convert_tokens_to_ids("<|im_end|>")
46eot_id = tokenizer.convert_tokens_to_ids("<|endoftext|>")
47
48inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048).to(model.device)
49with torch.no_grad():
50 output_ids = model.generate(
51 **inputs,
52 max_new_tokens=1024,
53 do_sample=False,
54 repetition_penalty=1.1,
55 eos_token_id=[im_end_id, eot_id],
56 pad_token_id=eot_id,
57 )
58
59gen_ids = output_ids[0][inputs["input_ids"].shape[1]:]
60print(tokenizer.decode(gen_ids, skip_special_tokens=True))1@article{bai2026inficheck,
2 title = {InFi-Check: Interpretable and Fine-Grained Fact-Checking of LLMs},
3 author = {Bai, Yuzhuo and Si, Shuzheng and Luo, Kangyang and Wang, Qingyi and
4 Li, Wenhao and Chen, Gang and Qi, Fanchao and Sun, Maosong},
5 journal = {arXiv preprint arXiv:2601.06666},
6 year = {2026}
7}