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 pandas. For PySpark, see Use ai.fix_grammar with PySpark. - For all AI Functions and prerequisites, see AI Functions overview.
- Change default configuration for AI Functions with pandas.
Overview
The ai.fix_grammar function extends the pandas Series class. To correct the spelling, grammar, and punctuation of each row of input, call the function on a pandas DataFrame text column.
The function returns a pandas Series that contains corrected text values, which can be stored in a new DataFrame column.
Syntax
df["corrections"] = df["input"].ai.fix_grammar()
Parameters
None.
Returns
The function returns a pandas Series that contains corrected text for each input text row. If the input text is null, the result is null.
Example
# This code uses AI. Always review output for mistakes.
df = pd.DataFrame([
"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."
], columns=["text"])
df["corrections"] = df["text"].ai.fix_grammar()
display(df)
Output:
Multimodal input
To fix grammar in PDFs or text files, set column_type="path" when the input column contains file path strings. For setup, see Use multimodal input with AI Functions.
# This code uses AI. Always review output for mistakes.
custom_df["corrections"] = custom_df["file_path"].ai.fix_grammar(column_type="path")
display(custom_df)
Related content
- Use ai.fix_grammar with PySpark.
- Learn more about AI Functions.
- Use multimodal input with AI Functions.
- Change default configuration for AI Functions with pandas.
- Understand billing for AI Functions.