次の方法で共有


pandas で ai.classify を使用する

ai.classify関数では、生成 AI を使用して、選択したカスタム ラベルに従って入力テキストを 1 行のコードで分類します。

  • この記事では、 pandas での ai.classify の使用について説明します。 PySpark で ai.classify を使用するには、 この記事を参照してください。
  • この概要記事では、他の AI 関数を参照してください。
  • AI 関数の構成をカスタマイズする方法について説明します。

概要

ai.classify 関数は、pandas Series クラスを拡張します。 ユーザー指定のラベルを各入力行に割り当てるには、 pandas DataFrame のテキスト列で関数を呼び出します。

この関数は、新しい DataFrame 列に格納できる分類ラベルを含む pandas Series を返します。

ヒント

ai.classify関数を少なくとも 2 つの入力ラベルと共に使用することをお勧めします。

構文

df["classification"] = df["input"].ai.classify("category1", "category2", "category3")

パラメーター

名前 Description
labels
必須
入力テキスト値に一致する分類ラベルのセットを表す 1 つ以上の 文字列

返品ポリシー

この関数は、各入力テキスト行の分類ラベルを含む pandas Series を返します。 テキスト値を分類できない場合は、対応するラベルが null

Example

# This code uses AI. Always review output for mistakes.

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)

このコード セルの例では、次の出力が提供されます。