共用方式為


將ai.fix_grammar與 PySpark 搭配使用

ai.fix_grammar 功能使用生成式 AI 來糾正輸入文本的拼寫、語法和標點符號,只需一行代碼即可。

備註

  • 本文介紹了將 ai.fix_grammar 與 PySpark 搭配使用。 若要將 ai.fix_grammar 與熊貓搭配使用,請參閱 這篇文章
  • 請參閱 此概述文章中的其他 AI 功能。
  • 瞭解如何自訂 AI 功能的設定

概觀

ai.fix_grammar 函式適用於 Spark DataFrames。 您必須將現有輸入資料行的名稱指定為參數。

函式會傳回新的 DataFrame,其中包含儲存在輸出資料行中的每個輸入文字資料列的更正文字。

語法

df.ai.fix_grammar(input_col="input", output_col="corrections")

參數

名稱 Description
input_col
為必填項目
包含現有直欄名稱的 字串 ,其中包含要更正拼字、文法和標點符號的輸入文字值。
output_col
可選
包含新資料行名稱的 字串 ,用於儲存每一列輸入文字的更正文字。 如果您未設定此參數,則會為輸出資料行產生預設名稱。
error_col
可選
字串,其中包含新欄位的名稱,以存儲處理每一行輸入文字時產生的任何 OpenAI 錯誤。 如果您未設定此參數,則會為錯誤資料行產生預設名稱。 如果輸入資料列沒有任何錯誤,則此資料列中的值會 null

退貨

函式會傳回 Spark DataFrame ,其中包含一個新資料行,其中包含輸入資料行中每一列文字的更正文字。 如果輸入文字 null,則結果會 null

Example

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

df = spark.createDataFrame([
        ("There are an error here.",),
        ("She and me go weigh back. We used to hang out every weeks.",),
        ("The big picture are right, but you're details is all wrong.",)
    ], ["text"])

results = df.ai.fix_grammar(input_col="text", output_col="corrections")
display(results)

此範例程式碼儲存格提供下列輸出:

螢幕擷取畫面顯示具有「文字」欄和「更正」欄的資料框,其中包含文字欄中的文字,並具有更正的文法。