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, BaseModel

Select 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.

add_example(example: Dict[str, str]) None[source]¶

Add new example to list.

validator check_dependencies  »  all fields[source]¶

Check that valid dependencies exist.

select_examples(input_variables: Dict[str, str]) List[dict][source]¶

Return list of examples sorted by ngram_overlap_score with input.

Descending order. Excludes any examples with ngram_overlap_score less than or equal to threshold.

Examples using NGramOverlapExampleSelector¶