MCPcopy Create free account
hub / github.com/THUDM/P-tuning / InputExample

Class InputExample

PT-Fewshot/pet/utils.py:65–109  ·  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

63
64
65class InputExample(object):
66 """A raw input example consisting of one or two segments of text and a label"""
67
68 def __init__(self, guid, text_a, text_b=None, label=None, logits=None, meta: Optional[Dict] = None, idx=-1):
69 """
70 Create a new InputExample.
71 :param guid: a unique textual identifier
72 :param text_a: the sequence of text
73 :param text_b: an optional, second sequence of text
74 :param label: an optional label
75 :param logits: an optional list of per-class logits
76 :param meta: an optional dictionary to store arbitrary meta information
77 :param idx: an optional numeric index
78 """
79 self.guid = guid
80 self.text_a = text_a
81 self.text_b = text_b
82 self.label = label
83 self.logits = logits
84 self.idx = idx
85 self.meta = meta if meta else {}
86
87 def __repr__(self):
88 return str(self.to_json_string())
89
90 def to_dict(self):
91 """Serialize this instance to a Python dictionary."""
92 output = copy.deepcopy(self.__dict__)
93 return output
94
95 def to_json_string(self):
96 """Serialize this instance to a JSON string."""
97 return json.dumps(self.to_dict(), indent=2, sort_keys=True) + "\n"
98
99 @staticmethod
100 def load_examples(path: str) -> List['InputExample']:
101 """Load a set of input examples from a file"""
102 with open(path, 'rb') as fh:
103 return pickle.load(fh)
104
105 @staticmethod
106 def save_examples(examples: List['InputExample'], path: str) -> None:
107 """Save a set of input examples to a file"""
108 with open(path, 'wb') as fh:
109 pickle.dump(examples, fh)
110
111
112class InputFeatures(object):

Callers 8

_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