LogoLogo
HomeBlogGitHub
latest
latest
  • New DOCS
  • What is Evidently?
  • Get Started
    • Evidently Cloud
      • Quickstart - LLM tracing
      • Quickstart - LLM evaluations
      • Quickstart - Data and ML checks
      • Quickstart - No-code evaluations
    • Evidently OSS
      • OSS Quickstart - LLM evals
      • OSS Quickstart - Data and ML monitoring
  • Presets
    • All Presets
    • Data Drift
    • Data Quality
    • Target Drift
    • Regression Performance
    • Classification Performance
    • NoTargetPerformance
    • Text Evals
    • Recommender System
  • Tutorials and Examples
    • All Tutorials
    • Tutorial - Tracing
    • Tutorial - Reports and Tests
    • Tutorial - Data & ML Monitoring
    • Tutorial - LLM Evaluation
    • Self-host ML Monitoring
    • LLM as a judge
    • LLM Regression Testing
  • Setup
    • Installation
    • Evidently Cloud
    • Self-hosting
  • User Guide
    • 📂Projects
      • Projects overview
      • Manage Projects
    • 📶Tracing
      • Tracing overview
      • Set up tracing
    • 🔢Input data
      • Input data overview
      • Column mapping
      • Data for Classification
      • Data for Recommendations
      • Load data to pandas
    • 🚦Tests and Reports
      • Reports and Tests Overview
      • Get a Report
      • Run a Test Suite
      • Evaluate Text Data
      • Output formats
      • Generate multiple Tests or Metrics
      • Run Evidently on Spark
    • 📊Evaluations
      • Evaluations overview
      • Generate snapshots
      • Run no code evals
    • 🔎Monitoring
      • Monitoring overview
      • Batch monitoring
      • Collector service
      • Scheduled evaluations
      • Send alerts
    • 📈Dashboard
      • Dashboard overview
      • Pre-built Tabs
      • Panel types
      • Adding Panels
    • 📚Datasets
      • Datasets overview
      • Work with Datasets
    • 🛠️Customization
      • Data drift parameters
      • Embeddings drift parameters
      • Feature importance in data drift
      • Text evals with LLM-as-judge
      • Text evals with HuggingFace
      • Add a custom text descriptor
      • Add a custom drift method
      • Add a custom Metric or Test
      • Customize JSON output
      • Show raw data in Reports
      • Add text comments to Reports
      • Change color schema
    • How-to guides
  • Reference
    • All tests
    • All metrics
      • Ranking metrics
    • Data drift algorithm
    • API Reference
      • evidently.calculations
        • evidently.calculations.stattests
      • evidently.metrics
        • evidently.metrics.classification_performance
        • evidently.metrics.data_drift
        • evidently.metrics.data_integrity
        • evidently.metrics.data_quality
        • evidently.metrics.regression_performance
      • evidently.metric_preset
      • evidently.options
      • evidently.pipeline
      • evidently.renderers
      • evidently.report
      • evidently.suite
      • evidently.test_preset
      • evidently.test_suite
      • evidently.tests
      • evidently.utils
  • Integrations
    • Integrations
      • Evidently integrations
      • Notebook environments
      • Evidently and Airflow
      • Evidently and MLflow
      • Evidently and DVCLive
      • Evidently and Metaflow
  • SUPPORT
    • Migration
    • Contact
    • F.A.Q.
    • Telemetry
    • Changelog
  • GitHub Page
  • Website
Powered by GitBook
On this page
  • Code example
  • Custom descriptors
  • Single column descriptor
  • Double column descriptor
  1. User Guide
  2. Customization

Add a custom text descriptor

How to add custom text descriptors.

PreviousText evals with HuggingFaceNextAdd a custom drift method

Last updated 1 month ago

You are looking at the old Evidently documentation: this API is available with versions 0.6.7 or lower. Check the newer docs version .

You can implement custom row-level evaluations for text data that you will later use just like any other descriptor across Metrics and Tests. You can implement descriptors that use a single column or two columns.

Note that if you want to use LLM-based evaluations, you can write custom prompts using .

Code example

Refer to a How-to example:

Custom descriptors

Imports:

from evidently.descriptors import CustomColumnEval, CustomPairColumnEval

Single column descriptor

You can create a custom descriptor that will take a single column from your dataset and run a certain evaluation for each row.

Implement your evaluation as a Python function. It will take a pandas Series as input and return a transformed Series.

Here, the is_empty_string_callable function takes a column of strings and returns an "EMPTY" or "NON EMPTY" outcome for each.

def is_empty_string_callable(val1):
    return pd.Series(["EMPTY" if val == "" else "NON EMPTY" for val in val1], index=val1.index)

Create a custom descriptor. Create an example of CustomColumnEval class to wrap the evaluation logic into an object that you can later use to process specific dataset input.

empty_string = CustomColumnEval(
    func=is_empty_string_callable,
    feature_type="cat",
    display_name="Empty response"
)

Where:

  • func: Callable[[pd.Series], pd.Series] is a function that returns a transformed pandas Series.

  • display_name: str is the new descriptor's name that will appear in Reports and Test Suites.

  • feature_type is the type of descriptor that the function returns (cat for categorical, num for numerical)

Apply the new descriptor. To create a Report with a new Descriptor, pass it as a column_name to the ColumnSummaryMetric. This will compute the new descriptor for all rows in the specified column and summarize its distribution:

report = Report(metrics=[
    ColumnSummaryMetric(column_name=empty_string.on("response")),
])

Run the Report on your df dataframe as usual:

report.run(reference_data=None, 
           current_data=df)

Double column descriptor

You can create a custom descriptor that will take two columns from your dataset and will run a certain evaluation for each row. (For example, for pairwise evaluators).

Implement your evaluation as a Python function. Here, the exact_match_callable function takes two columns and checks whether each pair of values is the same, returning "MATCH" if they are equal and "MISMATCH" if they are not.

def exact_match_callable(val1, val2):
    return pd.Series(["MATCH" if val else "MISMATCH" for val in val1 == val2])

Create a custom descriptor. Create an example of the CustomPairColumnEval class to wrap the evaluation logic into an object that you can later use to process two named columns in a dataset.

exact_match =  CustomPairColumnEval(
    func=exact_match_callable,
    first_column="response",
    second_column="question",
    feature_type="cat",
    display_name="Exact match between response and question"
)

Where:

  • func: Callable[[pd.Series, pd.Series], pd.Series] is a function that returns a transformed pandas Series after evaluating two columns.

  • first_column: str is the name of the first column to be passed into the function.

  • second_column: str is the name of the second column to be passed into the function.

  • display_name: str is the new descriptor's name that will appear in Reports and Test Suites.

  • feature_type is the type of descriptor that the function returns (cat for categorical, num for numerical).

Apply the new descriptor. To create a Report with a new Descriptor, pass it as a column_name to the ColumnSummaryMetric. This will compute the new descriptor for all rows in the dataset and summarize its distribution:

report = Report(metrics=[
    ColumnSummaryMetric(column_name=exact_match.as_column())
])

Run the Report on your df dataframe as usual:

report.run(reference_data=None, 
           current_data=df)
🛠️
here
LLM judge templates
evidently/examples/how_to_questions/how_to_use_llm_judge_template.ipynb at ad71e132d59ac3a84fce6cf27bd50b12b10d9137 · evidentlyai/evidentlyGitHub
Logo