| 42 | |
| 43 | |
| 44 | def predict_data(setting, lang, checkpoint, device, batch_size): |
| 45 | if '-pair' in checkpoint: |
| 46 | def func(batch): |
| 47 | paired = [dict(text=q, text_pair=a) for q, a in zip(batch['question'], batch['answer'])] |
| 48 | out = detector(paired , max_length=512, truncation=True) |
| 49 | batch['pred'] = [int(o['label'][-1]) for o in out] |
| 50 | return batch |
| 51 | else: |
| 52 | def func(batch): |
| 53 | out = detector(batch['answer'], max_length=512, truncation=True) |
| 54 | batch['pred'] = [int(o['label'][-1]) for o in out] |
| 55 | # batch['prob'] = [o['score'] for o in out] |
| 56 | return batch |
| 57 | |
| 58 | path = f"hc3/{setting}/{lang}_test.csv" # path to the csv data from the google drive |
| 59 | print('\n\n', path) |
| 60 | test_df = pd.read_csv(path) |
| 61 | dataset = Dataset.from_pandas(test_df) |
| 62 | print(dataset) |
| 63 | detector = pipeline('text-classification', model=checkpoint, device=device, framework='pt') |
| 64 | dataset = dataset.map(func, batched=True, batch_size=batch_size, desc='test') |
| 65 | return dataset |
| 66 | |
| 67 | |
| 68 | def evaluate_func(setting, lang, checkpoint, device, batch_size, sources): |