Home / Class/ ScoreStringEvalChain Class — langchain Architecture

ScoreStringEvalChain Class — langchain Architecture

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

Entity Profile

Dependency Diagram

graph TD
  100e92ce_b2db_532a_a36d_6d9957c8bc85["ScoreStringEvalChain"]
  42f35457_68a1_961e_1ac4_cbaa4a2b48b3["StringEvaluator"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|extends| 42f35457_68a1_961e_1ac4_cbaa4a2b48b3
  649622c5_b1b0_2ee7_22ee_c9c12162f9c3["LLMEvalChain"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|extends| 649622c5_b1b0_2ee7_22ee_c9c12162f9c3
  8d3a235d_a08f_2979_f52a_1772067dd1d3["LLMChain"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|extends| 8d3a235d_a08f_2979_f52a_1772067dd1d3
  3e3a6cc6_20d3_958c_6187_7fe8da9acaf2["eval_chain.py"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|defined in| 3e3a6cc6_20d3_958c_6187_7fe8da9acaf2
  3a242947_f64b_97f2_545f_5a0bdf685961["is_lc_serializable()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 3a242947_f64b_97f2_545f_5a0bdf685961
  643b1909_3015_425d_c421_d7127b96b6ab["requires_reference()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 643b1909_3015_425d_c421_d7127b96b6ab
  2da352ca_6951_d6cc_ec9e_921a7184ee8c["requires_input()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 2da352ca_6951_d6cc_ec9e_921a7184ee8c
  4d6fc4e4_9eb4_f556_a6e2_2f5b58153074["evaluation_name()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 4d6fc4e4_9eb4_f556_a6e2_2f5b58153074
  d2da8597_0127_09c2_01e2_cadf4a381e48["_skip_reference_warning()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| d2da8597_0127_09c2_01e2_cadf4a381e48
  06dff259_bc0f_cd14_4290_9a44925701e4["from_llm()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 06dff259_bc0f_cd14_4290_9a44925701e4
  5ba6784e_52a7_f9e8_de0f_c42cef48dd0b["_prepare_input()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 5ba6784e_52a7_f9e8_de0f_c42cef48dd0b
  1ba3de7d_f339_8eae_b310_30c58c7b3d3f["_prepare_output()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 1ba3de7d_f339_8eae_b310_30c58c7b3d3f
  9c3f9257_0fb7_153e_ac98_acdc020ded59["_evaluate_strings()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 9c3f9257_0fb7_153e_ac98_acdc020ded59
  492221f6_fc30_f273_5263_2ac9df9a6de5["_aevaluate_strings()"]
  100e92ce_b2db_532a_a36d_6d9957c8bc85 -->|method| 492221f6_fc30_f273_5263_2ac9df9a6de5

Relationship Graph

Source Code

libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py lines 150–411

class ScoreStringEvalChain(StringEvaluator, LLMEvalChain, LLMChain):
    """A chain for scoring on a scale of 1-10 the output of a model.

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

    Example:
        >>> from langchain_openai import ChatOpenAI
        >>> from langchain_classic.evaluation.scoring import ScoreStringEvalChain
        >>> model = ChatOpenAI(temperature=0, model_name="gpt-4")
        >>> chain = ScoreStringEvalChain.from_llm(llm=model)
        >>> result = chain.evaluate_strings(
        ...     input="What is the chemical formula for water?",
        ...     prediction="H2O",
        ...     reference="The chemical formula for water is H2O.",
        ... )
        >>> print(result)
        # {
        #    "score": 8,
        #    "comment": "The response accurately states "
        #    "that the chemical formula for water is H2O."
        #    "However, it does not provide an explanation of what the formula means."
        # }

    """

    output_key: str = "results"
    output_parser: BaseOutputParser = Field(
        default_factory=ScoreStringResultOutputParser,
    )
    normalize_by: float | None = None
    """The value to normalize the score by, if specified."""
    criterion_name: str
    """The name of the criterion being evaluated."""

    model_config = ConfigDict(
        extra="ignore",
    )

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

    @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 evaluation_name(self) -> str:
        """Get the name of the evaluation.

        Returns:
        -------
        str
            The name of the evaluation.
        """
        return f"score_string:{self.criterion_name}"

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

Frequently Asked Questions

What is the ScoreStringEvalChain class?
ScoreStringEvalChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py.
Where is ScoreStringEvalChain defined?
ScoreStringEvalChain is defined in libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py at line 150.
What does ScoreStringEvalChain extend?
ScoreStringEvalChain extends StringEvaluator, LLMEvalChain, LLMChain.

Analyze Your Own Codebase

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

Try Supermodel Free