Implementation:Evidentlyai Evidently Legacy Words Descriptor
| Knowledge Sources | |
|---|---|
| Domains | ML Monitoring, NLP, Text Analysis |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
Provides descriptor classes for checking word inclusion, exclusion, matching, and non-matching between text columns using configurable word lists and lemmatization.
Description
This module defines four descriptor classes that wrap the corresponding feature classes from evidently.legacy.features.words_feature:
- ExcludesWords - Checks whether a text column excludes specific words from a provided word list. Supports "all" (default) or "any" matching mode and optional lemmatization.
- IncludesWords - Checks whether a text column includes specific words from a provided word list. Defaults to "any" matching mode with lemmatization enabled.
- WordMatch - Compares words in two columns and evaluates whether there is a match. Takes a with_column parameter to specify the second column for comparison.
- WordNoMatch - The inverse of WordMatch; evaluates whether words in two columns do not match.
All four classes extend FeatureDescriptor and implement the feature() method, which accepts a column_name parameter and returns the corresponding GeneratedFeature from the words_feature module. Each descriptor supports configurable mode ("any" or "all"), lemmatize toggle, and an optional display_name inherited from the base class.
Usage
Use these descriptors when building Evidently reports or test suites to check text quality constraints such as whether generated text avoids forbidden words (ExcludesWords), contains required words (IncludesWords), or matches/diverges from a reference column (WordMatch/WordNoMatch). They are particularly useful in LLM monitoring to validate output against expected vocabulary.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File:
src/evidently/legacy/descriptors/words_descriptor.py
Signature
class ExcludesWords(FeatureDescriptor):
words_list: List[str]
mode: str = "all"
lemmatize: bool = True
def feature(self, column_name: str) -> GeneratedFeature: ...
class IncludesWords(FeatureDescriptor):
words_list: List[str]
mode: str = "any"
lemmatize: bool = True
def feature(self, column_name: str) -> GeneratedFeature: ...
class WordMatch(FeatureDescriptor):
with_column: str
mode: str = "any"
lemmatize: bool = True
def feature(self, column_name: str) -> GeneratedFeature: ...
class WordNoMatch(FeatureDescriptor):
with_column: str
mode: str = "any"
lemmatize: bool = True
def feature(self, column_name: str) -> GeneratedFeature: ...
Import
from evidently.legacy.descriptors.words_descriptor import ExcludesWords
from evidently.legacy.descriptors.words_descriptor import IncludesWords
from evidently.legacy.descriptors.words_descriptor import WordMatch
from evidently.legacy.descriptors.words_descriptor import WordNoMatch
I/O Contract
Inputs
ExcludesWords / IncludesWords:
| Name | Type | Required | Description |
|---|---|---|---|
| words_list | List[str] | Yes | The list of words to check for inclusion or exclusion. |
| mode | str | No | Matching mode: "all" (every word must match) or "any" (at least one word must match). Default varies by class. |
| lemmatize | bool | No | Whether to apply lemmatization before matching. Defaults to True. |
| display_name | Optional[str] | No | Custom display name for the generated feature (inherited from BaseDescriptor). |
| column_name | str | Yes (at call time) | The text column to evaluate, passed to the feature() method. |
WordMatch / WordNoMatch:
| Name | Type | Required | Description |
|---|---|---|---|
| with_column | str | Yes | Name of the second column to compare words against. |
| mode | str | No | Matching mode: "any" or "all". Defaults to "any". |
| lemmatize | bool | No | Whether to apply lemmatization before matching. Defaults to True. |
| display_name | Optional[str] | No | Custom display name for the generated feature. |
| column_name | str | Yes (at call time) | The primary text column, passed to the feature() method. |
Outputs
| Name | Type | Description |
|---|---|---|
| feature() return | GeneratedFeature | A words_feature instance (ExcludesWords, IncludesWords, WordMatch, or WordNoMatch) ready for feature generation. |
Usage Examples
from evidently.legacy.descriptors.words_descriptor import (
ExcludesWords, IncludesWords, WordMatch, WordNoMatch
)
# Check that responses exclude forbidden words
excludes = ExcludesWords(
words_list=["error", "fail", "crash"],
mode="all",
lemmatize=True,
display_name="No Error Words"
)
feature = excludes.feature("response")
# Check that responses include at least one required keyword
includes = IncludesWords(
words_list=["thank", "welcome", "please"],
mode="any",
)
feature = includes.feature("response")
# Match words between prediction and reference columns
match = WordMatch(with_column="reference_text", mode="any")
feature = match.feature("generated_text")
# Check for non-matching words
no_match = WordNoMatch(with_column="reference_text", mode="any")
feature = no_match.feature("generated_text")
Related Pages
- Environment:Evidentlyai_Evidently_Python_Core_Environment
- Evidentlyai_Evidently_Legacy_Generated_Features - Base classes (FeatureDescriptor, GeneratedFeature) that these descriptors extend.