(example)
| 51 | |
| 52 | |
| 53 | def process_example(example): |
| 54 | # Replace "ки" with "ⶻ" so that the size of the "input" matches the size of the "label" |
| 55 | inputs = example["input"].replace("ки", "ⶻ") |
| 56 | |
| 57 | # Find the indices of the "ⶻ" characters (that should match with the indexes of the "+" or "-" in the label) |
| 58 | indexes = [m.start() for m in re.finditer("ⶻ", inputs)] |
| 59 | |
| 60 | # Sanity that all indexes are either "+" or "-" |
| 61 | assert all(example["label"][idx] in ["+", "-"] for idx in indexes) |
| 62 | |
| 63 | # Get the labels |
| 64 | labels = [example["label"][idx] == "+" for idx in indexes] |
| 65 | |
| 66 | # Split the inputs into steps (caution, the first step is missing here, it is the prompt) |
| 67 | steps = [inputs[i:j] for i, j in zip(chain([0], indexes), chain(indexes, [None]))] |
| 68 | |
| 69 | # Remove the last step (single ⶻ) |
| 70 | steps = steps[:-1] |
| 71 | |
| 72 | # Get the prompt (first part) and completions (rest) |
| 73 | prompt = steps[0] |
| 74 | completions = steps[1:] |
| 75 | |
| 76 | # Remove the heading "ⶻ" and the final whitespace from the completions |
| 77 | assert all(completion.startswith("ⶻ") for completion in completions) |
| 78 | completions = [completion[1:].strip() for completion in completions] |
| 79 | |
| 80 | # At this point, we need to retrieve the first step from the prompt. |
| 81 | # First, we handle particular cases (annotation error) where we have a first label before the end of the prompt. |
| 82 | if prompt.startswith( |
| 83 | ( |
| 84 | "Mr. Rocky", |
| 85 | "Parker", |
| 86 | "What is the smallest positive", |
| 87 | " The Myth", |
| 88 | "Let $\\mathbf{a}$", |
| 89 | "Find the arithmetic", |
| 90 | "Determine an ordered pair", |
| 91 | "Determine the ordered pair", |
| 92 | "At the Quill and Scroll stationery", |
| 93 | "Round to the nearest", |
| 94 | r"Calculate $\sqrt{10p}", |
| 95 | r"Simplify $\sqrt{28x}", |
| 96 | ) |
| 97 | ): |
| 98 | # Some spotted datasets errors where there is an annotation in the prompt: we remove it |
| 99 | labels = labels[1:] |
| 100 | |
| 101 | # Then we handle the general case: we get the first step from the prompt by looking for "Step 1:" or "step 1:" or |
| 102 | # (less common) "?". |
| 103 | elif "Step 1:" in prompt: |
| 104 | prompt, first_step = prompt.split("Step 1:") |
| 105 | first_step = "Step 1:" + first_step |
| 106 | completions = [first_step.strip()] + completions |
| 107 | elif "step 1:" in prompt: |
| 108 | prompt, first_step = prompt.split("step 1:") |
| 109 | first_step = "step 1:" + first_step |
| 110 | completions = [first_step.strip()] + completions |
nothing calls this directly
no outgoing calls
no test coverage detected