Views
No views yet
| Detection Type | F1 Score |
|---|---|
| Overall | 70.30 |
| Factual Hallucination | 64.40 |
| Cognitive Hallucination | 73.80 |
1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3model_id = "future7/CogniDet"
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5model = AutoModelForCausalLM.from_pretrained(model_id)
6
7def detect_hallucinations(context, response):
8 inputs = tokenizer(
9 f"CONTEXT: {context}
10RESPONSE: {response}
11HALLUCINATIONS:",
12 return_tensors="pt"
13 )
14 outputs = model.generate(**inputs, max_new_tokens=100)
15 return tokenizer.decode(outputs[0], skip_special_tokens=True)
16
17# Example usage
18context = "Moringa trees grow in USDA zones 9-10. Flowering occurs annually in spring."
19response = "In cold regions, Moringa can bloom twice yearly if grown indoors."
20
21print(detect_hallucinations(context, response))
22# Output: "Bloom frequency claims in cold regions are speculative"1@inproceedings{tang2025cognibench,
2 title = {CogniBench: A Legal-inspired Framework for Assessing Cognitive Faithfulness of LLMs},
3 author = {Tang, Xiaqiang and Li, Jian and Hu, Keyu and Nan, Du
4 and Li, Xiaolong and Zhang, Xi and Sun, Weigao and Xie, Sihong},
5 booktitle = {Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (ACL 2025)},
6 year = {2025},
7 pages = {xxx--xxx}, % 添加页码范围
8 publisher = {Association for Computational Linguistics},
9 location = {Vienna, Austria},
10 url = {https://arxiv.org/abs/2505.20767},
11 archivePrefix = {arXiv},
12 eprint = {2505.20767},
13 primaryClass = {cs.CL}
14}