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

Method fewshot_context

test/general/lm_eval/base.py:674–740  ·  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

672
673 @utils.positional_deprecated
674 def fewshot_context(
675 self, doc, num_fewshot, provide_description=None, rnd=None, description=None
676 ):
677 """Returns a fewshot context string that is made up of a prepended description
678 (if provided), the `num_fewshot` number of examples, and an appended prompt example.
679
680 :param doc: str
681 The document as returned from training_docs, validation_docs, or test_docs.
682 :param num_fewshot: int
683 The number of fewshot examples to provide in the returned context string.
684 :param provide_description: bool
685 Not implemented, and this option is deprecated and will be removed in a future version in favor of a different description providing method
686 :param rnd: random.Random
687 The pseudo-random number generator used to randomly sample examples.
688 WARNING: This is currently a required arg although it's optionalized with a default `None`.
689 :param description: str
690 The task's description that will be prepended to the fewshot examples.
691 :returns: str
692 The fewshot context.
693 """
694 assert (
695 rnd is not None
696 ), "A `random.Random` generator argument must be provided to `rnd`"
697 assert not provide_description, (
698 "The `provide_description` arg will be removed in future versions. To prepend "
699 "a custom description to the context, supply the corresponding string via the "
700 "`description` arg."
701 )
702 if provide_description is not None:
703 # nudge people to not specify it at all
704 print(
705 "WARNING: provide_description is deprecated and will be removed in a future version in favor of description_dict"
706 )
707
708 description = description + "\n\n" if description else ""
709
710 if num_fewshot == 0:
711 labeled_examples = ""
712 else:
713 # for sets with no training docs, draw from other set *but ensure no overlap with current doc*
714 if self.has_training_docs():
715 fewshotex = self.fewshot_examples(k=num_fewshot, rnd=rnd)
716 else:
717 if self._fewshot_docs is None:
718 self._fewshot_docs = list(
719 self.validation_docs()
720 if self.has_validation_docs()
721 else self.test_docs()
722 )
723
724 fewshotex = rnd.sample(self._fewshot_docs, num_fewshot + 1)
725
726 # get rid of the doc that's the one we're evaluating, if it's in the fewshot
727 fewshotex = [x for x in fewshotex if x != doc][:num_fewshot]
728
729 labeled_examples = (
730 "\n\n".join(
731 [

Callers 1

evaluateFunction · 0.45

Calls 7

has_training_docsMethod · 0.95
fewshot_examplesMethod · 0.95
validation_docsMethod · 0.95
has_validation_docsMethod · 0.95
test_docsMethod · 0.95
doc_to_textMethod · 0.95
doc_to_targetMethod · 0.95

Tested by

no test coverage detected