Spaces:
Runtime error
Runtime error
Commit
•
7f12787
1
Parent(s):
2561b63
update
Browse files
scripts/halueval-upload-cli.py
CHANGED
@@ -40,6 +40,7 @@ for name in (gold_splits - {'general'}):
|
|
40 |
|
41 |
for entry in ds['data']:
|
42 |
is_hallucinated = random.random() > 0.5
|
|
|
43 |
if name in {'qa'}:
|
44 |
new_entry = {
|
45 |
'knowledge': entry['knowledge'],
|
@@ -47,7 +48,6 @@ for name in (gold_splits - {'general'}):
|
|
47 |
'answer': entry[f'{"hallucinated" if is_hallucinated else "right"}_answer'],
|
48 |
'hallucination': 'yes' if is_hallucinated else 'no'
|
49 |
}
|
50 |
-
new_entry_lst += [new_entry]
|
51 |
if name in {'dialogue'}:
|
52 |
new_entry = {
|
53 |
'knowledge': entry['knowledge'],
|
@@ -61,7 +61,8 @@ for name in (gold_splits - {'general'}):
|
|
61 |
'summary': entry[f'{"hallucinated" if is_hallucinated else "right"}_summary'],
|
62 |
'hallucination': 'yes' if is_hallucinated else 'no'
|
63 |
}
|
64 |
-
|
|
|
65 |
new_ds_map = list_to_dict(new_entry_lst)
|
66 |
new_ds = Dataset.from_dict(new_ds_map)
|
67 |
new_dsd = DatasetDict({'data': new_ds})
|
|
|
40 |
|
41 |
for entry in ds['data']:
|
42 |
is_hallucinated = random.random() > 0.5
|
43 |
+
new_entry = None
|
44 |
if name in {'qa'}:
|
45 |
new_entry = {
|
46 |
'knowledge': entry['knowledge'],
|
|
|
48 |
'answer': entry[f'{"hallucinated" if is_hallucinated else "right"}_answer'],
|
49 |
'hallucination': 'yes' if is_hallucinated else 'no'
|
50 |
}
|
|
|
51 |
if name in {'dialogue'}:
|
52 |
new_entry = {
|
53 |
'knowledge': entry['knowledge'],
|
|
|
61 |
'summary': entry[f'{"hallucinated" if is_hallucinated else "right"}_summary'],
|
62 |
'hallucination': 'yes' if is_hallucinated else 'no'
|
63 |
}
|
64 |
+
assert new_entry is not None
|
65 |
+
new_entry_lst += [new_entry]
|
66 |
new_ds_map = list_to_dict(new_entry_lst)
|
67 |
new_ds = Dataset.from_dict(new_ds_map)
|
68 |
new_dsd = DatasetDict({'data': new_ds})
|
src/backend/tasks/halueval/halueval_dialogue.yaml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
task: halueval_qa
|
2 |
+
dataset_path: pminervini/HaluEval
|
3 |
+
dataset_name: dialogue_samples
|
4 |
+
output_type: generate_until
|
5 |
+
training_split: data
|
6 |
+
validation_split: data
|
7 |
+
doc_to_text: !function utils.doc_to_text_dialogue
|
8 |
+
doc_to_target: !function utils.doc_to_target_dialogue
|
9 |
+
process_results: !function utils.process_results_qa
|
10 |
+
fewshot_delimiter: "\n"
|
11 |
+
generation_kwargs:
|
12 |
+
until:
|
13 |
+
- "\n"
|
14 |
+
- "."
|
15 |
+
- ","
|
16 |
+
do_sample: false
|
17 |
+
temperature: 0.0
|
18 |
+
filter_list:
|
19 |
+
- name: remove_whitespace
|
20 |
+
filter:
|
21 |
+
- function: remove_whitespace
|
22 |
+
- function: take_first
|
23 |
+
target_delimiter: " "
|
24 |
+
metric_list:
|
25 |
+
- metric: em
|
26 |
+
aggregation: mean
|
27 |
+
higher_is_better: true
|
28 |
+
- metric: correctness
|
29 |
+
aggregation: mean
|
30 |
+
higher_is_better: true
|
31 |
+
metadata:
|
32 |
+
- version: 0.0
|
src/backend/tasks/halueval/halueval_summarization.yaml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
task: halueval_qa
|
2 |
+
dataset_path: pminervini/HaluEval
|
3 |
+
dataset_name: summarization_samples
|
4 |
+
output_type: generate_until
|
5 |
+
training_split: data
|
6 |
+
validation_split: data
|
7 |
+
doc_to_text: !function utils.doc_to_text_summarization
|
8 |
+
doc_to_target: !function utils.doc_to_target_summarization
|
9 |
+
process_results: !function utils.process_results_qa
|
10 |
+
fewshot_delimiter: "\n"
|
11 |
+
generation_kwargs:
|
12 |
+
until:
|
13 |
+
- "\n"
|
14 |
+
- "."
|
15 |
+
- ","
|
16 |
+
do_sample: false
|
17 |
+
temperature: 0.0
|
18 |
+
filter_list:
|
19 |
+
- name: remove_whitespace
|
20 |
+
filter:
|
21 |
+
- function: remove_whitespace
|
22 |
+
- function: take_first
|
23 |
+
target_delimiter: " "
|
24 |
+
metric_list:
|
25 |
+
- metric: em
|
26 |
+
aggregation: mean
|
27 |
+
higher_is_better: true
|
28 |
+
- metric: correctness
|
29 |
+
aggregation: mean
|
30 |
+
higher_is_better: true
|
31 |
+
metadata:
|
32 |
+
- version: 0.0
|
src/backend/tasks/halueval/utils.py
CHANGED
@@ -34,13 +34,85 @@ You are trying to determine if the answer can be correctly inferred from the kno
|
|
34 |
|
35 |
You should try your best to determine if the answer contains non-factual or hallucinated information according to the above hallucination types. The answer you give MUST be \"Yes\" or \"No\""."""
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
def doc_to_text_qa(doc: dict[str, str]) -> str:
|
39 |
# print('XXX doc_to_text_qa')
|
|
|
40 |
doc_text = QA_INSTURCTIONS + "\n\n#Question#: " + doc["question"] + "\n#Answer#: " + doc["answer"] + "\n#Your Judgement#:"
|
41 |
return doc_text
|
42 |
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
def doc_to_target_qa(doc: dict[str, str]) -> str:
|
45 |
# print('XXX doc_to_target_qa')
|
46 |
return doc['hallucination']
|
|
|
34 |
|
35 |
You should try your best to determine if the answer contains non-factual or hallucinated information according to the above hallucination types. The answer you give MUST be \"Yes\" or \"No\""."""
|
36 |
|
37 |
+
DIALOGUE_INSTRUCTIONS = """I want you act as a response judge. Given a dialogue history and a response, your objective is to determine if the provided response contains non-factual or hallucinated information. You SHOULD give your judgement based on the following hallucination types and the world knowledge.
|
38 |
+
|
39 |
+
You are trying to determine if the true entity in the response is replaced with a highly similar entity.
|
40 |
+
#Dialogue History#: [Human]: Could you recommand movies similar to The Dark Knight? [Assistant]: The sequel to Batman Begins is The Dark Knight. [Human]: Okay. Who is the director of The Dark Knight and any other movies from him not related to Batman?
|
41 |
+
#Response#: Christopher Nolan was the director. He also directed insomnia and inception.
|
42 |
+
#Your Judgement#: No
|
43 |
+
#Dialogue History#: [Human]: Could you recommand movies similar to The Dark Knight? [Assistant]: The sequel to Batman Begins is The Dark Knight. [Human]: Okay. Who is the director of The Dark Knight and any other movies from him not related to Batman?
|
44 |
+
#Response#: Steven Spielberg was the director. He also directed insomnia and inception.
|
45 |
+
#Your Judgement#: Yes
|
46 |
+
|
47 |
+
You are trying to determine if the true entity in the response is replaced with a dissimilar entity.
|
48 |
+
#Dialogue History#: [Human]: Could you recommand movies similar to The Dark Knight? [Assistant]: The sequel to Batman Begins is The Dark Knight. [Human]: Okay. Who is the director of The Dark Knight and any other movies from him not related to Batman?
|
49 |
+
#Response#: Christopher Nolan was the director. He also directed insomnia and inception.
|
50 |
+
#Your Judgement#: No
|
51 |
+
#Dialogue History#: [Human]: Could you recommand movies similar to The Dark Knight? [Assistant]: The sequel to Batman Begins is The Dark Knight. [Human]: Okay. Who is the director of The Dark Knight and any other movies from him not related to Batman?
|
52 |
+
#Response#: Batman Begins was the director. He also directed insomnia and inception.
|
53 |
+
#Your Judgement#: Yes
|
54 |
+
|
55 |
+
You are trying to determine if the true entity in the response is replaced with a dissimilar entity in a different entity type.
|
56 |
+
#Dialogue History#: [Human]: Could you recommand movies similar to The Dark Knight? [Assistant]: The sequel to Batman Begins is The Dark Knight. [Human]: Okay. Who is the director of The Dark Knight and any other movies from him not related to Batman?
|
57 |
+
#Response#: Christopher Nolan was the director. He also directed insomnia and inception.
|
58 |
+
#Your Judgement#: No
|
59 |
+
#Dialogue History#: [Human]: Could you recommand movies similar to The Dark Knight? [Assistant]: The sequel to Batman Begins is The Dark Knight. [Human]: Okay. Who is the director of The Dark Knight and any other movies from him not related to Batman?
|
60 |
+
#Response#: United States of America was the director. He also directed insomnia and inception.
|
61 |
+
#Your Judgement#: Yes
|
62 |
+
|
63 |
+
You should try your best to determine if the response contains non-factual or hallucinated information according to the above hallucination types. The answer you give MUST be \"Yes\" or \"No\""."""
|
64 |
+
|
65 |
+
SUMMARIZATION_INSTRUCTIONS = """I want you act as a summary judge. Given a document and a summary, your objective is to determine if the provided summary contains non-factual or hallucinated information. You SHOULD give your judgement based on the following hallucination types and the world knowledge.
|
66 |
+
|
67 |
+
You are trying to determine if the summary is factual but some information cannot be directly inferred or entailed from the document.
|
68 |
+
#Document#: The panther chameleon was found on Monday by a dog walker in the wooded area at Marl Park. It had to be put down after X-rays showed all of its legs were broken and it had a deformed spine. RSPCA Cymru said it was an "extremely sad example of an abandoned and neglected exotic pet". Inspector Selina Chan said: "It is a possibility that the owners took on this animal but were unable to provide the care he needs and decided to release him to the wild. "We are urging potential owners of exotic animals to thoroughly research what is required in the care of the particular species before taking one on. "Potential owners need to make sure they can give their animal the environment it needs and they have the facilities, time, financial means and long-term commitment to maintain a good standard of care, as required under the Animal Welfare Act 2006." She added it was illegal to release non-native species into the wild.
|
69 |
+
#Summary#: A chameleon that was found in a Cardiff park has been put down after being abandoned and neglected by its owners.
|
70 |
+
#Your Judgement#: Yes
|
71 |
+
|
72 |
+
You are trying to determine if there exists some non-factual and incorrect information in the summary.
|
73 |
+
#Document#: The city was brought to a standstill on 15 December last year when a gunman held 18 hostages for 17 hours. Family members of victims Tori Johnson and Katrina Dawson were in attendance. Images of the floral tributes that filled the city centre in the wake of the siege were projected on to the cafe and surrounding buildings in an emotional twilight ceremony. Prime Minister Malcolm Turnbull gave an address saying a "whole nation resolved to answer hatred with love". "Testament to the spirit of Australians is that with such unnecessary, thoughtless tragedy, an amazing birth of mateship, unity and love occurs. Proud to be Australian," he said. How the Sydney siege unfolded New South Wales Premier Mike Baird has also announced plans for a permanent memorial to be built into the pavement in Martin Place. Clear cubes containing flowers will be embedded into the concrete and will shine with specialised lighting. It is a project inspired by the massive floral tributes that were left in the days after the siege. "Something remarkable happened here. As a city we were drawn to Martin Place. We came in shock and in sorrow but every step we took was with purpose," he said on Tuesday.
|
74 |
+
#Summary#: Crowds have gathered in Sydney's Martin Place to honour the victims of the Lindt cafe siege, one year on.
|
75 |
+
#Your Judgement#: No
|
76 |
+
|
77 |
+
You are trying to determine if there is a factual contradiction between the summary and the document.
|
78 |
+
#Document#: Christopher Huxtable, 34, from Swansea, had been missing since the collapse in February. His body was found on Wednesday and workers who carried out the search formed a guard of honour as it was driven from the site in the early hours of the morning. Ken Cresswell, 57, and John Shaw, 61, both from Rotherham, remain missing. The body of a fourth man, Michael Collings, 53, from Brotton, Teesside, was previously recovered from the site. Swansea East MP Carolyn Harris, who has been involved with the family since the incident, said they still did not know all the facts about the collapse. She said: "I feel very sad. My heart and my prayers go out to the family who have waited desperately for Christopher's body to be found. They can finally have closure, and say goodbye to him and grieve his loss. "But let's not forget that there's two other families who are still waiting for their loved ones to be returned." The building was due for demolition when it partially collapsed in February.
|
79 |
+
#Summary#: The body of a man whose body was found at the site of the Swansea Bay Power Station collapse has been removed from the site.
|
80 |
+
#Your Judgement#: Yes
|
81 |
+
|
82 |
+
You should try your best to determine if the summary contains non-factual or hallucinated information according to the above hallucination types. The answer you give MUST be \"Yes\" or \"No\""."""
|
83 |
+
|
84 |
|
85 |
def doc_to_text_qa(doc: dict[str, str]) -> str:
|
86 |
# print('XXX doc_to_text_qa')
|
87 |
+
# prompt = instruction + "\n\n#Question#: " + question + "\n#Answer#: " + answer + "\n#Your Judgement#:"
|
88 |
doc_text = QA_INSTURCTIONS + "\n\n#Question#: " + doc["question"] + "\n#Answer#: " + doc["answer"] + "\n#Your Judgement#:"
|
89 |
return doc_text
|
90 |
|
91 |
|
92 |
+
def doc_to_text_dialogue(doc: dict[str, str]) -> str:
|
93 |
+
# print('XXX doc_to_text_dialogue')
|
94 |
+
# prompt = instruction + "\n\n#Dialogue History#: " + dialog + "\n#Response#: " + response + "\n#Your Judgement#:"
|
95 |
+
doc_text = DIALOGUE_INSTRUCTIONS + "\n\n#Dialogue History#: " + doc["dialogue_history"] + "\n#Response#: " + doc["response"] + "\n#Your Judgement#:"
|
96 |
+
return doc_text
|
97 |
+
|
98 |
+
|
99 |
+
def doc_to_text_summarization(doc: dict[str, str]) -> str:
|
100 |
+
# print('XXX doc_to_text_dialogue')
|
101 |
+
# prompt1 = instruction + "\n\n#Document#: " + document
|
102 |
+
# prompt2 = "\n#Summary#: " + summary + "\n#Your Judgement#:"
|
103 |
+
doc_text_1 = SUMMARIZATION_INSTRUCTIONS + "\n\n#Document#: " + doc["document"]
|
104 |
+
doc_text_2 = "\n#Summary#: " + doc["summary"] + "\n#Your Judgement#:"
|
105 |
+
doc_text = doc_text_1 + doc_text_2
|
106 |
+
return doc_text
|
107 |
+
|
108 |
+
|
109 |
+
def doc_to_text_summarization(doc: dict[str, str]) -> str:
|
110 |
+
# print('XXX doc_to_text_dialogue')
|
111 |
+
# prompt = instruction + "\n\n#Dialogue History#: " + dialog + "\n#Response#: " + response + "\n#Your Judgement#:"
|
112 |
+
doc_text = DIALOGUE_INSTRUCTIONS + "\n\n#Dialogue History#: " + doc["question"] + "\n#Answer#: " + doc["answer"] + "\n#Your Judgement#:"
|
113 |
+
return doc_text
|
114 |
+
|
115 |
+
|
116 |
def doc_to_target_qa(doc: dict[str, str]) -> str:
|
117 |
# print('XXX doc_to_target_qa')
|
118 |
return doc['hallucination']
|