该 ai.classify 函数使用生成 AI 根据所选的自定义标签对输入文本进行分类,只需一行代码。
注释
概述
ai.classify 函数扩展了 pandas Series 类。 若要将用户提供的标签分配给每个输入行,请对 pandas DataFrame 的文本列调用函数。
该函数返回一个 pandas Series,其中包含分类标签,该标签可以存储在新的 DataFrame 列中。
小窍门
建议将 ai.classify 函数与至少两个输入标签一起使用。
Syntax
df["classification"] = df["input"].ai.classify("category1", "category2", "category3")
参数
| Name | Description |
|---|---|
labels 必选 |
一个或多个 字符串 ,表示要与输入文本值匹配的分类标签集。 |
退货
该函数返回一个 pandas Series ,其中包含每个输入文本行的分类标签。 如果无法对文本值进行分类,则对应的标签为 null。
Example
# This code uses AI. Always review output for mistakes.
# Read terms: https://azure.microsoft.com/support/legal/preview-supplemental-terms/.
df = pd.DataFrame([
"This duvet, lovingly hand-crafted from all-natural fabric, is perfect for a good night's sleep.",
"Tired of friends judging your baking? With these handy-dandy measuring cups, you'll create culinary delights.",
"Enjoy this *BRAND NEW CAR!* A compact SUV perfect for the professional commuter!"
], columns=["descriptions"])
df["category"] = df['descriptions'].ai.classify("kitchen", "bedroom", "garage", "other")
display(df)
此示例代码单元提供以下输出:
相关内容
使用 ai.analyze_sentiment检测情绪。
使用 ai_extract提取实体。
使用 ai.fix_grammar修复语法。
使用 ai.generate_response回答自定义用户提示。
使用ai.summarize功能汇总文本。
使用 ai.translate 翻译文本。
详细了解 完整的 AI 函数集。
自定义 AI 函数的配置。
我们错过了所需的功能吗? 在面料创意论坛上提出建议。