All labs Animated labs The chapter Course home

Lab 11Edit distance, one cell at a time

How many single-letter edits turn one word into another? Each cell of the table answers that for a pair of prefixes, using only the three cells next to it. Type two words, press Play, and watch the table fill. When it is full, the trace-back reads the cheapest edits off the table. The method and numbers are those of edit_distance.py, so they match the chapter.

Try:
Cell 0

What to look for

  • Cat to cart takes one edit, an insertion of r. The cheapest path runs down the diagonal while letters match and steps sideways exactly once.
  • Sunday to saturday takes three: insert a, insert t, and substitute n for r.
  • Set the substitution penalty to 2 and run cat to cut. The answer becomes 2, because a substitution now costs the same as a deletion plus an insertion. Jurafsky and Martin use that convention.
  • Raise the insertion penalty on its own and watch the cheapest path avoid insertions where it can, even if that means more edits in total.

Where this fits

This is the edit distance section of Corpora and Preprocessing. Run edit_distance.py to print the same tables as text.