|
import json |
|
import pandas as pd |
|
from sklearn.model_selection import train_test_split |
|
|
|
|
|
path_to_teca1 = 'dataset_te1.json' |
|
path_to_teca2 = 'dataset_te_vilaweb.json' |
|
|
|
|
|
teca1 = pd.read_json(path_to_teca1) |
|
teca2 = pd.read_json(path_to_teca2) |
|
teca = pd.concat([teca1, teca2]) |
|
|
|
|
|
teca.drop(['id'], axis=1, inplace=True) |
|
|
|
|
|
teca = teca.sample(frac=1).reset_index(drop=True) |
|
|
|
|
|
train, dev_test = train_test_split(teca, test_size=0.2, random_state=42, stratify=teca['label']) |
|
dev, test = train_test_split(dev_test, test_size=0.5, random_state=42, stratify=dev_test['label']) |
|
|
|
|
|
print('### VALUE COUNTS TECA ###') |
|
print(teca['label'].value_counts()) |
|
print('### VALUE COUNTS TRAIN ###') |
|
print(train['label'].value_counts()) |
|
print('### VALUE COUNTS DEV ###') |
|
print(dev['label'].value_counts()) |
|
print('### VALUE COUNTS TEST ###') |
|
print(test['label'].value_counts()) |
|
print('train shape:', train.shape[0], ', dev shape:', dev.shape[0], ', test shape:', test.shape[0]) |
|
|
|
|
|
sets = {'train': train, 'dev': dev, 'test': test} |
|
for key in sets: |
|
set_dict = sets[key].to_dict('records') |
|
json_content = {"version": '1.0.1', "data": set_dict} |
|
with open(key+'.json', 'w') as f: |
|
json.dump(json_content, f) |