langchain.prompts.example_selector.ngram_overlap.NGramOverlapExampleSelector¶
- class langchain.prompts.example_selector.ngram_overlap.NGramOverlapExampleSelector(*, examples: List[dict], example_prompt: PromptTemplate, threshold: float = - 1.0)[source]¶
Bases:
BaseExampleSelector,BaseModelSelect and order examples based on ngram overlap score (sentence_bleu score).
https://www.nltk.org/_modules/nltk/translate/bleu_score.html https://aclanthology.org/P02-1040.pdf
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
- param example_prompt: langchain.prompts.prompt.PromptTemplate [Required]¶
Prompt template used to format the examples.
- param examples: List[dict] [Required]¶
A list of the examples that the prompt template expects.
- param threshold: float = -1.0¶
Threshold at which algorithm stops. Set to -1.0 by default.
For negative threshold: select_examples sorts examples by ngram_overlap_score, but excludes none. For threshold greater than 1.0: select_examples excludes all examples, and returns an empty list. For threshold equal to 0.0: select_examples sorts examples by ngram_overlap_score, and excludes examples with no ngram overlap with input.