Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Evidentlyai Evidently Legacy Trigger Words Feature

From Leeroopedia
Knowledge Sources
Domains NLP, Feature Engineering, Text Analysis
Last Updated 2026-02-14 12:00 GMT

Overview

The TriggerWordsPresent class is a generated feature that checks whether any word from a predefined trigger word list appears in a text value, with optional lemmatization via NLTK's WordNet lemmatizer.

Description

TriggerWordsPresent extends ApplyColumnGeneratedFeature and produces a ColumnType.Categorical output (0 or 1). For each text value, it strips non-alphanumeric characters using a regex, splits the result into words, lowercases each word, optionally lemmatizes it using WordNetLemmatizer, and then checks if the processed word is in the provided words_list. If any match is found, the feature returns 1; otherwise it returns 0. For None or NaN values, it returns 0.

The NLTK WordNet resource is downloaded on first use, and the lemmatizer instance is lazily initialized and cached as a private attribute (_lem).

The feature column name is constructed as {column_name}_{word1}_{word2}_..._{lemmatize} and the display name follows the pattern "TriggerWordsPresent [words: [...], lemmatize: {bool}] for {column_name}".

Usage

Use this feature when you need to detect the presence of specific trigger words in text data, such as flagging offensive content, identifying specific topic mentions, or monitoring for keywords that indicate particular categories or issues.

Code Reference

Source Location

Signature

class TriggerWordsPresent(ApplyColumnGeneratedFeature):
    class Config:
        type_alias = "evidently:feature:TriggerWordsPresent"

    __feature_type__: ClassVar = ColumnType.Categorical
    column_name: str
    words_list: List[str]
    lemmatize: bool = True

    def __init__(self, column_name: str, words_list: List[str],
                 lemmatize: bool = True, display_name: Optional[str] = None): ...
    def apply(self, value: Any) -> int: ...

Import

from evidently.legacy.features.trigger_words_presence_feature import TriggerWordsPresent

I/O Contract

Inputs

Name Type Required Description
column_name str Yes Name of the text column to check for trigger words
words_list List[str] Yes List of trigger words to search for (should be lowercase)
lemmatize bool No Whether to lemmatize words before comparison (default: True)
display_name Optional[str] No Custom display name for the generated feature column

Outputs

Name Type Description
Trigger word presence int 1 if any trigger word is found in the text, 0 otherwise. Returns 0 for None or NaN values.

Usage Examples

from evidently.legacy.features.trigger_words_presence_feature import TriggerWordsPresent

# Check for the presence of specific trigger words with lemmatization
trigger_feature = TriggerWordsPresent(
    column_name="user_message",
    words_list=["urgent", "critical", "emergency"],
    lemmatize=True
)

# Without lemmatization
trigger_feature_no_lem = TriggerWordsPresent(
    column_name="comment",
    words_list=["buy", "sell", "trade"],
    lemmatize=False,
    display_name="Trade Keywords Present"
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment