Implementation:Evidentlyai Evidently Legacy Sentiment Feature
| Knowledge Sources | |
|---|---|
| Domains | NLP, Feature Engineering, Sentiment Analysis |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
The Sentiment class is a generated feature that computes the VADER compound sentiment polarity score for each text value in a specified column.
Description
Sentiment extends ApplyColumnGeneratedFeature and leverages NLTK's SentimentIntensityAnalyzer (VADER) to produce a numerical sentiment score for each row. The VADER lexicon is downloaded on first use and the analyzer instance is cached as a private attribute (_sid) for reuse across rows. For each cell value, the apply method returns the compound polarity score (a float ranging from -1.0 to 1.0), or 0 if the value is None or NaN.
The feature type is ColumnType.Numerical and produces a column named according to the template "Sentiment for {column_name}".
Usage
Use this feature when you need to derive a sentiment signal from text columns in your dataset, for example to monitor sentiment drift or to include sentiment as a derived metric in an Evidently report or test suite.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File:
src/evidently/legacy/features/sentiment_feature.py
Signature
class Sentiment(ApplyColumnGeneratedFeature):
class Config:
type_alias = "evidently:feature:Sentiment"
__feature_type__: ClassVar = ColumnType.Numerical
display_name_template: ClassVar = "Sentiment for {column_name}"
column_name: str
def __init__(self, column_name: str, display_name: Optional[str] = None): ...
def apply(self, value: Any) -> float: ...
Import
from evidently.legacy.features.sentiment_feature import Sentiment
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| column_name | str | Yes | Name of the text column to compute sentiment for |
| display_name | Optional[str] | No | Custom display name for the generated feature column |
Outputs
| Name | Type | Description |
|---|---|---|
| Sentiment score | float | VADER compound polarity score for each row, ranging from -1.0 (most negative) to 1.0 (most positive). Returns 0 for None or NaN values. |
Usage Examples
from evidently.legacy.features.sentiment_feature import Sentiment
# Create a sentiment feature for the "review_text" column
sentiment_feature = Sentiment(column_name="review_text")
# With a custom display name
sentiment_feature = Sentiment(column_name="comment", display_name="Comment Sentiment Score")