Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch.nn.functional as F
3
4# Load tokenizer and model
5model_path = 'FreedomIntelligence/medical_o1_verifier_3B'
6tokenizer = AutoTokenizer.from_pretrained(model_path)
7model = AutoModelForSequenceClassification.from_pretrained(
8 model_path, torch_dtype="auto", device_map="auto", attn_implementation="flash_attention_2", num_labels=2
9)
10
11# Evaluation template
12template = """<Model Response>
13{}
14</Model Response>
15
16<Reference Answer>
17{}
18</Reference Answer>
19
20Your task is to evaluate the model response by comparing it to the reference answer. If the model response is correct and aligns with the reference answer, output "True" . If it is incorrect or fails to select the correct option (if options are provided), output "False" . {}"""
21
22# Tokenize input and evaluate
23LLM_response = 'The answer is 25 percentage'
24ground_truth_answer = '25%'
25input_batch = tokenizer([template.format(LLM_response,ground_truth_answer,tokenizer.eos_token)], return_tensors="pt").to(model.device)
26logits = model(**input_batch,return_dict=True).logits
27probabilities = F.softmax(logits, dim=-1)
28result = "True" if probabilities[0, 1] > 0.5 else "False"
29
30print(f"Evaluation Result: {result}")@misc{chen2024huatuogpto1medicalcomplexreasoning,
title={HuatuoGPT-o1, Towards Medical Complex Reasoning with LLMs},
author={Junying Chen and Zhenyang Cai and Ke Ji and Xidong Wang and Wanlong Liu and Rongsheng Wang and Jianye Hou and Benyou Wang},
year={2024},
eprint={2412.18925},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2412.18925},
}