def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): guid = "%s-%s" % (set_type, i) text_a = line['text'] text_a_list = list(text_a) target = line['target'] query = target['span1_text'] query_idx = target['span1_index'] pronoun = target['span2_text'] pronoun_idx = target['span2_index'] assert text_a[pronoun_idx:( pronoun_idx + len(pronoun))] == pronoun, "pronoun: {}".format(pronoun) assert text_a[query_idx:( query_idx + len(query))] == query, "query: {}".format(query) if pronoun_idx > query_idx: text_a_list.insert(query_idx, "_") text_a_list.insert(query_idx + len(query) + 1, "_") text_a_list.insert(pronoun_idx + 2, "[") text_a_list.insert(pronoun_idx + len(pronoun) + 2 + 1, "]") else: text_a_list.insert(pronoun_idx, "[") text_a_list.insert(pronoun_idx + len(pronoun) + 1, "]") text_a_list.insert(query_idx + 2, "_") text_a_list.insert(query_idx + len(query) + 2 + 1, "_") text_a = "".join(text_a_list) text_b = None label = str(line['label']) if set_type != 'test' else None examples.append( InputExample(guid=guid, texts=[text_a, text_b], label=label)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): guid = "%s-%s" % (set_type, i) text_a = line[3] if set_type != 'test' else line[1] label = line[1] if set_type != 'test' else None examples.append( InputExample(guid=guid, texts=[text_a, None], label=label)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, row) in enumerate(lines.values): guid = row[0] text_a = row[1] label_ids = row[2:] if set_type != 'test' else None examples.append( InputExample(guid=guid, texts=[text_a, None], label_ids=label_ids)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): guid = "%s-%s" % (set_type, i) text_a = line['sentence1'] text_b = line['sentence2'] label = str(line['label']) if set_type != 'test' else None examples.append( InputExample(guid=guid, texts=[[text_a, None], [text_b, None]], label=label)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): guid = "%s-%s" % (set_type, i) title = line['title'] attribute = line['attr'] labels = line['labels'] # 标签序列使用label_ids examples.append(InputExample(guid=guid, texts=[[title, None], [attribute, None]], label_ids=labels)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): guid = "%s-%s" % (set_type, i) text_a = line['text'] labels = line['labels'] examples.append( InputExample(guid=guid, texts=[text_a, None], label_ids=labels)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): guid = "%s-%s" % (set_type, i) text_a = line['anchor'] text_b = line["positives"] text_c = line["negatives"] label = 1 examples.append( InputExample(guid=guid, texts=[[text_a, None], [text_b, None], [text_c, None]], label=label)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): if i == 0: continue guid = "%s-%s" % (set_type, i) text_a = line[0] label = line[1] examples.append( InputExample(guid=guid, texts=[text_a, None], label=label)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): guid = "%s-%s" % (set_type, i) text_a = line['words'] labels = [] for x in line['labels']: if 'M-' in x: labels.append(x.replace('M-', 'I-')) elif 'E-' in x: labels.append(x.replace('E-', 'I-')) else: labels.append(x) # 标签序列使用label_ids spans = get_spans(labels, id2label=None, markup=self.markup) examples.append(InputExample(guid=guid, texts=[text_a, None], label_ids=spans)) return examples
def create_examples(self, lines, set_type): """Creates examples for the training and dev sets.""" examples = [] for (i, line) in enumerate(lines): if i == 0: continue guid = "%s-%s" % (set_type, i) text_a = line['words'] labels = [] for x in line['labels']: if 'M-' in x: labels.append(x.replace('M-', 'I-')) elif 'E-' in x: labels.append(x.replace('E-', 'I-')) else: labels.append(x) # 标签序列使用label_ids examples.append(InputExample(guid=guid, texts=[text_a, None], label_ids=labels)) return examples