Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The ai.fix_grammar function corrects spelling, grammar, and punctuation in each input row.
Note
- This article covers
ai.fix_grammarwith PySpark. For pandas, see Use ai.fix_grammar with pandas. - For all AI Functions and prerequisites, see AI Functions overview.
- Change default configuration for AI Functions with PySpark.
Overview
The ai.fix_grammar function is available for Spark DataFrames. You must specify the name of an existing input column as a parameter.
The function returns a new DataFrame that includes corrected text for each input text row, stored in an output column.
Syntax
df.ai.fix_grammar(input_col="input", output_col="corrections")
Parameters
| Name | Description |
|---|---|
input_col Required |
A string that contains the name of an existing column with input text values to correct for spelling, grammar, and punctuation. |
output_col Optional |
A string that contains the name of a new column to store corrected text for each row of input text. If you don't set this parameter, a default name generates for the output column. |
error_col Optional |
A string that contains the name of a new column to store any OpenAI errors that result from processing each row of input text. If you don't set this parameter, a default name generates for the error column. If there are no errors for a row of input, the value in this column is null. |
Returns
The function returns a Spark DataFrame that includes a new column that contains corrected text for each row of text in the input column. If the input text is null, the result is 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)
Output:
Multimodal input
To fix grammar in PDFs or text files, set input_col_type="path". For setup, see Use multimodal input with AI Functions.
# This code uses AI. Always review output for mistakes.
results = custom_df.ai.fix_grammar(
input_col="file_path",
input_col_type="path",
output_col="corrections",
)
display(results)
Related content
- Use ai.fix_grammar with pandas.
- Learn more about AI Functions.
- Use multimodal input with AI Functions.
- Change default configuration for AI Functions with PySpark.
- Understand billing for AI Functions.