Text Proofreader

The MediaPipe Text Proofreader task lets you identify spelling, grammatical, and stylistic errors in a text and generate a corrected version while maintaining the original meaning. This task operates on text data with a machine learning (ML) model and outputs the corrected text.

Animated preview of Text Proofreader
On-device demo Text Proofreader Detect and correct grammar, spelling, and style errors locally with Gemma 3 1B. Available on Android, iOS, and desktop Python with on-device Gemma 3 1B via LiteRT-LM. On-device benchmark · Pixel 10 Pro CPU Gemma 3 1B · 100 words Prefill1,280tok/sDecode170tok/sE2E980ms

Quickstart

Install the SDK for your platform, initialize the task with a model, and run inference.

Android (Kotlin)

Gradleimplementation("com.google.mediapipe:tasks-text:latest.release")Sample code·Setup guide
import com.google.mediapipe.tasks.text.textproofreader.TextProofreader
import com.google.mediapipe.tasks.text.textproofreader.TextProofreader.TextProofreaderOptions

val options = TextProofreaderOptions.builder()
    .setModelPath("${context.filesDir}/proofread_quant_200m.litertlm")
    .build()

val proofreader = TextProofreader.createFromOptions(context, options)

val inputText = "Their are severel typos in this sentance."
val result = proofreader.proofread(inputText)
val correctedText = result.proofreadText

Android (Java)

Gradleimplementation 'com.google.mediapipe:tasks-text:latest.release'Sample code·Setup guide
import com.google.mediapipe.tasks.text.textproofreader.TextProofreader;
import com.google.mediapipe.tasks.text.textproofreader.TextProofreader.TextProofreaderOptions;
import com.google.mediapipe.tasks.text.textproofreader.TextProofreaderResult;

TextProofreaderOptions options = TextProofreaderOptions.builder()
    .setModelPath(context.getFilesDir() + "/proofread_quant_200m.litertlm")
    .build();

TextProofreader proofreader = TextProofreader.createFromOptions(context, options);

String inputText = "Their are severel typos in this sentance.";
TextProofreaderResult result = proofreader.proofread(inputText);
String correctedText = result.getProofreadText();

iOS

SwiftPMhttps://github.com/google-ai-edge/mediapipe → MediaPipeTasksTextPackage.swift·Sample code·Setup guide
import Foundation
import MediaPipeTasksText

guard let modelPath = Bundle.main.path(forResource: "proofread_quant_200m", ofType: "litertlm") else { return }

let options = TextProofreaderOptions()
options.baseOptions.modelAssetPath = modelPath

let textProofreader = try TextProofreader(options: options)

let inputText = "Their are severel typos in this sentance."
let result = try textProofreader.proofread(text: inputText)
let correctedText = result.proofreadText

Python

pippip install mediapipeSample code·Setup guide
import mediapipe as mp

BaseOptions = mp.tasks.BaseOptions
TextProofreader = mp.tasks.text.TextProofreader
TextProofreaderOptions = mp.tasks.text.TextProofreaderOptions

model_path = "proofread_quant_200m.litertlm"
options = TextProofreaderOptions(base_options=BaseOptions(model_asset_path=model_path), max_num_tokens=4096)

input_text = "Their are severel typos in this sentance."
with TextProofreader.create_from_options(options) as text_proofreader:
    result = text_proofreader.proofread(input_text)
    corrected_text = result.proofread_text

Task details

This section describes the capabilities, inputs, outputs, and configuration options of this task.

Features

  • Input text processing - Handles text pre-processing, including tokenization if needed.
  • Granular corrections - Provides a detailed breakdown of granular corrections, allowing you to identify which words were inserted, deleted, or left unchanged.
Inputs
Text Proofreader accepts the following input data type:
  • String
Outputs
The Text Proofreader outputs the following results:
  • String: represents the proofread result.
  • List of corrections: detailed breakdown of granular edits (insertions, deletions, or unchanged text segments).

Configuration options

This task has the following configuration options:

Android

Option Name Description Value Range Default Value
modelPath Path to the .litertlm model file in device storage (or use modelAssetFileDescriptor). String Required
maxNumTokens Optional limit on the maximum context length in tokens (maxTokens on iOS). If unset or 0, defaults to the model's built-in capacity (8192 tokens). Integer 0 (model default 8k)

iOS

Option Name Description Value Range Default Value
baseOptions.modelAssetPath Path or URL to the proofreader model (modelPath or modelAssetFileDescriptor on Android). String Required
maxTokens Optional limit on the maximum context length in tokens (maxTokens on iOS). If unset or 0, defaults to the model's built-in capacity (8192 tokens). Integer 0 (model default 8k)
cacheDirectory Optional writable directory for the model weight and program caches. Pass ":nocache" to disable caching. String Not set

Python

Option Name Description Value Range Default Value
base_options.model_asset_path Path or URL to the proofreader model (modelPath or modelAssetFileDescriptor on Android). String Required
max_num_tokens Optional limit on the maximum context length in tokens (maxTokens on iOS). If unset or 0, defaults to the model's built-in capacity (8192 tokens). Integer 0 (model default 8k)
cache_dir Optional writable directory for the model weight and program caches. Pass ":nocache" to disable caching. str ":nocache"

Task output

Each TextProofreaderResult returns the corrected text together with a granular diff of word-level edits:

Field Type Description
proofreadText string Complete proofread text with spelling, grammar, and stylistic corrections applied (proofread_text in Python).
corrections Correction[] Ordered list of diff segments (type: SAME, INSERTION, or DELETION; text: string) comparing the original input to proofreadText.

The following example shows the corrected string and granular edit segments returned for a sentence with typos:

{
  proofreadText: "There are several typos in this sentence.",
  corrections: [
    { type: "DELETION", text: "Their" },
    { type: "INSERTION", text: "There" },
    { type: "SAME", text: " are " },
    { type: "DELETION", text: "severel" },
    { type: "INSERTION", text: "several" },
    { type: "SAME", text: " typos in this " },
    { type: "DELETION", text: "sentance." },
    { type: "INSERTION", text: "sentence." }
  ]
}

Models

Text Proofreader pipeline overview

We offer a default, recommended model when you start developing with this task.

A lightweight 200M parameter model fine-tuned to identify spelling, grammatical, and stylistic errors in a text and generate a corrected version. This model is subject to the Gemma Terms of Use.

Model name Input Quantization type Terms of use Versions
Text Proofreader string Mixed Precision (Int4 + Int8) Gemma Latest

Task benchmarks

Here are the task benchmarks for the whole pipeline on a Pixel 10 Pro CPU. Peak memory usage for on-device model inference varies from approximately 200MB to 350MB depending on the input length (100 to 2000 words).

MediaPipe E2E Benchmark

Device Input Words (tokens) Prefill (tokens/s) Decode (tokens/s) E2E Latency (ms)
Pixel 10 Pro CPU 100 (~200 tokens) 1280 170 980
500 (~900 tokens) 1095 163 4,900
1000 (~1900 tokens) 1025 150 16,000
2000 (~3600 tokens) 980 140 28,000