MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / fewshot_context

Method fewshot_context

test/general/lm_eval/tasks/pawsx.py:146–213  ·  view source on GitHub ↗

Returns a fewshot context string that is made up of a prepended description (if provided), the `num_fewshot` number of examples, and an appended prompt example. :param doc: str The document as returned from training_docs, validation_docs, or test_docs. :param num

(
        self, doc, num_fewshot, provide_description=None, rnd=None, description=None
    )

Source from the content-addressed store, hash-verified

144
145 @utils.positional_deprecated
146 def fewshot_context(
147 self, doc, num_fewshot, provide_description=None, rnd=None, description=None
148 ):
149 """Returns a fewshot context string that is made up of a prepended description
150 (if provided), the `num_fewshot` number of examples, and an appended prompt example.
151
152 :param doc: str
153 The document as returned from training_docs, validation_docs, or test_docs.
154 :param num_fewshot: int
155 The number of fewshot examples to provide in the returned context string.
156 :param provide_description: bool
157 Not implemented, and this option is deprecated and will be removed in a future version in favor of a different description providing method
158 :param rnd: random.Random
159 The pseudo-random number generator used to randomly sample examples.
160 WARNING: This is currently a required arg although it's optionalized with a default `None`.
161 :param description: str
162 The task's description that will be prepended to the fewshot examples.
163 :returns: str
164 The fewshot context.
165 """
166 assert (
167 rnd is not None
168 ), "A `random.Random` generator argument must be provided to `rnd`"
169 assert not provide_description, (
170 "The `provide_description` arg will be removed in future versions. To prepend "
171 "a custom description to the context, supply the corresponding string via the "
172 "`description` arg."
173 )
174 if provide_description is not None:
175 # nudge people to not specify it at all
176 print(
177 "WARNING: provide_description is deprecated and will be removed in a future version in favor of description_dict"
178 )
179
180 description = description + "\n\n" if description else ""
181
182 if num_fewshot == 0:
183 labeled_examples = ""
184 else:
185 # for sets with no training docs, draw from other set *but ensure no overlap with current doc*
186 if self.has_training_docs():
187 fewshotex = self.fewshot_examples(k=num_fewshot, rnd=rnd)
188 else:
189 if self._fewshot_docs is None:
190 self._fewshot_docs = list(
191 self.validation_docs()
192 if self.has_validation_docs()
193 else self.test_docs()
194 )
195
196 fewshotex = rnd.sample(self._fewshot_docs, num_fewshot + 1)
197
198 # get rid of the doc that's the one we're evaluating, if it's in the fewshot
199 fewshotex = [x for x in fewshotex if x != doc][:num_fewshot]
200
201 labeled_examples = (
202 "\n\n".join(
203 [

Callers

nothing calls this directly

Calls 7

has_training_docsMethod · 0.95
validation_docsMethod · 0.95
has_validation_docsMethod · 0.95
test_docsMethod · 0.95
doc_to_fewshot_promptMethod · 0.95
doc_to_textMethod · 0.95
fewshot_examplesMethod · 0.45

Tested by

no test coverage detected