Home / Class/ PairwiseStringEvalChain Class — langchain Architecture

PairwiseStringEvalChain Class — langchain Architecture

Architecture documentation for the PairwiseStringEvalChain class in eval_chain.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  6997d03c_6524_f97b_7017_b2f56540bc07["PairwiseStringEvalChain"]
  910b9203_afa5_b8ca_1a1e_3933f70c340f["PairwiseStringEvaluator"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|extends| 910b9203_afa5_b8ca_1a1e_3933f70c340f
  5415ac56_b757_05e4_1f48_99970c59f799["LLMEvalChain"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|extends| 5415ac56_b757_05e4_1f48_99970c59f799
  ccf50fe1_4990_cf19_1e2d_25efe83f53c5["LLMChain"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|extends| ccf50fe1_4990_cf19_1e2d_25efe83f53c5
  7db782f0_522e_d3f7_666f_da5a1e80af4a["eval_chain.py"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|defined in| 7db782f0_522e_d3f7_666f_da5a1e80af4a
  74f1cd4c_7cfd_ae12_62f3_c4ecc0763645["is_lc_serializable()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| 74f1cd4c_7cfd_ae12_62f3_c4ecc0763645
  a61c9572_7e51_7905_c483_ad76f7506dea["requires_reference()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| a61c9572_7e51_7905_c483_ad76f7506dea
  009cff85_fcf3_5977_efdf_71645c0f320e["requires_input()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| 009cff85_fcf3_5977_efdf_71645c0f320e
  76fe65cd_f2e7_29b2_b7b0_4bdbffd7d9f5["_skip_reference_warning()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| 76fe65cd_f2e7_29b2_b7b0_4bdbffd7d9f5
  7f35a36c_35ea_7f92_9706_72edf0eab7e3["from_llm()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| 7f35a36c_35ea_7f92_9706_72edf0eab7e3
  ae00f73a_3274_a24c_aed1_e45be85f0fdd["_prepare_input()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| ae00f73a_3274_a24c_aed1_e45be85f0fdd
  8d13c038_c9d1_0607_fe88_3a2eaf8195b9["_prepare_output()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| 8d13c038_c9d1_0607_fe88_3a2eaf8195b9
  69c11dee_1bd0_daca_16bd_24a2df0fec66["_evaluate_string_pairs()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| 69c11dee_1bd0_daca_16bd_24a2df0fec66
  a98e0fa5_2b25_b62a_6940_98a36013ab00["_aevaluate_string_pairs()"]
  6997d03c_6524_f97b_7017_b2f56540bc07 -->|method| a98e0fa5_2b25_b62a_6940_98a36013ab00

Relationship Graph

Source Code

libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py lines 156–408

class PairwiseStringEvalChain(PairwiseStringEvaluator, LLMEvalChain, LLMChain):
    r"""Pairwise String Evaluation Chain.

    A chain for comparing two outputs, such as the outputs
     of two models, prompts, or outputs of a single model on similar inputs.

    Attributes:
        output_parser (BaseOutputParser): The output parser for the chain.

    Example:
        >>> from langchain_openai import ChatOpenAI
        >>> from langchain_classic.evaluation.comparison import PairwiseStringEvalChain
        >>> model = ChatOpenAI(
        ...     temperature=0, model_name="gpt-4", model_kwargs={"random_seed": 42}
        ... )
        >>> chain = PairwiseStringEvalChain.from_llm(llm=model)
        >>> result = chain.evaluate_string_pairs(
        ...     input = "What is the chemical formula for water?",
        ...     prediction = "H2O",
        ...     prediction_b = (
        ...        "The chemical formula for water is H2O, which means"
        ...        " there are two hydrogen atoms and one oxygen atom."
        ...     reference = "The chemical formula for water is H2O.",
        ... )
        >>> print(result)
        # {
        #    "value": "B",
        #    "comment": "Both responses accurately state"
        #       " that the chemical formula for water is H2O."
        #       " However, Response B provides additional information"
        # .     " by explaining what the formula means.\n[[B]]"
        # }

    """

    output_key: str = "results"
    output_parser: BaseOutputParser = Field(
        default_factory=PairwiseStringResultOutputParser,
    )

    @classmethod
    @override
    def is_lc_serializable(cls) -> bool:
        return False

    model_config = ConfigDict(
        extra="ignore",
    )

    @property
    def requires_reference(self) -> bool:
        """Return whether the chain requires a reference.

        Returns:
            `True` if the chain requires a reference, `False` otherwise.

        """
        return False

    @property
    def requires_input(self) -> bool:
        """Return whether the chain requires an input.

        Returns:
            `True` if the chain requires an input, `False` otherwise.

        """
        return True

    @property
    def _skip_reference_warning(self) -> str:
        """Return the warning to show when reference is ignored.

        Returns:
            The warning to show when reference is ignored.

        """
        return (
            f"Ignoring reference in {self.__class__.__name__}, as it is not expected."
            "\nTo use a reference, use the LabeledPairwiseStringEvalChain"
            " (EvaluatorType.LABELED_PAIRWISE_STRING) instead."

Frequently Asked Questions

What is the PairwiseStringEvalChain class?
PairwiseStringEvalChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py.
Where is PairwiseStringEvalChain defined?
PairwiseStringEvalChain is defined in libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py at line 156.
What does PairwiseStringEvalChain extend?
PairwiseStringEvalChain extends PairwiseStringEvaluator, LLMEvalChain, LLMChain.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free