Views
No views yet
precision recall f1-score support
0 0.85 0.71 0.77 100
1 0.75 0.87 0.81 100
accuracy 0.79 200
macro avg 0.80 0.79 0.79 200
weighted avg 0.80 0.79 0.79 2001def format_input(reference, query, response):
2 prompt = f"""Your job is to evaluate whether a machine learning model has hallucinated or not.
3 A hallucination occurs when the response is coherent but factually incorrect or nonsensical
4 outputs that are not grounded in the provided context.
5 You are given the following information:
6 ####INFO####
7 [Knowledge]: {reference}
8 [User Input]: {query}
9 [Model Response]: {response}
10 ####END INFO####
11 Based on the information provided is the model output a hallucination? Respond with only "yes" or "no"
12 """
13 return input
14
15text = format_input(query='Based on the follwoing
16 <context>Walrus are the largest mammal</context>
17 answer the question
18 <query> What is the best PC?</query>',
19 response='The best PC is the mac')
20
21messages = [
22 {"role": "user", "content": text}
23]
24
25pipe = pipeline(
26 "text-generation",
27 model=base_model,
28 model_kwargs={"attn_implementation": attn_implementation, "torch_dtype": torch.float16},
29 tokenizer=tokenizer,
30)
31generation_args = {
32 "max_new_tokens": 2,
33 "return_full_text": False,
34 "temperature": 0.01,
35 "do_sample": True,
36 }
37
38output = pipe(messages, **generation_args)
39print(f'Hallucination: {output[0]['generated_text'].strip().lower()}')
40# Hallucination: yes| Model | Precision | Recall | F1 |
|---|---|---|---|
| Our Merged Model | 0.75 | 0.87 | 0.81 |
| GPT-4 | 0.93 | 0.72 | 0.82 |
| GPT-4 Turbo | 0.97 | 0.70 | 0.81 |
| Gemini Pro | 0.89 | 0.53 | 0.67 |
| GPT-3.5 | 0.89 | 0.65 | 0.75 |
| GPT-3.5-turbo-instruct | 0.89 | 0.80 | 0.84 |
| Palm 2 (Text Bison) | 1.00 | 0.44 | 0.61 |
| Claude V2 | 0.80 | 0.95 | 0.87 |