Live data from Hacker News

How to Write a Spelling Corrector

norvig.com

71–80 of 133 posts

Re: How to Write a Spelling Corrector

#71
post #53
post #21

Earlier quoted context omitted.

What is the application where typos in a document are acceptable?

Classified reports. This technique is called the Canary Trap, with the name (but not the technique) coined by Tom Clancy. https://en.wikipedia.org/wiki/Canary_trap

For that purpose you'd want to add typos that would be "corrected" into the wrong word by a typical spellchecker or that are actually correct, but atypical in context, words. Otherwise passing the document through a spellchecker would remove the watermark.

Re: How to Write a Spelling Corrector

#72
post #65

I couldn't help but read this and think about all the "coding" initiatives I've seen in K-12 and shake my head. What Norvig is doing is what we should be teaching. He is tackling this seemingly REALLY hard problem by thinking about it methodically, translating some intuition into code, carefully constructing an argument about how to solve it, and ways that it could be extended. This is what actual engineers look like…

By that reasoning, we should not teach kids how to spell, or about punctuation, and just aim for them writing essays/stories/novels.

The commenter right above you expressed the same issue, and I wrote a longer reply there. But it's not that I don't think syntax is important, but I don't think we should pretend that the value in learning to code is learning the syntax. What I'm reacting to is "coding" programs that seem to eradicate any semblance of forcing kids to confront hard problems in favor of presenting them with trivial exercises for the sole purpose s of claiming "they can code."

Re: How to Write a Spelling Corrector

#73
post #44

Earlier quoted context omitted.

You can also use the set-comprehension syntax, which functions equivalently but looks slightly nicer: return {w for w in words if w in WORDS} could have also directly used the intersection operator on the sets: return words & WORDS or slightly more verbose, but maybe more clear for colleagues who don't regularly use sets in Python: return words.intersection(WORDS)

> return words & WORDS Not quite. It'd have to be set(WORDS) instead of WORDS -- which'd be expensive. Or WORDS.keys(), which I'm not sure about -- I'd have to benchmark it.

I wouldn't worry about the expense of set construction vs the expense of an n-squared algorithm.

Re: How to Write a Spelling Corrector

#74
post #39
post #34

Earlier quoted context omitted.

What is wrong with his docstrings?

Nothing's wrong with them. Though it is more usual to use triple quotes for docstrings even if they fit on one line (see PEP 257, "Triple quotes are used even though the string fits on one line. This makes it easy to later expand it.").

Easy in the sense of more pleasant version control diffs.

Re: How to Write a Spelling Corrector

#76
post #3

Spell chequer Martha Snow Eye halve a spelling chequer It came with my pea sea It plainly marques four my revue Miss steaks eye kin knot sea. Eye strike a quay and type a word And weight four it two say Weather eye am wrong oar write It shows me strait a weigh. As soon as a mist ache is maid It nose bee fore two long And eye can put the error rite It's rare lea ever wrong. Eye have run this poem threw it I am shore y…

That poem could've been written about speech recognition software as well.

Re: How to Write a Spelling Corrector

#77
Is this how modern spell checkers actually work? I assumed they would use a heuristic trying to match common misspellings to their frequent corrections. That or a combination of heuristic and Bayes.

Re: How to Write a Spelling Corrector

#78
post #71
post #53

Earlier quoted context omitted.

Classified reports. This technique is called the Canary Trap, with the name (but not the technique) coined by Tom Clancy. https://en.wikipedia.org/wiki/Canary_trap

For that purpose you'd want to add typos that would be "corrected" into the wrong word by a typical spellchecker or that are actually correct, but atypical in context, words. Otherwise passing the document through a spellchecker would remove the watermark.

Heh, perhaps an easier way would be to have unique phrases in each document. Typos risk exposing you because they will stand out to the person who is reading the document - assuming such a person is more discerning than most, given that they're accessing classified docs.

Re: How to Write a Spelling Corrector

#79
post #44

Earlier quoted context omitted.

You can also use the set-comprehension syntax, which functions equivalently but looks slightly nicer: return {w for w in words if w in WORDS} could have also directly used the intersection operator on the sets: return words & WORDS or slightly more verbose, but maybe more clear for colleagues who don't regularly use sets in Python: return words.intersection(WORDS)

> return words & WORDS Not quite. It'd have to be set(WORDS) instead of WORDS -- which'd be expensive. Or WORDS.keys(), which I'm not sure about -- I'd have to benchmark it.

[deleted]

Re: How to Write a Spelling Corrector

#80
post #44

Earlier quoted context omitted.

You can also use the set-comprehension syntax, which functions equivalently but looks slightly nicer: return {w for w in words if w in WORDS} could have also directly used the intersection operator on the sets: return words & WORDS or slightly more verbose, but maybe more clear for colleagues who don't regularly use sets in Python: return words.intersection(WORDS)

> return words & WORDS Not quite. It'd have to be set(WORDS) instead of WORDS -- which'd be expensive. Or WORDS.keys(), which I'm not sure about -- I'd have to benchmark it.

You would only need to do set(WORDS) once at the beginning of the program, so its amortized cost is low.
Post reply on HN