-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.py
More file actions
76 lines (60 loc) · 2.65 KB
/
Copy pathprocessor.py
File metadata and controls
76 lines (60 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding=utf-8
"""Processors for different tasks."""
import csv
import os
import pandas as pd
import tokenization
class InputExample(object):
"""A single training/test example for simple sequence classification."""
def __init__(self, guid, text_a, text_b=None, label=None):
"""Constructs a InputExample.
Args:
guid: Unique id for the example.
text_a: string. The untokenized text of the first sequence. For single
sequence tasks, only this sequence must be specified.
text_b: (Optional) string. The untokenized text of the second sequence.
Only must be specified for sequence pair tasks.
label: (Optional) string. The label of the example. This should be
specified for train and dev examples, but not for test examples.
"""
self.guid = guid
self.text_a = text_a
self.text_b = text_b
self.label = label
class DataProcessor(object):
"""Base class for data converters for sequence classification data sets."""
class Sentihood_QA_M_Processor(DataProcessor):
"""Processor for the Sentihood data set."""
def get_train_examples(self, data_dir):
"""See base class."""
train_data = pd.read_csv(os.path.join(data_dir, "train_QA_M.tsv"),sep="\t").values
return self._create_examples(train_data, "train")
def get_dev_examples(self, data_dir):
"""See base class."""
dev_data = pd.read_csv(os.path.join(data_dir, "dev_QA_M.tsv"),sep="\t").values
return self._create_examples(dev_data, "dev")
def get_test_examples(self, data_dir):
"""See base class."""
test_data = pd.read_csv(os.path.join(data_dir, "test_QA_M.tsv"),sep="\t").values
return self._create_examples(test_data, "test")
def get_labels(self):
"""See base class."""
return ['None', 'Positive', 'Negative']
def _create_examples(self, lines, set_type):
"""Creates examples for the training and dev sets."""
examples = []
for (i, line) in enumerate(lines):
# if i>50:break
guid = "%s-%s" % (set_type, i)
text_a = tokenization.convert_to_unicode(str(line[1]))
text_b = tokenization.convert_to_unicode(str(line[2]))
label = tokenization.convert_to_unicode(str(line[3]))
if i%1000==0:
print(i)
print("guid=",guid)
print("text_a=",text_a)
print("text_b=",text_b)
print("label=",label)
examples.append(
InputExample(guid=guid, text_a=text_a, text_b=text_b, label=label))
return examples