def to_example(self, row): assert len(row) == len(self.headers), "could not convert row to example %s\n%s" % (row, self.headers) d = dict(zip(self.headers, row)) ex = Example(**d) ex.relation = ex.annotated_relations.strip() for k in ['pos']: ex[k] = ex[k].replace('`', "'") if ex.relation in self.relation_map: ex.relation = self.relation_map[ex.relation] for k in ['dependency', 'dep_extra', 'dep_malt']: ex[k] = ex[k].replace("\\n", "\n").replace("\\t", "\t") return self.convert_types(ex)
def to_example(self, row): assert len(row) == len( self.headers), "could not convert row to example %s\n%s" % ( row, self.headers) d = dict(zip(self.headers, row)) ex = Example(**d) ex.relation = ex.annotated_relations.strip() for k in ['pos']: ex[k] = ex[k].replace('`', "'") if ex.relation in self.relation_map: ex.relation = self.relation_map[ex.relation] for k in ['dependency', 'dep_extra', 'dep_malt']: ex[k] = ex[k].replace("\\n", "\n").replace("\\t", "\t") return self.convert_types(ex)
def corrupt(self, feat, add=False): corrupted = Example(**deepcopy(feat.__dict__)) corrupted.corrupt = True # randomly drop a node drop = np.random.randint(0, len(corrupted.sequence)) sequence = corrupted.sequence[:drop] if drop < len(corrupted.sequence) - 1: sequence += corrupted.sequence[drop+1:] corrupted.sequence = sequence corrupted.relation = self.vocab['rel'].add('no_relation') corrupted.length = len(corrupted.sequence) return corrupted if corrupted.length else None