yanyc commited on
Commit
e3304a2
·
1 Parent(s): cd9ae06

Update SciGraph.py

Browse files
Files changed (1) hide show
  1. SciGraph.py +8 -8
SciGraph.py CHANGED
@@ -120,21 +120,21 @@ class SciGraph(datasets.GeneratorBasedBuilder):
120
  with open(classes, 'r') as f:
121
  functions = list(json.load(f).keys())
122
  data = pd.read_json(function)
123
-
 
 
 
 
 
124
  if split == 'train':
125
- data = data.loc[data[functions].sum(axis=1) == 1]
126
- data['label'] = [functions[row.tolist().index(1)] for index, row in data[functions].iterrows()]
127
- data = data[['_id', 'abstract', 'label']]
128
- for idx, row in data.iterrows():
129
  yield idx, {
130
  "id": row._id,
131
  "abstract": row.abstract,
132
  "label": row.label
133
  }
134
  elif split == 'test':
135
- data = data.loc[data[functions].sum(axis=1) == 0]
136
- data = data[['_id', 'abstract']]
137
- for idx, row in data.iterrows():
138
  yield idx, {
139
  "id": row._id,
140
  "abstract": row.abstract,
 
120
  with open(classes, 'r') as f:
121
  functions = list(json.load(f).keys())
122
  data = pd.read_json(function)
123
+ data = data.loc[data[functions].sum(axis=1) == 1]
124
+ data['label'] = [functions[row.tolist().index(1)] for index, row in data[functions].iterrows()]
125
+ data = data[['_id', 'abstract', 'label']]
126
+
127
+
128
+ train_data, test_data = train_test_split(data, test_size=0.1, random_state=42)
129
  if split == 'train':
130
+ for idx, row in train_data.iterrows():
 
 
 
131
  yield idx, {
132
  "id": row._id,
133
  "abstract": row.abstract,
134
  "label": row.label
135
  }
136
  elif split == 'test':
137
+ for idx, row in test_data.iterrows():
 
 
138
  yield idx, {
139
  "id": row._id,
140
  "abstract": row.abstract,