MCPcopy Create free account
hub / github.com/tensorflow/models / SquadExample

Class SquadExample

official/nlp/data/squad_lib.py:31–79  ·  view source on GitHub ↗

A single training/test example for simple sequence classification. For examples without an answer, the start and end position are -1. Attributes: qas_id: ID of the question-answer pair. question_text: Original text for the question. doc_tokens: The list of tokens in the context obt

Source from the content-addressed store, hash-verified

29
30
31class SquadExample(object):
32 """A single training/test example for simple sequence classification.
33
34 For examples without an answer, the start and end position are -1.
35
36 Attributes:
37 qas_id: ID of the question-answer pair.
38 question_text: Original text for the question.
39 doc_tokens: The list of tokens in the context obtained by splitting on
40 whitespace only.
41 orig_answer_text: Original text for the answer.
42 start_position: Starting index of the answer in `doc_tokens`.
43 end_position: Ending index of the answer in `doc_tokens`.
44 is_impossible: Whether the question is impossible to answer given the
45 context. Only used in SQuAD 2.0.
46 """
47
48 def __init__(self,
49 qas_id,
50 question_text,
51 doc_tokens,
52 orig_answer_text=None,
53 start_position=None,
54 end_position=None,
55 is_impossible=False):
56 self.qas_id = qas_id
57 self.question_text = question_text
58 self.doc_tokens = doc_tokens
59 self.orig_answer_text = orig_answer_text
60 self.start_position = start_position
61 self.end_position = end_position
62 self.is_impossible = is_impossible
63
64 def __str__(self):
65 return self.__repr__()
66
67 def __repr__(self):
68 s = ""
69 s += "qas_id: %s" % (tokenization.printable_text(self.qas_id))
70 s += ", question_text: %s" % (
71 tokenization.printable_text(self.question_text))
72 s += ", doc_tokens: [%s]" % (" ".join(self.doc_tokens))
73 if self.start_position:
74 s += ", start_position: %d" % (self.start_position)
75 if self.start_position:
76 s += ", end_position: %d" % (self.end_position)
77 if self.start_position:
78 s += ", is_impossible: %r" % (self.is_impossible)
79 return s
80
81
82class InputFeatures(object):

Callers 1

read_squad_examplesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected