(path: str, name: str, with_circular: bool = True)
| 113 | |
| 114 | @staticmethod |
| 115 | def load(path: str, name: str, with_circular: bool = True): |
| 116 | data = [] |
| 117 | filename = osp.join(path, f'{name}.jsonl') |
| 118 | with open(filename, 'r', encoding='utf-8') as infile: |
| 119 | for id, line in enumerate(infile): |
| 120 | entry = json.loads(line) |
| 121 | if 'cloze' in name: |
| 122 | data.append({ |
| 123 | 'question': entry['question'].strip(), |
| 124 | 'answer': entry['answer'].strip() |
| 125 | }) |
| 126 | else: |
| 127 | if with_circular: |
| 128 | data.extend(get_circular_example(entry, id)) |
| 129 | else: |
| 130 | question = entry['question'].strip( |
| 131 | ) + '\n' + get_number(entry['options']) |
| 132 | info = { |
| 133 | 'question': question, |
| 134 | 'answer': entry['answer'].strip() |
| 135 | } |
| 136 | # For PPL evaluation |
| 137 | for i in range(4): |
| 138 | info[chr(ord('A') + |
| 139 | i)] = entry['options'][i].strip() |
| 140 | data.append(info) |
| 141 | |
| 142 | if 'cloze' not in name: |
| 143 | data = data[:(len(data) // 4 + 7) // 8 * 8] |
| 144 | dataset = Dataset.from_list(data) |
| 145 | return dataset |
| 146 | |
| 147 | |
| 148 | import collections |
nothing calls this directly
no test coverage detected