Post-Editing and Text Correction with Word Diffs
Annotators correct a machine translation, HTR line, or model answer in place, while Potato shows a word diff and saves word and character edit distances.
The text_edit scheme fills an editor with a text from the item, such as a machine translation or a recognized line of handwriting, and the annotator corrects the text in place. While the annotator types, Potato shows a word diff against the original and counts the edits in words and in characters. Each answer stores the corrected text, the original text, and both edit distances. The scheme suits machine translation post-editing, grammatical error correction, text simplification, and the correction of OCR or HTR output.
Post-editing is the human correction of a machine translation until the translation is acceptable. The Levenshtein distance between two sequences is the smallest number of insertions, deletions, and substitutions that turns one sequence into the other. Potato computes one Levenshtein distance over words and one over characters, and the two counts measure how much an annotator changed the original.
Configuration
The config below is Potato's machine translation post-editing example. The source sentence is the item text, and the machine translation sits in a separate mt_output field:
annotation_task_name: "Machine Translation Post-Editing"
task_dir: .
output_annotation_dir: annotation_output/text-edit/
export_annotation_format: jsonl
data_files:
- data/text-edit-example.json
item_properties:
id_key: id
text_key: text
user_config:
allow_all_users: true
users: []
annotation_schemes:
- annotation_type: text_edit
name: post_edit
description: "Edit the machine translation output to produce a fluent, accurate translation"
source_field: mt_output
show_diff: true
show_edit_distance: true
allow_reset: truetext_key names the field Potato shows as the item text, so the annotator reads the German or French source above the scheme. source_field names the field the editor starts from. Without source_field, or on an item that lacks the field, the editor and the "Original" block both start empty. The scheme then behaves as a plain text box whose distances count from an empty original. To correct the item text itself, set source_field to the same field as text_key, as Potato's HTR example does.
Options
text_edit option | Default | Meaning |
|---|---|---|
name | required | Scheme name, also the key of the stored answer |
description | required | The instruction shown above the editor |
source_field | "" | The item field whose text fills the editor and the "Original" block |
show_diff | true | Show the word diff under the editor |
show_edit_distance | true | Show the "Words changed" and "Chars changed" counters |
allow_reset | true | Show the "Reset to Original" button |
show_diff and show_edit_distance change only what the annotator sees. Potato computes and stores both edit distances whatever the two settings say. Turning both displays off suits a study of editing effort in which the counters could push annotators toward fewer changes.
Data format
Each item carries the text to edit in the field that source_field names. The example's data file holds one JSON object per line:
{"id": "te001", "text": "Source (German): Die Regierung hat gestern ein neues Gesetz zur Regulierung der Internetkonzerne verabschiedet.", "mt_output": "The government has yesterday a new law for the regulation of the internet corporations passed."}
{"id": "te005", "text": "Source (Portuguese): A empresa anunciou que vai investir dois bilhoes de dolares em energia renovavel nos proximos cinco anos.", "mt_output": "The company announced that will invest two billions of dollars in renewable energy in the next five years."}The annotation page
The scheme's description heads five parts. "Original" shows the source_field text on a shaded background, and the annotator cannot edit the block. The five-row box under "Edit below" starts with the same text. "Words changed" and "Chars changed" count the edits, and "Changes" shows the edited text as a word diff, with deleted words struck through in red and inserted words in green. "Reset to Original" puts the original text back in the editor.
The counters and the diff update on every change to the editor, and both stay at 0 and empty until the first change. Reopening a saved item restores the saved text into the editor and recomputes the diff and the counters.
Word and character edit distances
The browser computes two Levenshtein distances between the original and the edited text on every change:
- Words changed is the Levenshtein distance between the two texts split on whitespace. Two words match only when the words are identical, so a change of case or of attached punctuation counts as a substitution, and
mat.andmatare different words. - Chars changed is the Levenshtein distance between the two full strings, with spaces, line breaks, and case counted.
Correcting the example's te005 item shows the two counts side by side. The machine translation reads "The company announced that will invest two billions of dollars in renewable energy in the next five years." An annotator who writes "The company announced that it will invest two billion dollars in renewable energy over the next five years." makes four word edits. The four are inserting it, replacing billions with billion, deleting of, and replacing in with over. The same correction is 11 character edits.
Both counts are raw edit counts with no division by length. Neither count is the translation edit rate (TER) of machine translation evaluation. TER divides the edit count by the reference length and counts the move of a whole word sequence as one shift. HTER is TER measured against a human post-edit of the same output. Moving "yesterday" from the end of "the government passed a new law yesterday" to the front costs 2 in Words changed, as one deletion and one insertion, and 20 in Chars changed, where TER counts one shift. To report TER or HTER, compute the metric from the stored original_text and edited_text with a TER implementation such as sacreBLEU, whose README lists TER (checked on 2026-11-28).
The diff aligns the two word sequences by their longest common subsequence. A replaced word appears as the struck-out old word followed by the new word. A one-character fix inside a word, such as sit to sits, still strikes out the whole word, and Chars changed gives the character count for such a fix.
Stored answer
Each text_edit answer is a JSON string with four fields:
{"edited_text":"The cat sits on the mat.","original_text":"The cat sit on the mat.","edit_distance_chars":1,"edit_distance_words":1}Potato stores the string under a label with the scheme's own name. In the jsonl export, the answer above sits at record["labels"]["post_edit"]["post_edit"], and a script reads the four fields with json.loads. Answers saved by older versions of Potato can hold the plain edited text instead of the JSON string, and Potato reads both shapes when an item is reopened.
Pressing Next on an item whose editor still shows the original text saves the item as accepted, with edited_text equal to original_text and both distances at 0. An item nobody reached has no answer, so the export tells an accepted item from an unopened one. Potato added the accepted-unchanged save in version 2.13.1. Before 2.13.1, an untouched item saved nothing until the text changed or "Reset to Original" ran.
For projects made with potato import -f page_xml, the page_xml export writes each edited_text back into the matching TextLine of the project's copy of the PAGE file. PAGE XML and HTR line correction covers the import and the export.
Agreement
Potato's agreement report at /admin/iaa leaves text_edit schemes out, as the report does for free-text text schemes. Potato treats free text as having no defined agreement between two annotators, because two correct corrections can differ in wording. To compare annotators, give each item to two or more annotators with num_annotators_per_item, then compute a distance between the annotators' edited_text values outside Potato. Character error rate and TER of one annotator's text against the other's are both common choices. Correct HTR Output Line by Line runs the character error rate comparison on 88 lines from two transcribers.
Keystroke logging in the editor
With keystroke_logging.enabled: true, Potato logs typing in the text_edit editor as in any other free-text field. The editor carries no schema attribute, and the tracker takes the scheme name from the surrounding form. Sessions for the example's editor are keyed post_edit:::post_edit-editor.
Potato writes the original text into the editor before the annotator focuses the editor, and the pre-filled text fires no input events. The event stream therefore records only the annotator's own insertions, deletions, and pastes, and keystrokes, chars_inserted, chars_deleted, and the paste counts measure the annotator's work. The character counts are net length changes per event, so replacing a selection undercounts. Typing one letter over a selected three-letter word logs two characters deleted and none inserted, and pasting four characters over a three-character selection logs one pasted character. Post-editors often select a word and retype it, so read the counts as a lower bound. Two summary features read differently on a pre-filled editor. pasted_fraction divides the pasted characters by the whole final text, the original included. non_terminal_edits counts an edit as a revision only when the edit falls before a running length that starts at 0, so most edits inside the original text are not counted as revisions.
To leave the editor out of the logs, add the scheme's name to exclude_schemas. Add this block to the config above:
keystroke_logging:
enabled: true
exclude_schemas: [post_edit]Keystroke Logging lists every summary feature, and Writing-Process Detection describes the flags built on the features.
text_edit beside text and error_span
The three schemes record different things about a text:
| Task | Scheme | What the answer holds |
|---|---|---|
| Correct an existing text and measure the change | text_edit | The corrected text, the original, and two edit distances |
| Write a new text with no starting text, such as an explanation or a translation from scratch | text | The typed string |
| Mark and classify the errors in a text without fixing the errors | error_span | Error spans with a type, a severity, and a quality score |
A text box can collect a correction, as in the text correction example. The box starts empty, and the annotator retypes the whole text. Potato saves the typed string with no distance to the original. error_span and text_edit answer different questions about the same output. An MQM study that needs error categories and a corrected reference puts an error_span scheme and a text_edit scheme on the same item, with the same source_field in both.
Examples
Potato's release has two text_edit projects, and each runs from the root of a Potato checkout. The machine translation example from the configuration above holds five sentences from German, French, Spanish, Japanese, and Portuguese:
python potato/flask_server.py start examples/classification/text-edit/config.yaml -p 8000The HTR example shows each handwritten line cropped from the page image with the image_region display, and the editor starts from the recognized text:
python potato/flask_server.py start examples/text/htr-line-correction/config.yaml -p 8000Limits
- Whole-word diff. "Changes" marks whole words, and only "Chars changed" shows the size of a fix inside a word.
- No shifts and no rates. Both distances are Levenshtein counts, and a moved phrase costs one deletion and one insertion per word. Compute TER or a length-normalized rate from the stored texts.
- No agreement coefficient. The agreement report skips
text_edit, and annotators are compared outside Potato. - One text per scheme. Each scheme edits one field. Put two
text_editschemes on the page to edit two fields of the same item.
Further reading
- Error Span - MQM error categories and severities on the same output
- Text and Number Input - Free-text answers with no starting text
- Correct HTR Output Line by Line - PAGE XML import,
text_editcorrection, and character error rate - Digital Humanities Annotation - PAGE XML lines in a
text_editscheme - Trajectory Correction - Corrected agent steps with the same word diff
- Keystroke Logging - Typing dynamics for free-text fields
- Inter-Annotator Agreement - Coefficients for the schemes the agreement report scores
References
- Snover, M., Dorr, B., Schwartz, R., Micciulla, L., and Makhoul, J. (2006). A Study of Translation Edit Rate with Targeted Human Annotation. Proceedings of the 7th Conference of the Association for Machine Translation in the Americas, 223-231. https://aclanthology.org/2006.amta-papers.25/
For implementation details, see the source documentation.