siyangliu commited on
Commit
f02ca70
1 Parent(s): 47dcb7c

Upload data_split.py

Browse files
Files changed (1) hide show
  1. data_split.py +18 -0
data_split.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import random
3
+ random.seed(42)
4
+ def split_data():
5
+ f = open("./PsyQA_full.json")
6
+ lines = json.load(f)
7
+ random.shuffle(lines)
8
+ train_data = lines[:int(len(lines)*0.8)]
9
+ valid_data = lines[int(len(lines)*0.8):int(len(lines)*0.9)]
10
+ test_data = lines[int(len(lines)*0.9):]
11
+ print(len(train_data), len(valid_data), len(test_data))
12
+ with open("train.json", "w") as f:
13
+ json.dump(train_data, f)
14
+ with open("valid.json", "w") as f:
15
+ json.dump(valid_data, f)
16
+ with open("test.json", "w") as f:
17
+ json.dump(test_data, f)
18
+ split_data()