criminal-classification-cha.../herbert/01_create_datasets.py
2021-07-11 22:37:19 +02:00

17 lines
645 B
Python

with open('../test-A/in.tsv','r') as f_in, open(f'../test-A/huggingface_format.tsv', 'w') as f_hf:
f_hf.write('text\n')
for line_in in f_in:
text = line_in.replace('\t', ' ')
f_hf.write(text)
for dataset in 'train', 'dev-0':
with open(f'../{dataset}/in.tsv') as f_in, open(f'../{dataset}/expected.tsv') as f_exp, open(f'../{dataset}/huggingface_format.tsv','w') as f_hf:
f_hf.write('text\tlabel\n')
for line_in, line_exp in zip(f_in, f_exp):
label = line_exp.rstrip('\n')
text = line_in.replace('\t', ' ').rstrip('\n')
f_hf.write(text +'\t'+ str(label) + '\n')