format the subject example from a df into prompt, which conclude question, choices and correct choices
(df: pd.DataFrame,
idx: int,
include_answer: bool = True)
| 302 | |
| 303 | |
| 304 | def format_example(df: pd.DataFrame, |
| 305 | idx: int, |
| 306 | include_answer: bool = True) -> str: |
| 307 | ''' |
| 308 | format the subject example from a df into prompt, which conclude question, choices and correct choices |
| 309 | ''' |
| 310 | choices = ["A", "B", "C", "D"] |
| 311 | prompt = f"[Example {idx + 1}]\nquestion:\n```\n{df.iloc[idx, 0]}\n```\n" |
| 312 | options = "options:\n```" |
| 313 | k = df.shape[1] - 2 |
| 314 | for j in range(k): |
| 315 | if j == k - 1: |
| 316 | options += f"\n{choices[j]}. {df.iloc[idx, j + 1]}\n```\n" |
| 317 | else: |
| 318 | options += f"\n{choices[j]}. {df.iloc[idx, j + 1]}" |
| 319 | answer = "answer:" |
| 320 | if include_answer: |
| 321 | answer += f" {df.iloc[idx, k + 1]}\n\n" |
| 322 | prompt += options |
| 323 | prompt += answer |
| 324 | return prompt |
| 325 | |
| 326 | |
| 327 | def gen_prompt(train_df: pd.DataFrame, |