snowflake.snowpark.DataFrameAIFunctions.sentiment¶
- DataFrameAIFunctions.sentiment(input_column: Union[snowflake.snowpark.column.Column, str], categories: Optional[List[str]] = None, *, output_column: Optional[str] = None) snowflake.snowpark.DataFrame[source]¶
Extract sentiment analysis from text content.
This method analyzes the sentiment of text in each row, providing overall sentiment and optionally sentiment for specific categories or aspects mentioned in the text.
- Parameters:
input_column – The column (Column object or column name as string) containing the text to analyze for sentiment.
categories – Optional list of up to 10 categories (also called entities or aspects) for which sentiment should be extracted. Each category may be a maximum of 30 characters long. For example, if extracting sentiment from restaurant reviews, you might specify
['cost', 'quality', 'service', 'wait time']as categories. If not provided, only overall sentiment is returned.output_column – The name of the output column to be appended. If not provided, a column named
AI_SENTIMENT_OUTPUTis appended.
- Returns:
A new DataFrame with an appended output column containing sentiment results. The output is a JSON object with a
categoriesfield containing an array of records. Each record includes:name: The category name (overallfor overall sentiment)sentiment: One ofunknown,positive,negative,neutral, ormixed
Examples:
Note
AI_SENTIMENT can analyze sentiment in English, French, German, Hindi, Italian, Spanish, and Portuguese. You can specify categories in the language of the text or in English.
This function or method is experimental since 1.39.0.