Datasets:
GEM
/

Tasks:
Other
Modalities:
Text
Languages:
English
ArXiv:
Libraries:
Datasets
License:
Abinaya Mahendiran commited on
Commit
727fcd0
1 Parent(s): 256e6b8

Updated data preparation script

Browse files
Files changed (1) hide show
  1. data_preparation.py +28 -12
data_preparation.py CHANGED
@@ -81,24 +81,42 @@ def split_data(file_name: str, data_type: str) -> (dict, dict):
81
  train, test = train_test_split(data, train_size=0.7, random_state = 42)
82
  return(train, test)
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  if __name__ == "__main__":
86
  # split the train data
87
  train, test = split_data("squad_data/train-v2.0.json", "json")
88
 
89
- # add gem id and save the files
90
  train = add_gem_id(train, "train")
91
- test = add_gem_id(test, "test")
92
-
93
  # save the train split
94
- with open("train.json", "w") as train_file:
95
- json.dump(train, train_file, indent = 2)
96
- train_file.close()
97
 
 
 
98
  # save the test split
99
- with open("test.json", "w") as test_file:
100
- json.dump(test, test_file, indent = 2)
101
- test_file.close()
102
 
103
  # load validation data
104
  with open("squad_data/dev-v2.0.json", "r") as dev_file:
@@ -107,7 +125,5 @@ if __name__ == "__main__":
107
 
108
  # add gem id and save valid.json
109
  validation = add_gem_id(validation, "validation")
110
- with open("validation.json", "w") as val_file:
111
- json.dump(validation, val_file, indent = 2)
112
- val_file.close()
113
 
 
81
  train, test = train_test_split(data, train_size=0.7, random_state = 42)
82
  return(train, test)
83
 
84
+ # Function to save json file
85
+ def save_json(data: dict, file_name: str):
86
+ """
87
+ Method to save the json file.
88
+
89
+ Parameters:
90
+ ----------
91
+ data: dict,
92
+ data to be saved in file.
93
+ file_name: str,
94
+ name of the file.
95
+
96
+ Returns:
97
+ --------
98
+ None
99
+ """
100
+
101
+ # save the split
102
+ with open(file_name, "w") as data_file:
103
+ json.dump(data, data_file, indent = 2)
104
+ data_file.close()
105
+
106
 
107
  if __name__ == "__main__":
108
  # split the train data
109
  train, test = split_data("squad_data/train-v2.0.json", "json")
110
 
111
+ # add gem id to train split
112
  train = add_gem_id(train, "train")
 
 
113
  # save the train split
114
+ save_json(train, "train.json")
 
 
115
 
116
+ # add gem id to test split
117
+ test = add_gem_id(test, "test")
118
  # save the test split
119
+ save_json(test, "test.json")
 
 
120
 
121
  # load validation data
122
  with open("squad_data/dev-v2.0.json", "r") as dev_file:
 
125
 
126
  # add gem id and save valid.json
127
  validation = add_gem_id(validation, "validation")
128
+ save_json(validation, "validation.json")
 
 
129