该 ai.analyze_sentiment 函数使用生成 AI 来检测输入文本的情感状态,只需一行代码即可。 它可以检测输入的情绪状态是正、负、混合还是中性。 它还可以根据指定的标签检测情绪状态。 如果函数无法确定情绪,它将输出留空。
注释
概述
ai.analyze_sentiment 函数扩展了 pandas Series 类。 若要检测每个输入行的情绪,请对 pandas DataFrame 文本列调用函数。
该函数返回一个 pandas Series,其中包含情绪标签,该标签可以存储在 DataFrame 的新列中。
Syntax
# Default sentiment labels
df["sentiment"] = df["input"].ai.analyze_sentiment()
# Custom sentiment labels
df["sentiment"] = df["input"].ai.analyze_sentiment("label2", "label2", "label3")
参数
| Name | Description |
|---|---|
labels 可选 |
一个或多个表示要与输入文本值匹配的情绪标签集的 字符串 。 |
退货
该函数返回一个 pandas Series,其中包含每个输入文本行的情绪标签。 默认情绪标签包括positive、negative或neutralmixed。 如果指定了自定义标签,则改用这些标签。 如果无法确定情绪,则返回值 null。
Example
# This code uses AI. Always review output for mistakes.
df = pd.DataFrame([
"The cleaning spray permanently stained my beautiful kitchen counter. Never again!",
"I used this sunscreen on my vacation to Florida, and I didn't get burned at all. Would recommend.",
"I'm torn about this speaker system. The sound was high quality, though it didn't connect to my roommate's phone.",
"The umbrella is OK, I guess."
], columns=["reviews"])
df["sentiment"] = df["reviews"].ai.analyze_sentiment()
display(df)
此示例代码单元提供以下输出:
相关内容
使用 ai.classify 对文本进行分类。
使用 ai.embed 生成矢量嵌入。
使用 ai_extract提取实体。
使用 ai.fix_grammar修复语法。
使用 ai.generate_response回答自定义用户提示。
使用ai.summarize功能汇总文本。
使用 ai.translate 翻译文本。
详细了解 完整的 AI 函数集。
自定义 AI 函数的配置。
我们错过了所需的功能吗? 在面料创意论坛上提出建议。