Ihor commited on
Commit
28ace77
1 Parent(s): 3894895

Upload events_classification_biotech.py

Browse files
Files changed (1) hide show
  1. events_classification_biotech.py +4 -14
events_classification_biotech.py CHANGED
@@ -1,5 +1,5 @@
1
- import pandas as pd
2
  import datasets
 
3
  from datasets.tasks import TextClassification
4
 
5
  DESCRIPTION = """
@@ -75,25 +75,15 @@ class BiotechNews(datasets.GeneratorBasedBuilder):
75
  datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
76
  ]
77
 
78
- def convert_to_none(self, label):
79
- if type(label) == float:
80
- label = None
81
- return label
82
-
83
  def get_all_labels(self, curr_labels):
84
  curr_labels = [lbl for lbl in curr_labels if lbl]
85
  all_curr_labels = ', '.join(curr_labels)
86
  return all_curr_labels
87
 
88
  def _generate_examples(self, filepath):
89
- csv_reader = pd.read_csv(filepath)
90
- for id_, row in csv_reader.iterrows():
91
- i, title, content, organization, label1, label2, label3, label4, label5 = row
92
- label1 = self.convert_to_none(label1)
93
- label2 = self.convert_to_none(label2)
94
- label3 = self.convert_to_none(label3)
95
- label4 = self.convert_to_none(label4)
96
- label5 = self.convert_to_none(label5)
97
 
98
  curr_labels = (label1, label2, label3, label4, label5)
99
  all_curr_labels = self.get_all_labels(curr_labels)
 
 
1
  import datasets
2
+ from datasets import load_dataset
3
  from datasets.tasks import TextClassification
4
 
5
  DESCRIPTION = """
 
75
  datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}),
76
  ]
77
 
 
 
 
 
 
78
  def get_all_labels(self, curr_labels):
79
  curr_labels = [lbl for lbl in curr_labels if lbl]
80
  all_curr_labels = ', '.join(curr_labels)
81
  return all_curr_labels
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
  all_curr_labels = self.get_all_labels(curr_labels)