該 ai.classify 函數使用生成式 AI 根據您選擇的自定義標籤對輸入文本進行分類,只需一行代碼即可。
備註
概觀
此 ai.classify 函式適用於 Spark DataFrames。 您必須將現有輸入欄的名稱指定為參數,以及分類標籤清單。
函式會傳回一個新的 DataFrame,其中包含符合輸入文字每一列的標籤,並儲存在輸出資料行中。
語法
df.ai.classify(labels=["category1", "category2", "category3"], input_col="text", output_col="classification")
參數
| 名稱 | Description |
|---|---|
labels 為必填項目 |
字串陣列,代表要與輸入欄中的文字值相符的分類標籤集。 |
input_col 為必填項目 |
包含現有欄名稱的 字串 ,其中包含要根據自訂標籤分類的輸入文字值。 |
output_col 可選 |
包含新資料行名稱的 字串 ,您要在其中儲存每個輸入文字列的分類標籤。 如果您未設定此參數,則會產生輸出欄的預設名稱。 |
error_col 可選 |
包含新欄位名稱的 字串。 新的欄會儲存處理每一行輸入文字時所產生的任何 OpenAI 錯誤。 如果您未設定此參數,則會為錯誤資料行產生預設名稱。 如果輸入資料列沒有任何錯誤,則此資料列中的值會 null。 |
退貨
函式會傳回 Spark DataFrame ,其中包含符合每個輸入文字資料列之分類標籤的新資料行。 如果無法分類文字值,對應的標籤會 null。
Example
# This code uses AI. Always review output for mistakes.
df = spark.createDataFrame([
("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!",)
], ["descriptions"])
categories = df.ai.classify(labels=["kitchen", "bedroom", "garage", "other"], input_col="descriptions", output_col="categories")
display(categories)
此範例程式碼儲存格提供下列輸出:
相關內容
用 ai.analyze_sentiment檢測情緒。
用 ai.embed 產生向量嵌入。
使用 ai_extract 擷取實體。
用 ai.fix_grammar修復語法。
使用 ai.generate_response 回答自訂使用者提示。
使用 ai.similarity 計算相似度。
使用 ai.summarize 總結文本。
使用 ai.translate 翻譯文本。
進一步了解 全套 AI 功能。
自訂 AI功能的配置。
我們錯過了您需要的功能嗎? 請在 Fabric Ideas 論壇上提出建議。