vosadcii commited on
Commit
9905cd0
1 Parent(s): dbe3f45

split data

Browse files
Files changed (4) hide show
  1. data/test.json +0 -0
  2. data/train.json +0 -0
  3. data_preparation.py +43 -0
  4. policies.py +6 -2
data/test.json ADDED
The diff for this file is too large to render. See raw diff
 
data/train.json ADDED
The diff for this file is too large to render. See raw diff
 
data_preparation.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from sklearn.model_selection import train_test_split
3
+
4
+
5
+ def split_data(file_name: str, data_type: str):
6
+ if data_type == "json":
7
+ with open(file_name, 'r') as json_file:
8
+ data = json.load(json_file)["data"]
9
+ json_file.close()
10
+
11
+ train, test = train_test_split(data, train_size=0.9, random_state=42)
12
+ return(train, test)
13
+
14
+
15
+ def save_json(data: dict, file_name: str):
16
+ """
17
+ Method to save the json file.
18
+ Parameters:
19
+ ----------
20
+ data: dict,
21
+ data to be saved in file.
22
+ file_name: str,
23
+ name of the file.
24
+ Returns:
25
+ --------
26
+ None
27
+ """
28
+
29
+ # save the split
30
+ with open(file_name, "w") as data_file:
31
+ json.dump(data, data_file, indent=2)
32
+ data_file.close()
33
+
34
+
35
+ if __name__ == "__main__":
36
+ # split the train data
37
+ train, test = split_data("policies-qa-training.json", "json")
38
+
39
+ # save the train split
40
+ save_json(train, "train.json")
41
+
42
+ # save the test split
43
+ save_json(test, "test.json")
policies.py CHANGED
@@ -6,13 +6,16 @@ from datasets.tasks import QuestionAnsweringExtractive
6
 
7
  logger = datasets.logging.get_logger(__name__)
8
 
 
 
9
  _DESCRIPTION = """\
10
  Manually generated dataset for policies qa
11
  """
12
 
13
  _URLS = {
14
- "train": "./policies-qa-training.json"
15
- }
 
16
 
17
 
18
  class PoliciesQAConfig(datasets.BuilderConfig):
@@ -63,6 +66,7 @@ class PoliciesQA(datasets.GeneratorBasedBuilder):
63
  question_column="question", context_column="context", answers_column="answers"
64
  )
65
  ],
 
66
  )
67
 
68
  def _split_generators(self, dl_manager):
 
6
 
7
  logger = datasets.logging.get_logger(__name__)
8
 
9
+ _CITATION = """"""
10
+
11
  _DESCRIPTION = """\
12
  Manually generated dataset for policies qa
13
  """
14
 
15
  _URLS = {
16
+ "train": "./data/train.json",
17
+ "test": "./data/test.json"
18
+ }
19
 
20
 
21
  class PoliciesQAConfig(datasets.BuilderConfig):
 
66
  question_column="question", context_column="context", answers_column="answers"
67
  )
68
  ],
69
+ citation=_CITATION,
70
  )
71
 
72
  def _split_generators(self, dl_manager):