# 读取JSON/JSONL文件 defread_json_data(file_path): if file_path.endswith('.json'): withopen(file_path, 'r', encoding='utf-8') as f: return json.load(f) elif file_path.endswith('.jsonl'): data = [] withopen(file_path, 'r', encoding='utf-8') as f: for line in f: data.append(json.loads(line)) return data else: raise ValueError("不支持的文件格式")
# 添加主 answers 中的答案(如果存在且不为空) if"answers"in item and item["answers"]: merged_answers.extend(item["answers"])
# 添加 qa_pairs 中的答案(如果存在且不为空) if"qa_pairs"in item and item["qa_pairs"]: for qa_pair in item["qa_pairs"]: if"answers"in qa_pair and qa_pair["answers"]: merged_answers.extend(qa_pair["answers"])
return merged_answers
# 检查答案是否出现在任何段落中 defcheck_answer_in_contexts(item): # 获取所有可能的答案 all_answers = merge_answers(item) all_answers = [normalize_answer(ans) for ans in all_answers if ans.strip()]
# 使用 Wikipedia 转储作为检索源 searcher = LuceneSearcher.from_prebuilt_index('wikipedia-dpr') # 检索与给定查询相关的文档 hits = searcher.search('who got the first nobel prize in physics') # 显示检索到的文档和相关性分数 print(f'doc: {searcher.doc(hits[0].docid).raw()}\nscore: {hits[0].score}')
PYTHON
doc: {
"id" : "628725",
"contents" : "\"Nobel Prize in Physics\"\nreceive a diploma, a medal and a document confirming the prize amount. Nobel Prize in Physics The Nobel Prize in Physics () is a yearly award given by the Royal Swedish Academy of Sciences for those who have made the most outstanding contributions for mankind in the field of physics. It is one of the five Nobel Prizes established by the will of Alfred Nobel in 1895 and awarded since 1901; the others being the Nobel Prize in Chemistry, Nobel Prize in Literature, Nobel Peace Prize, and Nobel Prize in Physiology or Medicine. The first Nobel Prize in Physics was"
}
score: 16.33108901977539
TEXT
密集检索(DPR):
1 2 3 4 5 6 7 8 9 10 11
from pyserini.encode import DprQueryEncoder from pyserini.search.faiss import FaissSearcher
# 加载查询编码器 encoder = DprQueryEncoder("facebook/dpr-question_encoder-single-nq-base") # 使用 Wikipedia 转储 作为检索源 searcher = FaissSearcher.from_prebuilt_index('wikipedia-dpr-100w.dpr-single-nq', encoder) # 检索与给定查询相关的文档 hits = searcher.search('who got the first nobel prize in physics') # 显示检索到的文档和相关性分数 print(f'doc: {searcher.doc(hits[0].docid).raw()}\nscore: {hits[0].score}')
PYTHON
doc: {
"id" : "284453",
"contents" : "\"Nobel Prize\"\nA group including 42 Swedish writers, artists, and literary critics protested against this decision, having expected Leo Tolstoy to be awarded. Some, including Burton Feldman, have criticised this prize because they consider Prudhomme a mediocre poet. Feldman's explanation is that most of the Academy members preferred Victorian literature and thus selected a Victorian poet. The first Physiology or Medicine Prize went to the German physiologist and microbiologist Emil von Behring. During the 1890s, von Behring developed an antitoxin to treat diphtheria, which until then was causing thousands of deaths each year. The first Nobel Peace Prize went to the Swiss"
}
score: 82.00704956054688
import torch import transformers import types import dataclasses import io import os import json import copy import numpy as np from typing importLiteral from functools import partial from dataclasses import dataclass, field from transformers import Trainer, AutoModelForCausalLM from peft import LoraConfig, TaskType, get_peft_model from typing importDict, Sequence, Union
@dataclass classTrainingArguments(transformers.TrainingArguments): cache_dir: str = field(default=None) # 缓存目录 optim: str = field(default="adamw_torch") # 优化器 model_max_length: int = field( # 模型的最大序列长度 default=4096, metadata={ "help": "Maximum sequence length. Sequences will be right padded to this length (and possibly truncated)." "Enforcing a consistent max length ensures memory usage is constant and predictable." } )
padding: Literal["max_length", "longest"] = field( # 填充策略 default="longest", metadata={ "help": "Padding strategy. If 'max_length', pads to `model_max_length` always; this might lead to some " "redundant compute. If 'longest', pads to the longest sequence in the batch, capped by `model_max_length`." } )
resume_from_checkpoint: bool = field( # 是否从检查点恢复 default=False, metadata={"help": "If True, loads from last check point."} )
use_fast_tokenizer: bool = field( # 是否使用快速分词器 default=False, metadata={ "help": "Use fast tokenizer if True. " "Fast LLaMA tokenizer forces protobuf downgrade to 3.20.3. " "Use fast tokenizer only if you can live with that." } )
# 修改模型的zero_grad方法以节省内存 deflet_model_save_mem_when_zero_grad(model: torch.nn.Module): # 将所有模型参数的梯度设置为零或None defnew_zero_grad(self, set_to_none: bool = True) -> None: ifgetattr(self, "_is_replica", False): warnings.warn( "Calling .zero_grad() from a module created with nn.DataParallel() has no effect. " "The parameters are copied (in a differentiable manner) from the original module. " "This means they are not leaf nodes in autograd and so don't accumulate gradients. " "If you need gradients in your forward method, consider using autograd.grad instead." )
for p inself.parameters(): if p.grad isnotNone: if set_to_none: # 设置为None更节省内存 p.grad = None else: if p.grad.grad_fn isnotNone: p.grad.detach_() else: p.grad.requires_grad_(False) p.grad.zero_()
# 动态修改模型的zero_grad方法 model.zero_grad = types.MethodType(new_zero_grad, model) return model
# 确保文件对象是可读的IO基类 def_make_r_io_base(f, mode: str): ifnotisinstance(f, io.IOBase): f = open(f, mode=mode) return f
# 处理FSDP (完全分片数据并行) 情况 if trainer.is_fsdp_enabled: # 配置完全状态字典,可选的offload到CPU和rank0_only cfg = FullStateDictConfig(offload_to_cpu=True, rank0_only=rank0_only) with FSDP.state_dict_type(trainer.model, StateDictType.FULL_STATE_DICT, cfg): state_dict = trainer.model.state_dict() if trainer.args.should_save: # 只有应该保存的rank才保存 trainer._save(output_dir, state_dict=state_dict) # 保存模型
# 处理DeepSpeed情况 elif trainer.is_deepspeed_enabled: if trainer.args.should_save: trainer._save(output_dir) # DeepSpeed有自己的保存逻辑
else: # 非FSDP和非DeepSpeed情况 state_dict = trainer.model.state_dict() if trainer.args.should_save: cpu_state_dict = {key: value.cpu() for key, value in state_dict.items()} # 转移到CPU del state_dict # 删除原状态字典节省内存 trainer._save(output_dir, state_dict=cpu_state_dict) # 保存CPU上的状态字典
if trainer.args.should_save: if give_rw_access: # 可选设置目录读写权限 try: os.system(f"chmod -R a+xwr {output_dir}") except Exception as e: print(f"Failed to give read-write access to {output_dir}: {e}") print(f"Saving model took {time.perf_counter() - now:.2f} seconds.") # 记录保存耗时
Loading training set from: dataset/ASQA/demos.json
===DEBUG Input:
"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nDocument 1 (Title: Nathan's Hot Dog Eating Contest): competitive eating by downing 50 hot dogs\u2014smashing the previous record of 25.5. The Japanese eater introduced advanced eating and training techniques that shattered previous competitive eating world records. The rise in popularity of the event coincided with the surge in popularity of the worldwide competitive eating circuit. On July 4, 2011, Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women. Previously, women and men had competed against each other, except for one all-female Memorial Day competition held in 1975. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pepto-Bismol-sponsored pink belt and\n\nDocument 2 (Title: Nathan's Hot Dog Eating Contest): Island most years since about 1972, usually in conjunction with Independence Day. Nathan's promoter Mortimer Matz claimed that on July 4, 1916, four immigrants held a hot dog eating contest at Nathan's Famous stand on Coney Island to settle an argument about who was the most patriotic. He also made the spurious claim that the contest has been held each year since then except 1941 (\"as a protest to the war in Europe\") and 1971 (as a protest to political unrest in the U.S.). A man by the name of Jim Mullen is said to have won the first contest,\n\nDocument 3 (Title: Nathan's Hot Dog Eating Contest): called to the stage individually during introductions. In 2013, six-time defending champion Joey Chestnut was escorted to the stage in a sedan chair. The competition draws many spectators and worldwide press coverage. In 2007, an estimated 50,000 came out to witness the event. In 2004 a three-story-high \"Hot Dog Eating Wall of Fame\" was erected at the site of the annual contest. The wall lists past winners, and has a digital clock which counts down the minutes until the next contest. Despite substantial damage suffered at Nathan's due to Hurricane Sandy in October 2012, the location was repaired, reopened, and\n\nDocument 4 (Title: Nathan's Hot Dog Eating Contest): Nathan's Hot Dog Eating Contest The Nathan's Hot Dog Eating Contest is an annual American hot dog competitive eating competition. It is held each year on Independence Day at Nathan's Famous Corporation's original, and best-known restaurant at the corner of Surf and Stillwell Avenues in Coney Island, a neighborhood of Brooklyn, New York City. The contest has gained public attention in recent years due to the stardom of Takeru Kobayashi and Joey Chestnut. The defending men's champion is Joey Chestnut, who ate 74 hot dogs in the 2018 contest. The defending women's champion is Miki Sudo, who ate 37 hot\n\nDocument 5 (Title: Sonya Thomas): at the time. The only eaters besides Kobayashi to defeat Thomas between the 2004 and 2005 Nathan's contests were Bill \"El Wingador\" Simmons in the controversial 2005 Wing Bowl, and Dale Boone, who won a contest eating overheated baked beans after he doused the beans in water to cool them down. On July 4, 2011, Thomas became the first champion of Nathan's Hot Dog Eating Contest for Women. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pink Belt and won $10,000. Thomas had won 1st place in the National Buffalo Wing Festival US chicken wing eating championship\n\nBased on your knowledge and the provided information, answer the question:\n{question}who won nathan's hot dog eating contest?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nThe documents that are useful to answer the question \"Who won Nathan's hot dog eating contest?\" are:\n\n* Document 1: Nathan's Hot Dog Eating Contest\n* Document 5: Sonya Thomas\n\nDocument 1 provides information about the history of the contest, including the fact that Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women in 2011.\n\nDocument 5 provides more information about Sonya Thomas, including her achievements in competitive eating, including winning the Nathan's Hot Dog Eating Contest for Women in 2011.\n\nBased on these documents, we can conclude that Sonya Thomas won the Nathan's Hot Dog Eating Contest for Women in 2011.\n\nHowever, the provided answer mentions the champions of the 2021 edition, which is not mentioned in the provided documents. Therefore, we cannot determine the winners of the contest for years after 2011 based on the provided information.\n\nIn conclusion, the answer to the question \"Who won Nathan's hot dog eating contest?\" is Sonya Thomas, who won the Nathan's Hot Dog Eating Contest for Women in 2011.<|eot_id|>"===
===DEBUG Target:
tensor([ 791, 9477, 430, 527, 5505, 311, 4320, 279, 3488,
330, 15546, 2834, 37837, 596, 4106, 5679, 12459, 14130,
7673, 527, 1473, 9, 12051, 220, 16, 25, 37837,
596, 8166, 14588, 60638, 47633, 198, 9, 12051, 220,
20, 25, 21533, 64, 11355, 271, 7676, 220, 16,
5825, 2038, 922, 279, 3925, 315, 279, 14130, 11,
2737, 279, 2144, 430, 21533, 64, 11355, 6244, 279,
18824, 315, 279, 1176, 37837, 596, 8166, 14588, 60638,
47633, 369, 11215, 304, 220, 679, 16, 382, 7676,
220, 20, 5825, 810, 2038, 922, 21533, 64, 11355,
11, 2737, 1077, 33997, 304, 15022, 12459, 11, 2737,
11230, 279, 37837, 596, 8166, 14588, 60638, 47633, 369,
11215, 304, 220, 679, 16, 382, 29815, 389, 1521,
9477, 11, 584, 649, 32194, 430, 21533, 64, 11355,
2834, 279, 37837, 596, 8166, 14588, 60638, 47633, 369,
11215, 304, 220, 679, 16, 382, 11458, 11, 279,
3984, 4320, 34945, 279, 34838, 315, 279, 220, 2366,
16, 14002, 11, 902, 374, 539, 9932, 304, 279,
3984, 9477, 13, 15636, 11, 584, 4250, 8417, 279,
26526, 315, 279, 14130, 369, 1667, 1306, 220, 679,
16, 3196, 389, 279, 3984, 2038, 382, 644, 17102,
11, 279, 4320, 311, 279, 3488, 330, 15546, 2834,
37837, 596, 4106, 5679, 12459, 14130, 7673, 374, 21533,
64, 11355, 11, 889, 2834, 279, 37837, 596, 8166,
14588, 60638, 47633, 369, 11215, 304, 220, 679, 16,
13, 128009]) ==> "The documents that are useful to answer the question \"Who won Nathan's hot dog eating contest?\" are:\n\n* Document 1: Nathan's Hot Dog Eating Contest\n* Document 5: Sonya Thomas\n\nDocument 1 provides information about the history of the contest, including the fact that Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women in 2011.\n\nDocument 5 provides more information about Sonya Thomas, including her achievements in competitive eating, including winning the Nathan's Hot Dog Eating Contest for Women in 2011.\n\nBased on these documents, we can conclude that Sonya Thomas won the Nathan's Hot Dog Eating Contest for Women in 2011.\n\nHowever, the provided answer mentions the champions of the 2021 edition, which is not mentioned in the provided documents. Therefore, we cannot determine the winners of the contest for years after 2011 based on the provided information.\n\nIn conclusion, the answer to the question \"Who won Nathan's hot dog eating contest?\" is Sonya Thomas, who won the Nathan's Hot Dog Eating Contest for Women in 2011.<|eot_id|>"===
Tokenization metadata:
{"num_examples": 2, "input_ids_avg_len": 1099.5, "input_ids_max_len": 1216, "input_ids_min_len": 983, "labels_avg_len": 1099.5, "labels_max_len": 1216, "labels_min_len": 983, "model_max_length": 4096}
trainer.train(resume_from_checkpoint=training_args.resume_from_checkpoint) # 训练完成后记录日志 print("hooray! training finished successfully!\nNow on to model saving -- With mixed precision, FSDP will upcast in the model preparation step, and FSDP will then save checkpoints in the upcasted precision. See: https://huggingface.co/docs/accelerate/en/concept_guides/fsdp_and_deepspeed") trainer.save_state() # 保存训练状态 safe_save_model_for_hf_trainer(trainer=trainer, output_dir=training_args.output_dir) # 安全地保存模型 print("hooray again! model saving worked.")
PYTHON
3.2 inference.py:推理与评估
导入必要的包:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import sys import io import os import json import transformers import copy import torch import functools import string import re import numpy as np from vllm import LLM, SamplingParams from tqdm import tqdm from typing importUnion
[ { "question":"Who won nathan's hot dog eating contest?", "answers":[ "The Nathan's Hot Dog Eating Contest is an annual American hot dog eating competition held on Independence Day at Nathan's Famous Corporation's original restaurant at the corner of Surf and Stillwell Avenues in Coney Island, a neighborhood of Brooklyn, New York City. The current men's and women's competitions champions are Joey Chestnut and Michelle Lesco, who crowned themselves in the 2021 edition. Previously, Miki Sudo had won the women's competition every year from 2014-2020, with Chestnut doing so in the men's variant in 2017 and 2016 and Matt Stonie in 2015." ], "qa_pairs":[ { "question":"Who won the men's competition of Nathan's Hot Dog Eating Contest in 2017?", "answers":[ "Joey Chestnut" ] }, { "question":"Who won the women's competition of Nathan's Hot Dog Eating Contest in 2017?", "answers":[ "Miki Sudo" ] }, { "question":"Who won the men's competition of Nathan's Hot Dog Eating Contest in 2016?", "answers":[ "Joey Chestnut" ] }, { "question":"Who won the women's competition of Nathan's Hot Dog Eating Contest in 2016?", "answers":[ "Miki Sudo" ] }, { "question":"Who won the men's competition of Nathan's Hot Dog Eating Contest in 2015?", "answers":[ "Matt Stonie" ] }, { "question":"Who won the women's competition of Nathan's Hot Dog Eating Contest in 2015?", "answers":[ "Miki Sudo" ] } ], "rationale":"The documents that are useful to answer the question \"Who won Nathan's hot dog eating contest?\" are:\n\n* Document 1: Nathan's Hot Dog Eating Contest\n* Document 5: Sonya Thomas\n\nDocument 1 provides information about the history of the contest, including the fact that Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women in 2011.\n\nDocument 5 provides more information about Sonya Thomas, including her achievements in competitive eating, including winning the Nathan's Hot Dog Eating Contest for Women in 2011.\n\nBased on these documents, we can conclude that Sonya Thomas won the Nathan's Hot Dog Eating Contest for Women in 2011.\n\nHowever, the provided answer mentions the champions of the 2021 edition, which is not mentioned in the provided documents. Therefore, we cannot determine the winners of the contest for years after 2011 based on the provided information.\n\nIn conclusion, the answer to the question \"Who won Nathan's hot dog eating contest?\" is Sonya Thomas, who won the Nathan's Hot Dog Eating Contest for Women in 2011.", "ctxs":[ { "id":"3360010", "title":"Nathan's Hot Dog Eating Contest", "text":"competitive eating by downing 50 hot dogs—smashing the previous record of 25.5. The Japanese eater introduced advanced eating and training techniques that shattered previous competitive eating world records. The rise in popularity of the event coincided with the surge in popularity of the worldwide competitive eating circuit. On July 4, 2011, Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women. Previously, women and men had competed against each other, except for one all-female Memorial Day competition held in 1975. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pepto-Bismol-sponsored pink belt and", "score":0.7802734375 }, { "id":"3360007", "title":"Nathan's Hot Dog Eating Contest", "text":"Island most years since about 1972, usually in conjunction with Independence Day. Nathan's promoter Mortimer Matz claimed that on July 4, 1916, four immigrants held a hot dog eating contest at Nathan's Famous stand on Coney Island to settle an argument about who was the most patriotic. He also made the spurious claim that the contest has been held each year since then except 1941 (\"as a protest to the war in Europe\") and 1971 (as a protest to political unrest in the U.S.). A man by the name of Jim Mullen is said to have won the first contest,", "score":0.7802734375 }, { "id":"3360012", "title":"Nathan's Hot Dog Eating Contest", "text":"called to the stage individually during introductions. In 2013, six-time defending champion Joey Chestnut was escorted to the stage in a sedan chair. The competition draws many spectators and worldwide press coverage. In 2007, an estimated 50,000 came out to witness the event. In 2004 a three-story-high \"Hot Dog Eating Wall of Fame\" was erected at the site of the annual contest. The wall lists past winners, and has a digital clock which counts down the minutes until the next contest. Despite substantial damage suffered at Nathan's due to Hurricane Sandy in October 2012, the location was repaired, reopened, and", "score":0.7958984375 }, { "id":"3360002", "title":"Nathan's Hot Dog Eating Contest", "text":"Nathan's Hot Dog Eating Contest The Nathan's Hot Dog Eating Contest is an annual American hot dog competitive eating competition. It is held each year on Independence Day at Nathan's Famous Corporation's original, and best-known restaurant at the corner of Surf and Stillwell Avenues in Coney Island, a neighborhood of Brooklyn, New York City. The contest has gained public attention in recent years due to the stardom of Takeru Kobayashi and Joey Chestnut. The defending men's champion is Joey Chestnut, who ate 74 hot dogs in the 2018 contest. The defending women's champion is Miki Sudo, who ate 37 hot", "score":0.7978515625 }, { "id":"3425375", "title":"Sonya Thomas", "text":"at the time. The only eaters besides Kobayashi to defeat Thomas between the 2004 and 2005 Nathan's contests were Bill \"El Wingador\" Simmons in the controversial 2005 Wing Bowl, and Dale Boone, who won a contest eating overheated baked beans after he doused the beans in water to cool them down. On July 4, 2011, Thomas became the first champion of Nathan's Hot Dog Eating Contest for Women. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pink Belt and won $10,000. Thomas had won 1st place in the National Buffalo Wing Festival US chicken wing eating championship", "score":0.8037109375 } ] } ]
INFO 04-10 11:21:45 llm_engine.py:98] Initializing an LLM engine (v0.4.1) with config: model='saved_models/InstructRAG-FT/ASQA', speculative_config=None, tokenizer='saved_models/InstructRAG-FT/ASQA', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, tokenizer_revision=None, trust_remote_code=False, dtype=torch.float16, max_seq_len=4096, download_dir=None, load_format=auto, tensor_parallel_size=1, disable_custom_all_reduce=False, quantization=None, enforce_eager=False, kv_cache_dtype=auto, quantization_param_path=None, device_config=cuda, decoding_config=DecodingConfig(guided_decoding_backend='outlines'), seed=0)
INFO 04-10 11:21:45 utils.py:608] Found nccl from library /public/home/jfqu/.config/vllm/nccl/cu12/libnccl.so.2.18.1
INFO 04-10 11:21:48 selector.py:65] Cannot use FlashAttention backend for Volta and Turing GPUs.
INFO 04-10 11:21:48 selector.py:33] Using XFormers backend.
INFO 04-10 11:22:38 model_runner.py:173] Loading model weights took 14.9595 GB
INFO 04-10 11:22:40 gpu_executor.py:119] # GPU blocks: 5774, # CPU blocks: 2048
INFO 04-10 11:22:42 model_runner.py:976] Capturing the model for CUDA graphs. This may lead to unexpected consequences if the model is not static. To run the model in eager mode, set 'enforce_eager=True' or use '--enforce-eager' in the CLI.
INFO 04-10 11:22:42 model_runner.py:980] CUDA graphs can take additional 1~3 GiB memory per GPU. If you are running out of memory, consider decreasing `gpu_memory_utilization` or enforcing eager mode. You can also reduce the `max_num_seqs` as needed to decrease memory usage.
INFO 04-10 11:22:51 model_runner.py:1057] Graph capturing finished in 9 secs.
{ "user_prefix":"<|start_header_id|>user<|end_header_id|>\n\n", "assistant_prefix":"<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n", "query_prompt":"Based on your knowledge and the provided information, answer the question:\n{question}", "demo_task_instruction":"Your task is to analyze the provided documents and answer the given question. Please generate a brief explanation of how the contents of these documents lead to your answer. If the provided information is not helpful to answer the question, you only need to respond based on your own knowledge, without referring to the documents.\n\nBelow are some examples of how to answer the question:\n\n", "demo_prefix":"Read the following documents relevant to the given question: {question}\n\n", "demo_postfix":"###\n\nNow it is your turn to analyze the following documents and answer the given question.\n\n", "rationale_generation_instruction":"Please identify documents that are useful to answer the given question: '{question}', and explain how the contents lead to the answer: {answers}.\n\nIf none of the documents is aligned with the answer, in that case, you have to explain the answer only based on your own knowledge, without referring to the provided information.\n\n", "rationale_generation_postfix_ASQA":"Note that the question may be ambiguous and have multiple correct answers. Make sure your response includes all correct answers and provides clear reasoning details followed by a concise conclusion.", "rationale_generation_postfix_PopQA":"Note that the question mainly asks about the object entity that holds a certain relationship with the given subject entity. There may be multiple correct answers. Make sure your response includes all correct answers and provides clear reasoning details followed by a concise conclusion.", "rationale_generation_postfix_TriviaQA":"Note that the question may be compositional and require intermediate analysis to deduce the final answer. Make sure your response is grounded and provides clear reasoning details followed by a concise conclusion.", "rationale_generation_postfix_NaturalQuestions":"Note that the question may be compositional and require intermediate analysis to deduce the final answer. Make sure your response is grounded and provides clear reasoning details followed by a concise conclusion.", "rationale_generation_postfix_2WikiMultiHopQA":"Note that the question may be compositional and require intermediate analysis to deduce the final answer. Make sure your response is grounded and provides clear reasoning details followed by a concise conclusion." }
100%|██████████| 1/1 [00:00<00:00, 153.02it/s]
[
"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nDocument 1 (Title: Nathan's Hot Dog Eating Contest): competitive eating by downing 50 hot dogs—smashing the previous record of 25.5. The Japanese eater introduced advanced eating and training techniques that shattered previous competitive eating world records. The rise in popularity of the event coincided with the surge in popularity of the worldwide competitive eating circuit. On July 4, 2011, Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women. Previously, women and men had competed against each other, except for one all-female Memorial Day competition held in 1975. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pepto-Bismol-sponsored pink belt and\n\nDocument 2 (Title: Nathan's Hot Dog Eating Contest): Island most years since about 1972, usually in conjunction with Independence Day. Nathan's promoter Mortimer Matz claimed that on July 4, 1916, four immigrants held a hot dog eating contest at Nathan's Famous stand on Coney Island to settle an argument about who was the most patriotic. He also made the spurious claim that the contest has been held each year since then except 1941 (\"as a protest to the war in Europe\") and 1971 (as a protest to political unrest in the U.S.). A man by the name of Jim Mullen is said to have won the first contest,\n\nDocument 3 (Title: Nathan's Hot Dog Eating Contest): called to the stage individually during introductions. In 2013, six-time defending champion Joey Chestnut was escorted to the stage in a sedan chair. The competition draws many spectators and worldwide press coverage. In 2007, an estimated 50,000 came out to witness the event. In 2004 a three-story-high \"Hot Dog Eating Wall of Fame\" was erected at the site of the annual contest. The wall lists past winners, and has a digital clock which counts down the minutes until the next contest. Despite substantial damage suffered at Nathan's due to Hurricane Sandy in October 2012, the location was repaired, reopened, and\n\nDocument 4 (Title: Nathan's Hot Dog Eating Contest): Nathan's Hot Dog Eating Contest The Nathan's Hot Dog Eating Contest is an annual American hot dog competitive eating competition. It is held each year on Independence Day at Nathan's Famous Corporation's original, and best-known restaurant at the corner of Surf and Stillwell Avenues in Coney Island, a neighborhood of Brooklyn, New York City. The contest has gained public attention in recent years due to the stardom of Takeru Kobayashi and Joey Chestnut. The defending men's champion is Joey Chestnut, who ate 74 hot dogs in the 2018 contest. The defending women's champion is Miki Sudo, who ate 37 hot\n\nDocument 5 (Title: Sonya Thomas): at the time. The only eaters besides Kobayashi to defeat Thomas between the 2004 and 2005 Nathan's contests were Bill \"El Wingador\" Simmons in the controversial 2005 Wing Bowl, and Dale Boone, who won a contest eating overheated baked beans after he doused the beans in water to cool them down. On July 4, 2011, Thomas became the first champion of Nathan's Hot Dog Eating Contest for Women. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pink Belt and won $10,000. Thomas had won 1st place in the National Buffalo Wing Festival US chicken wing eating championship\n\nBased on your knowledge and the provided information, answer the question:\nwho won nathan's hot dog eating contest?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
]
Processed prompts: 100%|██████████| 1/1 [00:07<00:00, 7.43s/it]
'The documents provided do not directly answer the question "who won Nathan\'s Hot Dog Eating Contest?" However, they do provide information about the contest, its history, and past winners.\n\nFrom Document 1, we learn that Takeru Kobayashi set a new record by eating 50 hot dogs in 2006, and Sonya Thomas became the champion of the first Nathan\'s Hot Dog Eating Contest for Women in 2011.\n\nFrom Document 4, we learn that the defending men\'s champion is Joey Chestnut, who ate 74 hot dogs in the 2018 contest, and the defending women\'s champion is Miki Sudo, who ate 37 hot dogs in the same contest.\n\nFrom Document 5, we learn that Sonya Thomas became the first champion of Nathan\'s Hot Dog Eating Contest for Women in 2011, eating 40 hot dogs in 10 minutes.\n\nBased on this information, we can conclude that:\n\n* Takeru Kobayashi won the Nathan\'s Hot Dog Eating Contest in 2006, eating 50 hot dogs.\n* Sonya Thomas won the Nathan\'s Hot Dog Eating Contest for Women in 2011, eating 40 hot dogs.\n* Joey Chestnut is the defending men\'s champion, having eaten 74 hot dogs in the 2018 contest.\n* Miki Sudo is the defending women\'s champion, having eaten 37 hot dogs in the 2018 contest.\n\nTherefore, the answer to the question "who won Nathan\'s Hot Dog Eating Contest?" is not a single answer, but rather a list of past winners, including Takeru Kobayashi, Sonya Thomas, Joey Chestnut, and Miki Sudo.'
Outputs saved to ./result.json [ { "question":"Who won nathan's hot dog eating contest?", "answers":[ "The Nathan's Hot Dog Eating Contest is an annual American hot dog eating competition held on Independence Day at Nathan's Famous Corporation's original restaurant at the corner of Surf and Stillwell Avenues in Coney Island, a neighborhood of Brooklyn, New York City. The current men's and women's competitions champions are Joey Chestnut and Michelle Lesco, who crowned themselves in the 2021 edition. Previously, Miki Sudo had won the women's competition every year from 2014-2020, with Chestnut doing so in the men's variant in 2017 and 2016 and Matt Stonie in 2015." ], "qa_pairs":[ { "question":"Who won the men's competition of Nathan's Hot Dog Eating Contest in 2017?", "answers":[ "Joey Chestnut" ] }, { "question":"Who won the women's competition of Nathan's Hot Dog Eating Contest in 2017?", "answers":[ "Miki Sudo" ] }, { "question":"Who won the men's competition of Nathan's Hot Dog Eating Contest in 2016?", "answers":[ "Joey Chestnut" ] }, { "question":"Who won the women's competition of Nathan's Hot Dog Eating Contest in 2016?", "answers":[ "Miki Sudo" ] }, { "question":"Who won the men's competition of Nathan's Hot Dog Eating Contest in 2015?", "answers":[ "Matt Stonie" ] }, { "question":"Who won the women's competition of Nathan's Hot Dog Eating Contest in 2015?", "answers":[ "Miki Sudo" ] } ], "rationale":"The documents provided do not directly answer the question \"who won Nathan's Hot Dog Eating Contest?\" However, they do provide information about the contest, its history, and past winners.\n\nFrom Document 1, we learn that Takeru Kobayashi set a new record by eating 50 hot dogs in 2006, and Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women in 2011.\n\nFrom Document 4, we learn that the defending men's champion is Joey Chestnut, who ate 74 hot dogs in the 2018 contest, and the defending women's champion is Miki Sudo, who ate 37 hot dogs in the same contest.\n\nFrom Document 5, we learn that Sonya Thomas became the first champion of Nathan's Hot Dog Eating Contest for Women in 2011, eating 40 hot dogs in 10 minutes.\n\nBased on this information, we can conclude that:\n\n* Takeru Kobayashi won the Nathan's Hot Dog Eating Contest in 2006, eating 50 hot dogs.\n* Sonya Thomas won the Nathan's Hot Dog Eating Contest for Women in 2011, eating 40 hot dogs.\n* Joey Chestnut is the defending men's champion, having eaten 74 hot dogs in the 2018 contest.\n* Miki Sudo is the defending women's champion, having eaten 37 hot dogs in the 2018 contest.\n\nTherefore, the answer to the question \"who won Nathan's Hot Dog Eating Contest?\" is not a single answer, but rather a list of past winners, including Takeru Kobayashi, Sonya Thomas, Joey Chestnut, and Miki Sudo.", "prompt":"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nDocument 1 (Title: Nathan's Hot Dog Eating Contest): competitive eating by downing 50 hot dogs—smashing the previous record of 25.5. The Japanese eater introduced advanced eating and training techniques that shattered previous competitive eating world records. The rise in popularity of the event coincided with the surge in popularity of the worldwide competitive eating circuit. On July 4, 2011, Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women. Previously, women and men had competed against each other, except for one all-female Memorial Day competition held in 1975. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pepto-Bismol-sponsored pink belt and\n\nDocument 2 (Title: Nathan's Hot Dog Eating Contest): Island most years since about 1972, usually in conjunction with Independence Day. Nathan's promoter Mortimer Matz claimed that on July 4, 1916, four immigrants held a hot dog eating contest at Nathan's Famous stand on Coney Island to settle an argument about who was the most patriotic. He also made the spurious claim that the contest has been held each year since then except 1941 (\"as a protest to the war in Europe\") and 1971 (as a protest to political unrest in the U.S.). A man by the name of Jim Mullen is said to have won the first contest,\n\nDocument 3 (Title: Nathan's Hot Dog Eating Contest): called to the stage individually during introductions. In 2013, six-time defending champion Joey Chestnut was escorted to the stage in a sedan chair. The competition draws many spectators and worldwide press coverage. In 2007, an estimated 50,000 came out to witness the event. In 2004 a three-story-high \"Hot Dog Eating Wall of Fame\" was erected at the site of the annual contest. The wall lists past winners, and has a digital clock which counts down the minutes until the next contest. Despite substantial damage suffered at Nathan's due to Hurricane Sandy in October 2012, the location was repaired, reopened, and\n\nDocument 4 (Title: Nathan's Hot Dog Eating Contest): Nathan's Hot Dog Eating Contest The Nathan's Hot Dog Eating Contest is an annual American hot dog competitive eating competition. It is held each year on Independence Day at Nathan's Famous Corporation's original, and best-known restaurant at the corner of Surf and Stillwell Avenues in Coney Island, a neighborhood of Brooklyn, New York City. The contest has gained public attention in recent years due to the stardom of Takeru Kobayashi and Joey Chestnut. The defending men's champion is Joey Chestnut, who ate 74 hot dogs in the 2018 contest. The defending women's champion is Miki Sudo, who ate 37 hot\n\nDocument 5 (Title: Sonya Thomas): at the time. The only eaters besides Kobayashi to defeat Thomas between the 2004 and 2005 Nathan's contests were Bill \"El Wingador\" Simmons in the controversial 2005 Wing Bowl, and Dale Boone, who won a contest eating overheated baked beans after he doused the beans in water to cool them down. On July 4, 2011, Thomas became the first champion of Nathan's Hot Dog Eating Contest for Women. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pink Belt and won $10,000. Thomas had won 1st place in the National Buffalo Wing Festival US chicken wing eating championship\n\nBased on your knowledge and the provided information, answer the question:\nwho won nathan's hot dog eating contest?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n", "ctxs":[ { "id":"3360010", "title":"Nathan's Hot Dog Eating Contest", "text":"competitive eating by downing 50 hot dogs—smashing the previous record of 25.5. The Japanese eater introduced advanced eating and training techniques that shattered previous competitive eating world records. The rise in popularity of the event coincided with the surge in popularity of the worldwide competitive eating circuit. On July 4, 2011, Sonya Thomas became the champion of the first Nathan's Hot Dog Eating Contest for Women. Previously, women and men had competed against each other, except for one all-female Memorial Day competition held in 1975. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pepto-Bismol-sponsored pink belt and", "score":0.7802734375 }, { "id":"3360007", "title":"Nathan's Hot Dog Eating Contest", "text":"Island most years since about 1972, usually in conjunction with Independence Day. Nathan's promoter Mortimer Matz claimed that on July 4, 1916, four immigrants held a hot dog eating contest at Nathan's Famous stand on Coney Island to settle an argument about who was the most patriotic. He also made the spurious claim that the contest has been held each year since then except 1941 (\"as a protest to the war in Europe\") and 1971 (as a protest to political unrest in the U.S.). A man by the name of Jim Mullen is said to have won the first contest,", "score":0.7802734375 }, { "id":"3360012", "title":"Nathan's Hot Dog Eating Contest", "text":"called to the stage individually during introductions. In 2013, six-time defending champion Joey Chestnut was escorted to the stage in a sedan chair. The competition draws many spectators and worldwide press coverage. In 2007, an estimated 50,000 came out to witness the event. In 2004 a three-story-high \"Hot Dog Eating Wall of Fame\" was erected at the site of the annual contest. The wall lists past winners, and has a digital clock which counts down the minutes until the next contest. Despite substantial damage suffered at Nathan's due to Hurricane Sandy in October 2012, the location was repaired, reopened, and", "score":0.7958984375 }, { "id":"3360002", "title":"Nathan's Hot Dog Eating Contest", "text":"Nathan's Hot Dog Eating Contest The Nathan's Hot Dog Eating Contest is an annual American hot dog competitive eating competition. It is held each year on Independence Day at Nathan's Famous Corporation's original, and best-known restaurant at the corner of Surf and Stillwell Avenues in Coney Island, a neighborhood of Brooklyn, New York City. The contest has gained public attention in recent years due to the stardom of Takeru Kobayashi and Joey Chestnut. The defending men's champion is Joey Chestnut, who ate 74 hot dogs in the 2018 contest. The defending women's champion is Miki Sudo, who ate 37 hot", "score":0.7978515625 }, { "id":"3425375", "title":"Sonya Thomas", "text":"at the time. The only eaters besides Kobayashi to defeat Thomas between the 2004 and 2005 Nathan's contests were Bill \"El Wingador\" Simmons in the controversial 2005 Wing Bowl, and Dale Boone, who won a contest eating overheated baked beans after he doused the beans in water to cool them down. On July 4, 2011, Thomas became the first champion of Nathan's Hot Dog Eating Contest for Women. Eating 40 hot dogs in 10 minutes, Thomas earned the inaugural Pink Belt and won $10,000. Thomas had won 1st place in the National Buffalo Wing Festival US chicken wing eating championship", "score":0.8037109375 } ] } ]
acc = [] # 存储每个QA对的准确率 hit = [] # 存储是否完全命中(所有QA对均准确)
for item in data: loc_acc = [] # 临时存储当前item中每个QA对的检查结果 for qa_pair in item['qa_pairs']: # 检查当前QA对的答案是否出现在rationale中 loc_acc.append(exact_presence(qa_pair['answers'], item["rationale"]))