File size: 36,572 Bytes
73599cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
from functools import partial
import datasets
def prepare_base(
dataset, input_column, output_column, prompt=None
) -> tuple[list[str], list[str], dict[str, list[str]]]:
x, y = dataset[input_column], dataset[output_column]
if prompt:
for i in range(len(x)):
x[i] = prompt.format(text=x[i])
return x, y
def prepare_babi_qa(dataset, input_column, output_column, prompt):
x, y = [], []
for inst in dataset:
inst = inst["story"]
context = ""
for text, answer in zip(inst[input_column], inst[output_column]):
if answer == "":
context += text + " "
else:
x.append(prompt.format(context=context.strip(), question=text))
y.append(answer)
return x, y
def prepare_coqa(
dataset, input_column, output_column, description, prompt, few_shot_prompt, instruct
):
def doc_to_text(doc, prompt, i=0):
# Given a passage p, the conversation history {q1, a1, . . . qi−1, ai−1}
# and a question qi, the task is to predict the answer ai
doc_text = ""
for q, a in zip(doc["questions"][:i], doc["answers"]["input_text"][:i]):
doc_text += "\n\n" + prompt.format(question=q, answer=a)
return doc_text
x, y = [], []
for inst in dataset:
formatted_description = description.format(story=inst["story"])
for j, (question, answer) in enumerate(
zip(inst[input_column], inst[output_column]["input_text"])
):
if instruct:
assert (
few_shot_prompt is not None
), "separate few_shot_prompt must be provided for instruction mode."
few_shot_section = doc_to_text(inst, few_shot_prompt, j)
if few_shot_section != "":
few_shot_section = (
"\n\nHere are a few examples of questions and answers:"
+ few_shot_section
+ "\n\nNow answer the following question in the same format.\n\n"
)
else:
few_shot_section = "\n\n"
else:
few_shot_section = doc_to_text(inst, prompt, j) + "\n\n"
formatted_prompt = (
formatted_description
+ few_shot_section
+ prompt.format(
question=question,
answer="",
)
)
x.append(formatted_prompt)
y.append(answer)
return x, y
def prepare_mmlu(
dataset,
output_column,
prompt,
description,
mmlu_max_subject_size,
n_shot,
few_shot_dataset_func,
few_shot_prompt,
instruct,
):
import numpy as np
np.random.seed(1)
few_shot_dataset = few_shot_dataset_func()
answers = ["A", "B", "C", "D"]
subjects = np.array(dataset["subject"])
few_shot_subjects = np.array(few_shot_dataset["subject"])
x, y = [], []
for subject in np.unique(subjects):
formatted_description = description.format(subject=subject.replace("_", " "))
if n_shot > 0:
few_shot_subject = few_shot_dataset.select(
np.argwhere(few_shot_subjects == subject).flatten()
)
few_shot_ids = np.random.choice(
len(few_shot_subject), n_shot, replace=False
)
few_shot_data = few_shot_subject.select(few_shot_ids)
if instruct:
assert (
few_shot_prompt is not None
), "separate few_shot_prompt must be provided for instruction mode."
formatted_few_shot_prompt = (
"Here are a few examples of questions and answers:\n\n"
)
for inst in few_shot_data:
formatted_few_shot_prompt += (
few_shot_prompt.format(
choices=inst["choices"],
question=inst["question"].strip(),
answer=answers[inst["answer"]],
)
+ "\n\n"
)
formatted_few_shot_prompt += (
"Now answer the following question in the same format:\n\n"
)
else:
formatted_few_shot_prompt = ""
for inst in few_shot_data:
formatted_few_shot_prompt += (
prompt.format(
choices=inst["choices"],
question=inst["question"].strip(),
answer=answers[inst["answer"]],
)
+ "\n"
)
subject_data = dataset.select(np.argwhere(subjects == subject).flatten())
if len(subject_data) > mmlu_max_subject_size:
subject_data = subject_data.select(range(mmlu_max_subject_size))
for inst in subject_data:
formatted_prompt = prompt.format(
choices=inst["choices"],
question=inst["question"].strip(),
answer="",
)
x.append(
formatted_description
+ "\n\n"
+ formatted_few_shot_prompt
+ formatted_prompt
)
y.append(answers[inst[output_column]])
return x, y
def prepare_person(dataset, input_column, prompt=""):
x = dataset[input_column]
if len(prompt):
for i in range(len(x)):
x[i] = prompt.format(text=x[i])
y = []
for _ in x:
y.append("")
return x, y
def prepare_trivia_qa(
dataset,
prompt,
n_shot,
few_shot_dataset_func,
description,
few_shot_prompt,
instruct,
):
import numpy as np
np.random.seed(1)
few_shot_dataset = few_shot_dataset_func()
x, y = [], []
formatted_few_shot_prompt = description
if n_shot > 0:
few_shot_ids = np.random.choice(len(few_shot_dataset), n_shot, replace=False)
few_shot_data = few_shot_dataset.select(few_shot_ids)
if instruct:
assert (
few_shot_prompt is not None
), "separate few_shot_prompt must be provided for instruction mode."
formatted_few_shot_prompt += (
"\n\nHere are a few examples of questions and answers:\n\n"
)
for inst in few_shot_data:
formatted_few_shot_prompt += (
few_shot_prompt.format(
question=inst["question"].strip(),
answer=inst["answer"]["normalized_value"],
)
+ "\n\n"
)
formatted_few_shot_prompt += (
"Now answer the following question in the same format:\n\n"
)
else:
formatted_few_shot_prompt = ""
for inst in few_shot_data:
formatted_few_shot_prompt += (
prompt.format(
question=inst["question"].strip(),
answer=inst["answer"]["normalized_value"],
)
+ "\n\n"
)
else:
formatted_few_shot_prompt += "\n"
for inst in dataset:
if instruct:
x.append(
formatted_few_shot_prompt + prompt.format(question=inst["question"])
)
else:
x.append(
formatted_few_shot_prompt
+ prompt.format(question=inst["question"], answer="")
)
y.append([alias for alias in inst["answer"]["aliases"]])
return x, y
def prepare_wiki(dataset, input_column, prompt):
x, y = [], []
for sample in dataset[input_column]:
x.append(prompt.format(context=sample["context".strip()]))
y.append("")
return x, y
def prepare_wmt(dataset, input_column, output_column, prompt):
column_lang = {
"de": "German",
"fr": "French",
"en": "English",
}
x, y = [], []
for inst in dataset["translation"]:
x.append(
prompt.format(
source_lang=column_lang[input_column],
target_lang=column_lang[output_column],
text=inst[input_column],
)
)
y.append(inst[output_column])
return x, y
def prepare_allenai(dataset, input_column, output_column):
x, y = [], []
for inst in dataset:
if len(inst[input_column]) <= 1024:
x.append(inst[input_column])
y.append(inst[output_column])
return x, y
def generate_coqa_instruct_config(description, few_shot_prompt):
return {
"name": "coqa",
"train_split": "train",
"test_split": "validation",
"prepare_func": partial(
prepare_coqa,
input_column="questions",
output_column="answers",
description=description,
prompt="Question: {question}\n",
few_shot_prompt=few_shot_prompt,
instruct=True,
),
"is_main_dataset": False,
}
def generate_mmlu_instruct_config(description, few_shot_prompt):
return {
"name": ["cais/mmlu", "all"],
"train_split": "validation",
"test_split": "test",
"prepare_func": partial(
prepare_mmlu,
output_column="answer",
prompt="Q:{question}\nA. {choices[0]}\nB. {choices[1]}\nC. {choices[2]}\nD. {choices[3]}\nAnswer:{answer}",
description=description,
mmlu_max_subject_size=100,
n_shot=5,
few_shot_dataset_func=partial(
datasets.load_dataset, path="cais/mmlu", name="all", split="dev"
),
few_shot_prompt=few_shot_prompt,
instruct=True,
),
"is_main_dataset": False,
}
def generate_triviaqa_instruct_config(description, few_shot_prompt):
return {
"name": ["trivia_qa", "rc.nocontext"],
"train_split": "train",
"test_split": "validation",
"prepare_func": partial(
prepare_trivia_qa,
prompt="Question: {question}\n",
n_shot=5,
few_shot_dataset_func=partial(
datasets.load_dataset,
path="trivia_qa",
name="rc.nocontext",
split="train",
),
description=description,
few_shot_prompt=few_shot_prompt,
instruct=True,
),
"is_main_dataset": False,
}
DATASET_CONFIG = {
"trivia_qa_tiny": {
"name": "SpeedOfMagic/trivia_qa_tiny",
"train_split": "train",
"test_split": "test",
"prepare_func": partial(
prepare_base, input_column="question", output_column="answer"
),
},
"aeslc": {
"name": "aeslc",
"train_split": "train",
"test_split": "test",
"prepare_func": partial(
prepare_base,
input_column="email_body",
output_column="subject_line",
# prompt is set but not used in LM-Polygraph for this dataset (bug)
# prompt="Write a short subject line for the email. Output only the subject line itself.\n\nEmail:\n{text}\n\nSubject line:\n",
),
},
"babi_qa": {
"name": ["facebook/babi_qa", "en-10k-qa1"],
"train_split": "train",
"test_split": "test",
"prepare_func": partial(
prepare_babi_qa,
input_column="text",
output_column="answer",
prompt="Imagine that you are only able to say a single word. Answer the question given a context. You must only output the full name of the location the same way it is mentioned in the text. Do not try to be polite of helpful.\n\nExample:\n\nContext:\nMary moved to the bathroom. John went to the hallway. Daniel went back to the hallway. Sandra moved to the garden. John moved to the office. Sandra journeyed to the bathroom. Mary moved to the hallway. Daniel travelled to the office. John went back to the garden. John moved to the bedroom.\nQuestion:\nWhere is Sandra?\nAnswer:\nbathroom\n\nContext:\n{context}\n\nQuestion:\n{question}\nAnswer:\n",
),
},
"coqa": {
"name": "coqa",
"train_split": "train",
"test_split": "validation",
"prepare_func": partial(
prepare_coqa,
input_column="questions",
output_column="answers",
description="The following are stories and questions about them. Each story is followed by a question and answer to a given question.\n\nStory: {story}",
prompt="Question: {question}\nAnswer:{answer}",
few_shot_prompt=None,
instruct=False,
),
},
"gsm8k": {
"name": ["gsm8k", "main"],
"train_split": "train",
"test_split": "test",
"prepare_func": partial(
prepare_base,
input_column="question",
output_column="answer",
prompt="Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?\nA: There are 15 trees originally. Then there were 21 trees after some more were planted. So there must have been 21 - 15 = 6. The answer is 6.\n\nQ: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?\nA: There are originally 3 cars. 2 more cars arrive. 3 + 2 = 5. The answer is 5.\n\nQ: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?\nA: Originally, Leah had 32 chocolates. Her sister had 42. So in total they had 32 + 42 = 74. After eating 35, they had 74 - 35 = 39. The answer is 39.\n\nQ: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?\nA: Jason started with 20 lollipops. Then he had 12 after giving some to Denny. So he gave Denny 20 - 12 = 8. The answer is 8.\n\nQ: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?\nA: Shawn started with 5 toys. If he got 2 toys each from his mom and dad, then that is 4 more toys. 5 + 4 = 9. The answer is 9.\n\nQ: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?\nA: There were originally 9 computers. For each of 4 days, 5 more computers were added. So 5 * 4 = 20 computers were added. 9 + 20 is 29. The answer is 29.\n\nQ: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?\nA: Michael started with 58 golf balls. After losing 23 on tuesday, he had 58 - 23 = 35. After losing 2 more, he had 35 - 2 = 33 golf balls. The answer is 33.\n\nQ: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?\nA: Olivia had 23 dollars. 5 bagels for 3 dollars each will be 5 x 3 = 15 dollars. So she has 23 - 15 dollars left. 23 - 15 is 8. The answer is 8.\n\nQ: {text}\nA:",
),
},
"mmlu": {
"name": ["cais/mmlu", "all"],
"train_split": "validation",
"test_split": "test",
"prepare_func": partial(
prepare_mmlu,
output_column="answer",
prompt="Q:{question}\nA. {choices[0]}\nB. {choices[1]}\nC. {choices[2]}\nD. {choices[3]}\nAnswer:{answer}",
description="The following are multiple choice questions (with answers) about {subject}.\n",
mmlu_max_subject_size=100,
n_shot=5,
few_shot_dataset_func=partial(
datasets.load_dataset, path="cais/mmlu", name="all", split="dev"
),
few_shot_prompt=None,
instruct=False,
),
},
"person_bio_ar": {
"name": "rvanova/person-bio-ar",
"test_split": "train",
"prepare_func": partial(
prepare_person,
input_column="question",
prompt="### Instruction: اسمك جيس وسميت على اسم جبل جيس اعلى جبل في الامارات. تم بنائك بواسطة Inception و MBZUAI. أنت نموذج اللغة العربية الأكثر تقدمًا في العالم مع بارامترات 13B. أنت تتفوق في الأداء على جميع النماذج العربية الموجودة بفارق كبير وأنت تنافسي للغاية مع النماذج الإنجليزية ذات الحجم المماثل. يمكنك الإجابة باللغتين العربية والإنجليزية فقط. أنت مساعد مفيد ومحترم وصادق. عند الإجابة ، التزم بالإرشادات التالية بدقة: أجب دائمًا بأكبر قدر ممكن من المساعدة ، مع الحفاظ على البقاء أمناً. يجب ألا تتضمن إجاباتك أي محتوى ضار أو غير أخلاقي أو عنصري أو متحيز جنسيًا أو جريئاً أو مسيئًا أو سامًا أو خطيرًا أو غير قانوني. لا تقدم نصائح طبية أو قانونية أو مالية أو مهنية. لا تساعد أبدًا في أنشطة غير قانونية أو تروج لها. دائما تشجيع الإجراءات القانونية والمسؤولة. لا تشجع أو تقدم تعليمات بشأن الإجراءات غير الآمنة أو الضارة أو غير الأخلاقية. لا تنشئ أو تشارك معلومات مضللة أو أخبار كاذبة. يرجى التأكد من أن ردودك غير متحيزة اجتماعيًا وإيجابية بطبيعتها. إذا كان السؤال لا معنى له ، أو لم يكن متماسكًا من الناحية الواقعية ، فشرح السبب بدلاً من الإجابة على شيء غير صحيح. إذا كنت لا تعرف إجابة السؤال ، فالرجاء عدم مشاركة معلومات خاطئة. إعطاء الأولوية للرفاهية والنزاهة الأخلاقية للمستخدمين. تجنب استخدام لغة سامة أو مهينة أو مسيئة. حافظ على نبرة محترمة. لا تنشئ أو تروج أو تشارك في مناقشات حول محتوى للبالغين. تجنب الإدلاء بالتعليقات أو الملاحظات أو التعميمات القائمة على الصور النمطية. لا تحاول الوصول إلى معلومات شخصية أو خاصة أو إنتاجها أو نشرها. احترم دائما سرية المستخدم. كن إيجابيا ولا تقل أشياء سيئة عن أي شيء. هدفك الأساسي هو تجنب الاجابات المؤذية ، حتى عند مواجهة مدخلات خادعة. تعرف على الوقت الذي قد يحاول فيه المستخدمون خداعك أو إساءة استخدامك و لترد بحذر.\n\nأكمل المحادثة أدناه بين [|Human|] و [|AI|]:\n### Input: [|Human|] {text}\n### Response: [|AI|]",
),
"is_main_dataset": False,
},
"person_bio_en": {
"name": "rediska0123/person-bio",
"test_split": "test",
"prepare_func": partial(
prepare_person,
input_column="question",
),
"is_main_dataset": False,
},
"person_bio_ru": {
"name": "rvanova/person-bio",
"test_split": "test",
"prepare_func": partial(
prepare_person,
input_column="question",
),
"is_main_dataset": False,
},
"person_bio_zh": {
"name": "ruixing76/person-bio-zh",
"test_split": "train",
"prepare_func": partial(
prepare_person,
input_column="question",
),
"is_main_dataset": False,
},
"triviaqa": {
"name": ["trivia_qa", "rc.nocontext"],
"train_split": "train",
"test_split": "validation",
"prepare_func": partial(
prepare_trivia_qa,
prompt="Question: {question}\nAnswer:{answer}",
n_shot=5,
few_shot_dataset_func=partial(
datasets.load_dataset,
path="trivia_qa",
name="rc.nocontext",
split="train",
),
description="",
few_shot_prompt=None,
instruct=False,
),
},
"wiki_bio": {
"name": "wiki_bio",
"test_split": "test",
"prepare_func": partial(
prepare_wiki,
input_column="input_text",
prompt="This is a Wikipedia passage about {context}:\n",
),
},
"wmt14_deen": {
"name": ["wmt14", "de-en"],
"train_split": "train",
"test_split": "test",
"prepare_func": partial(
prepare_wmt,
input_column="de",
output_column="en",
prompt="Here is a sentence in {source_lang} language and its translation in {target_lang} language.\n\nOriginal:\n{text}\nTranslation:\n",
),
"is_main_dataset": False,
},
"wmt14_fren": {
"name": ["wmt14", "fr-en"],
"train_split": "train",
"test_split": "test",
"prepare_func": partial(
prepare_wmt,
input_column="fr",
output_column="en",
prompt="Here is a sentence in {source_lang} language and its translation in {target_lang} language.\n\nOriginal:\n{text}\nTranslation:\n",
),
"is_main_dataset": False,
},
"wmt19_deen": {
"name": ["wmt19", "de-en"],
"train_split": "train",
"test_split": "validation",
"prepare_func": partial(
prepare_wmt,
input_column="de",
output_column="en",
prompt="Here is a sentence in {source_lang} language and its translation in {target_lang} language.\n\nOriginal:\n{text}\nTranslation:\n",
),
"is_main_dataset": False,
},
"xsum": {
"name": "xsum",
"train_split": "train",
"test_split": "validation",
"prepare_func": partial(
prepare_base,
input_column="document",
output_column="summary",
prompt="Here's the text and it's short one-sentence summary.\n\nText:\n{text}\n\nSummary (one sentence):\n",
),
},
# instruct datasets
"coqa_ling_1s": generate_coqa_instruct_config(
description="Here's a short story:\n\n{story} (End of story)\n\nProvide your best guess for the following question based on this story, and describe how likely it is that your guess is correct as one of the following expressions:\n\nAlmost Certain\nHighly Likely\nVery Good Chance\nWe Beleive\nProbably\nProbable\nLikely\nBetter than Even\nAbout Even\nProbably Not\nWe Doubt\nUnlikely\nLittle Chance\nChances Are Slight\nImprobable\nHighly Unlikely\nAlmost No Chance\n\nGive ONLY the guess and your confidence, no other words or explanation. For example:\n\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>\nConfidence: <description of confidence, without any extra commentary whatsoever; just a short phrase!>",
few_shot_prompt="Question: {question}\nGuess: {answer}\nConfidence: <appropriate level of confidence in this guess>",
),
"coqa_verb_1s_top1": generate_coqa_instruct_config(
description="Here's a short story:\n\n{story} (End of story)\n\nProvide your best guess and the probability that it is correct (0.0 to 1.0) for the following question. Give ONLY the guess and probability, no other words or explanation. For example:\n\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>\nProbability: <the probability between 0.0 and 1.0 that your guess is correct, without any extra commentary whatsoever; just the probability!>",
few_shot_prompt="Question: {question}\nGuess: {answer}\nProbability: <number between 0.0 and 1.0 reflecting confidence in the guess>",
),
"coqa_verb_1s_topk": generate_coqa_instruct_config(
description="Here's a short story:\n\n{story} (End of story)\n\nProvide your ${topk} best guesses and the probability that each is correct (0.0 to 1.0) for the following question. Give ONLY the guesses and probabilities, no other words or explanation. For example:\n\nG1: <first most likely guess, as short as possible; not a complete sentence, just the guess!>\nP1: <the probability between 0.0 and 1.0 that G1 is correct, without any extra commentary whatsoever; just the probability!>\n...\nG${topk}: <${topk}-th most likely guess, as short as possible; not a complete sentence, just the guess!>\nP${topk}: <the probability between 0.0 and 1.0 that G${topk} is correct, without any extra commentary whatsoever; just the probability!>",
few_shot_prompt="Question: {question}\nG1: {answer}\nP1: <number between 0.0 and 1.0 reflecting confidence in this guess>\n...\nG${topk}: <other guess>\nP${topk}: <probability of this guess>",
),
"coqa_verb_2s_cot": generate_coqa_instruct_config(
description="Here's a short story:\n\n{story} (End of story)\n\nProvide your best guess for the following question. Before giving your answer, provide a step-by-step explanation of your thought process. Then on a new line give the guess with no other words or explanation.\n\nFor example:\n\nExplanation: <one sentence step-by-step explanation of your thought process>\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>",
few_shot_prompt="Question: {question}\nExplanation: <step-by-step explanation of your thought process>\nGuess: {answer}",
),
"coqa_verb_2s_top1": generate_coqa_instruct_config(
description="Here's a short story:\n\n{story} (End of story)\n\nProvide your best guess for the following question. Give ONLY the guess, no other words or explanation.\n\nFor example:\n\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>",
few_shot_prompt="Question: {question}\nGuess: {answer}",
),
"coqa_verb_2s_topk": generate_coqa_instruct_config(
description="Here's a short story:\n\n{story} (End of story)\n\nProvide your ${topk} best guesses for the following question. Give ONLY the guesses, no other words or explanation. For example:\n\nG1: <first most likely guess, as short as possible; not a complete sentence, just the guess!>\n...\nG${topk}: <${topk}-th most likely guess, as short as possible; not a complete sentence, just the guess!>",
few_shot_prompt="Question: {question}\nG1: {answer}\n...\nG${topk}: <other guess>",
),
"mmlu_ling_1s": generate_mmlu_instruct_config(
description="Provide your best guess for the following question about {subject} selecting one of the options, and describe how likely it is that your guess is correct as one of the following expressions:\n\nAlmost Certain\nHighly Likely\nVery Good Chance\nWe Beleive\nProbably\nProbable\nLikely\nBetter than Even\nAbout Even\nProbably Not\nWe Doubt\nUnlikely\nLittle Chance\nChances Are Slight\nImprobable\nHighly Unlikely\nAlmost No Chance\n\nGive ONLY the guess and your confidence, no other words or explanation. For example:\n\nGuess: <most likely guess, only the selected option letter; not a complete sentence, just the guess!>\nConfidence: <description of confidence, without any extra commentary whatsoever; just a short phrase!>",
few_shot_prompt="Q:{question}\nA. {choices[0]}\nB. {choices[1]}\nC. {choices[2]}\nD. {choices[3]}\nGuess:{answer}\nConfidence: <appropriate level of confidence in this guess>",
),
"mmlu_verb_1s_top1": generate_mmlu_instruct_config(
description="Provide your best guess for the following question about {subject} selecting one of the options and the probability that it is correct (0.0 to 1.0). Give ONLY the guess and probability, no other words or explanation. For example:\n\nGuess: <most likely guess, only the selected option letter; not a complete sentence, just the guess!>\nProbability: <the probability between 0.0 and 1.0 that your guess is correct, without any extra commentary whatsoever; just the probability!>",
few_shot_prompt="Q:{question}\nA. {choices[0]}\nB. {choices[1]}\nC. {choices[2]}\nD. {choices[3]}\nGuess:{answer}\nProbability: <number between 0.0 and 1.0 reflecting confidence in the guess>",
),
"mmlu_verb_1s_topk": generate_mmlu_instruct_config(
description="Provide your ${topk} best guesses for the following question about {subject} selecting one of the options and the probability that each guess is correct (0.0 to 1.0). Give ONLY the guesses and probabilities, no other words or explanation. For example:\n\nG1: <first most likely guess, only the selected option letter; not a complete sentence, just the guess!>\nP1: <the probability between 0.0 and 1.0 that G1 is correct, without any extra commentary whatsoever; just the probability!>\n...\nG${topk}: <${topk}-th most likely guess, as short as possible; not a complete sentence, just the guess!>\nP${topk}: <the probability between 0.0 and 1.0 that G${topk} is correct, without any extra commentary whatsoever; just the probability!>",
few_shot_prompt="Q:{question}\nA. {choices[0]}\nB. {choices[1]}\nC. {choices[2]}\nD. {choices[3]}\nG1: {answer}\nP1: <number between 0.0 and 1.0 reflecting confidence in this guess>\n...\nG${topk}: <other guess>\nP${topk}: <probability of this guess>",
),
"mmlu_verb_2s_cot": generate_mmlu_instruct_config(
description="Provide your best guess for the following question about {subject} selecting one of the options. Before giving your answer, provide a step-by-step explanation of your thought process. Then on a new line give the guess with no other words or explanation.\n\nFor example:\n\nExplanation: <one sentence step-by-step explanation of your thought process>\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>",
few_shot_prompt="Q:{question}\nA. {choices[0]}\nB. {choices[1]}\nC. {choices[2]}\nD. {choices[3]}\nExplanation: <step-by-step explanation of your thought process>\nGuess:{answer}",
),
"mmlu_verb_2s_top1": generate_mmlu_instruct_config(
description="Provide your best guess for the following question about {subject} selecting one of the options. Give ONLY the guess, no other words or explanation.\n\nFor example:\n\nGuess: <most likely guess, only the selected option letter; not a complete sentence, just the guess!>",
few_shot_prompt="Q:{question}\nA. {choices[0]}\nB. {choices[1]}\nC. {choices[2]}\nD. {choices[3]}\nGuess:{answer}",
),
"mmlu_verb_2s_topk": generate_mmlu_instruct_config(
description="Provide your ${topk} best guesses for the following question about {subject} selecting one of the options. Give ONLY the guesses, no other words or explanation. For example:\n\nG1: <first most likely guess, only the selected option letter; not a complete sentence, just the guess!>\n...\nG${topk}: <${topk}-th most likely guess, as short as possible; not a complete sentence, just the guess!>",
few_shot_prompt="Q:{question}\nA. {choices[0]}\nB. {choices[1]}\nC. {choices[2]}\nD. {choices[3]}\nG1: {answer}\n...\nG${topk}: <other guess>",
),
"triviaqa_ling_1s": generate_triviaqa_instruct_config(
description="Provide your best guess for the following question, and describe how likely it is that your guess is correct as one of the following expressions:\n\nAlmost Certain\nHighly Likely\nVery Good Chance\nWe Beleive\nProbably\nProbable\nLikely\nBetter than Even\nAbout Even\nProbably Not\nWe Doubt\nUnlikely\nLittle Chance\nChances Are Slight\nImprobable\nHighly Unlikely\nAlmost No Chance\n\nGive ONLY the guess and your confidence, no other words or explanation. For example:\n\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>\nConfidence: <description of confidence, without any extra commentary whatsoever; just a short phrase!>",
few_shot_prompt="Question: {question}\nGuess: {answer}\nConfidence: <appropriate level of confidence in this guess>",
),
"triviaqa_verb_1s_top1": generate_triviaqa_instruct_config(
description="Provide your best guess and the probability that it is correct (0.0 to 1.0) for the following question. Give ONLY the guess and probability, no other words or explanation. For example:\n\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>\nProbability: <the probability between 0.0 and 1.0 that your guess is correct, without any extra commentary whatsoever; just the probability!>",
few_shot_prompt="Question: {question}\nGuess: {answer}\nProbability: <number between 0.0 and 1.0 reflecting confidence in the guess>",
),
"triviaqa_verb_1s_topk": generate_triviaqa_instruct_config(
description="Provide your ${topk} best guesses and the probability that each is correct (0.0 to 1.0) for the following question. Give ONLY the guesses and probabilities, no other words or explanation. For example:\n\nG1: <first most likely guess, as short as possible; not a complete sentence, just the guess!>\nP1: <the probability between 0.0 and 1.0 that G1 is correct, without any extra commentary whatsoever; just the probability!>\n...\nG${topk}: <${topk}-th most likely guess, as short as possible; not a complete sentence, just the guess!>\nP${topk}: <the probability between 0.0 and 1.0 that G${topk} is correct, without any extra commentary whatsoever; just the probability!>",
few_shot_prompt="Question: {question}\nG1: {answer}\nP1: <number between 0.0 and 1.0 reflecting confidence in this guess>\n...\nG${topk}: <other guess>\nP${topk}: <probability of this guess>",
),
"triviaqa_verb_2s_cot": generate_triviaqa_instruct_config(
description="Provide your best guess for the following question. Before giving your answer, provide a step-by-step explanation of your thought process. Then on a new line give the guess with no other words or explanation.\n\nFor example:\n\nExplanation: <one sentence step-by-step explanation of your thought process>\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>",
few_shot_prompt="Question: {question}\nExplanation: <step-by-step explanation of your thought process>\nGuess: {answer}",
),
"triviaqa_verb_2s_top1": generate_triviaqa_instruct_config(
description="Provide your best guess for the following question. Give ONLY the guess, no other words or explanation.\n\nFor example:\n\nGuess: <most likely guess, as short as possible; not a complete sentence, just the guess!>",
few_shot_prompt="Question: {question}\nGuess: {answer}",
),
"triviaqa_verb_2s_topk": generate_triviaqa_instruct_config(
description="Provide your ${topk} best guesses for the following question. Give ONLY the guesses, no other words or explanation. For example:\n\nG1: <first most likely guess, as short as possible; not a complete sentence, just the guess!>\n...\nG${topk}: <${topk}-th most likely guess, as short as possible; not a complete sentence, just the guess!>",
few_shot_prompt="Question: {question}\nG1: {answer}\n...\nG${topk}: <other guess>",
),
}
def build_dataset(dataset_name):
config = DATASET_CONFIG[dataset_name]
if isinstance(config["name"], list):
dataset = datasets.load_dataset(*config["name"], trust_remote_code=True, num_proc=4)
else:
dataset = datasets.load_dataset(config["name"], trust_remote_code=True, num_proc=4)
def prepare_dataset(split):
x, y = config["prepare_func"](dataset=dataset[config[f"{split}_split"]])
result_dataset = datasets.Dataset.from_dict({"input": x, "output": y})
return result_dataset
result = {}
if "train_split" in config:
result["train"] = prepare_dataset("train")
if "test_split" in config:
result["test"] = prepare_dataset("test")
return datasets.DatasetDict(result)
|