Update SciGraph.py
Browse files- 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 |
-
|
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 |
-
|
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,
|