Upload events_classification_biotech.py
Browse files
events_classification_biotech.py
CHANGED
|
@@ -57,6 +57,7 @@ class BiotechNews(datasets.GeneratorBasedBuilder):
|
|
| 57 |
"content": datasets.Value("string"),
|
| 58 |
"target organization": datasets.Value("string"),
|
| 59 |
"all_labels": datasets.Value("string"),
|
|
|
|
| 60 |
"label 1": datasets.features.ClassLabel(names=labels),
|
| 61 |
"label 2": datasets.features.ClassLabel(names=labels),
|
| 62 |
"label 3": datasets.features.ClassLabel(names=labels),
|
|
@@ -77,18 +78,21 @@ class BiotechNews(datasets.GeneratorBasedBuilder):
|
|
| 77 |
|
| 78 |
def get_all_labels(self, curr_labels):
|
| 79 |
curr_labels = [lbl for lbl in curr_labels if lbl]
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
def _generate_examples(self, filepath):
|
| 84 |
-
csv_reader = load_dataset('csv',data_files=filepath, split='train')
|
| 85 |
for example in csv_reader:
|
| 86 |
id_, title, content, organization, label1, label2, label3, label4, label5 = example.values()
|
| 87 |
|
| 88 |
curr_labels = (label1, label2, label3, label4, label5)
|
| 89 |
-
|
| 90 |
|
| 91 |
yield id_, {"title": title, "content": content, "target organization": organization,
|
| 92 |
-
"all_labels":
|
|
|
|
| 93 |
"label 1": label1, "label 2": label2, "label 3": label3, "label 4": label4,
|
| 94 |
"label 5": label5}
|
|
|
|
| 57 |
"content": datasets.Value("string"),
|
| 58 |
"target organization": datasets.Value("string"),
|
| 59 |
"all_labels": datasets.Value("string"),
|
| 60 |
+
"all_labels_concat": datasets.Value("string"),
|
| 61 |
"label 1": datasets.features.ClassLabel(names=labels),
|
| 62 |
"label 2": datasets.features.ClassLabel(names=labels),
|
| 63 |
"label 3": datasets.features.ClassLabel(names=labels),
|
|
|
|
| 78 |
|
| 79 |
def get_all_labels(self, curr_labels):
|
| 80 |
curr_labels = [lbl for lbl in curr_labels if lbl]
|
| 81 |
+
if not len(curr_labels):
|
| 82 |
+
curr_labels = ['other']
|
| 83 |
+
curr_labels_cat = ', '.join(curr_labels)
|
| 84 |
+
return curr_labels, curr_labels_cat
|
| 85 |
|
| 86 |
def _generate_examples(self, filepath):
|
| 87 |
+
csv_reader = load_dataset('csv', data_files=filepath, split='train')
|
| 88 |
for example in csv_reader:
|
| 89 |
id_, title, content, organization, label1, label2, label3, label4, label5 = example.values()
|
| 90 |
|
| 91 |
curr_labels = (label1, label2, label3, label4, label5)
|
| 92 |
+
curr_labels, curr_labels_cat = self.get_all_labels(curr_labels)
|
| 93 |
|
| 94 |
yield id_, {"title": title, "content": content, "target organization": organization,
|
| 95 |
+
"all_labels": curr_labels,
|
| 96 |
+
"all_labels_concat": curr_labels_cat,
|
| 97 |
"label 1": label1, "label 2": label2, "label 3": label3, "label 4": label4,
|
| 98 |
"label 5": label5}
|