[d129b2]: / medicalbert / datareader / FeatureSetBuilder.py

Download this file

36 lines (27 with data), 1.1 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
# This class allows us to create a set of input features
# where each new input feature is added as another dimension
# For example
# We could add a value for the first element related to age
# and in the second element its health condition
# But for now, this allows us to break long pieces of text
# into shorter chunks
class FeatureSetBuilder:
def __init__(self, label):
self.features = []
self.label = label
def add(self, input_feature):
self.features.append(input_feature)
def resize(self, num_sections, func):
# if the num sections isn't maxed we either need to pad out or cut down.
while len(self.features) < num_sections:
self.features.append(func)
# Handle the case where we have too many sections - cut at the head
if len(self.features) > num_sections:
self.features = self.features[-num_sections:]
#returns all features
def get(self):
return self.features
def get_feature(self, feature_index):
return self.features[feature_index]
def get_label(self):
return self.label