MCPcopy Index your code
hub / github.com/THUDM/GLM / InputExample

Class InputExample

tasks/data_utils.py:43–90  ·  view source on GitHub ↗

A raw input example consisting of one or two segments of text and a label

Source from the content-addressed store, hash-verified

41
42
43class InputExample(object):
44 """A raw input example consisting of one or two segments of text and a label"""
45
46 def __init__(self, guid, text_a, text_b=None, label=None, logits=None, meta: Optional[Dict] = None, idx=-1,
47 num_choices=1):
48 """
49 Create a new InputExample.
50
51 :param guid: a unique textual identifier
52 :param text_a: the sequence of text
53 :param text_b: an optional, second sequence of text
54 :param label: an optional label
55 :param logits: an optional list of per-class logits
56 :param meta: an optional dictionary to store arbitrary meta information
57 :param idx: an optional numeric index
58 """
59 self.guid = guid
60 self.text_a = text_a
61 self.text_b = text_b
62 self.label = label
63 self.logits = logits
64 self.idx = idx
65 self.num_choices = num_choices
66 self.meta = meta if meta else {}
67
68 def __repr__(self):
69 return str(self.to_json_string())
70
71 def to_dict(self):
72 """Serialize this instance to a Python dictionary."""
73 output = copy.deepcopy(self.__dict__)
74 return output
75
76 def to_json_string(self):
77 """Serialize this instance to a JSON string."""
78 return json.dumps(self.to_dict(), indent=2, sort_keys=True) + "\n"
79
80 @staticmethod
81 def load_examples(path: str) -> List['InputExample']:
82 """Load a set of input examples from a file"""
83 with open(path, 'rb') as fh:
84 return pickle.load(fh)
85
86 @staticmethod
87 def save_examples(examples: List['InputExample'], path: str) -> None:
88 """Save a set of input examples to a file"""
89 with open(path, 'wb') as fh:
90 pickle.dump(examples, fh)
91
92
93def num_special_tokens_to_add(text_a_ids, text_b_ids, answer_ids, add_cls, add_sep, add_piece, add_eos=True):

Callers 15

_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90
_create_examplesMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected