Creates examples for the training and dev sets.
(self, lines, set_type)
| 799 | return ["true", "false"] |
| 800 | |
| 801 | def _create_examples(self, lines, set_type): |
| 802 | """Creates examples for the training and dev sets.""" |
| 803 | examples = [] |
| 804 | for (i, line) in enumerate(lines): |
| 805 | guid = "%s-%s" % (set_type, i) |
| 806 | text_a = convert_to_unicode(line['text']) |
| 807 | text_a_list = list(text_a) |
| 808 | target = line['target'] |
| 809 | query = target['span1_text'] |
| 810 | query_idx = target['span1_index'] |
| 811 | pronoun = target['span2_text'] |
| 812 | pronoun_idx = target['span2_index'] |
| 813 | |
| 814 | assert text_a[pronoun_idx: (pronoun_idx + len(pronoun)) |
| 815 | ] == pronoun, "pronoun: {}".format(pronoun) |
| 816 | assert text_a[query_idx: (query_idx + len(query))] == query, "query: {}".format(query) |
| 817 | |
| 818 | if pronoun_idx > query_idx: |
| 819 | text_a_list.insert(query_idx, "_") |
| 820 | text_a_list.insert(query_idx + len(query) + 1, "_") |
| 821 | text_a_list.insert(pronoun_idx + 2, "[") |
| 822 | text_a_list.insert(pronoun_idx + len(pronoun) + 2 + 1, "]") |
| 823 | else: |
| 824 | text_a_list.insert(pronoun_idx, "[") |
| 825 | text_a_list.insert(pronoun_idx + len(pronoun) + 1, "]") |
| 826 | text_a_list.insert(query_idx + 2, "_") |
| 827 | text_a_list.insert(query_idx + len(query) + 2 + 1, "_") |
| 828 | |
| 829 | text_a = "".join(text_a_list) |
| 830 | |
| 831 | if set_type == "test": |
| 832 | label = "true" |
| 833 | else: |
| 834 | label = line['label'] |
| 835 | |
| 836 | examples.append( |
| 837 | InputExample(guid=guid, text_a=text_a, text_b=None, label=label)) |
| 838 | return examples |
| 839 | |
| 840 | |
| 841 | class COPAProcessor(DataProcessor): |
no test coverage detected