314 points · by rrampage · 3y ago · 180 comments
It was actually a little depressing - it made me realize that some people just have a "something" that I'm not going to get through hard work or whatnot.
*edit: ah, found it. https://norvig.com/spell-correct.html
I had the same thought - read the URL and then said "Oh well that's Peter Norvig he's just weird in a cool way"
Until that day comes, I keep working at it.
So in this case, the special "something" he has is quite literally the amount of hard work he put in to learn this stuff. And if you take this opportunity to learn about edit distance, you'll be one step closer to that special someone you want to be.
"To deal with hyper-planes in a 14-dimensional space, visualize a 3-D space and say 'fourteen' to yourself very loudly. Everyone does it."
– Geoffrey Hinton, A geometrical view of perceptrons
Well, you actually can come up with Norvig's spellchecker very easily with a similar trick. Just tell yourself: to deal with a really hard problem, just argmax with an okayish heuristic. Everyone does it.
Solutions like this seem impossibly elegant because they tolerate a whole lot of error, but they are actually extremely obvious when you tolerate error.
[0] - https://web.archive.org/web/20070410053746/http://norvig.com...
[1] - https://web.archive.org/web/20150906100448/http://www.norvig... : ctrl+f "Update"
I'm sure there's better stuff now.
Also it's possible to better ranks candidates to fix typos by taking into account the layout of the keyboard (e.g. on a QWERTY keyboard is you see "wery" it is, despite having an edit distance of 1, highly unlikely the person typing meant to type "very". "weary" is much more likely). So just sorting by edit distance and then suggesting the most common word often doesn't result in the best candidate being shown first.
And then context. Ah, context. I type this and my browser isn't aware I'm talking about algorithms and not only says "metaphone" is incorrect but suggests "megaphone".
So... The matter still isn't settled if you ask me.
This code is very simple, very short, very unoptimized and done in a few hours, free solo. The kind of code the article could have linked as an example of how simple it is now to write a spellchecker, in fact it explicitly talks about how you can do it in a few lines of Python, i.e. this.
What the article is about is complex, highly optimized code that took months to do, because computers at the time didn't even have enough space to store the complete word list uncompressed, neither in storage nor in memory, and even with compression, you had to be clever.
One potential answer is indeed the recent developments in AI (generative stuff like GPT & stable diffusion etc).
That's kind of like watching someone use Red-Black Trees and assuming that they intuited them out of thin air. It's just remembering a basic algorithm that would be familiar to anyone in his particular field.
Because it's based on Wikipedia, it can correct proper names too. It's very extensible: by changing the error model, you can get fuzzy auto-complete that can look at "Shwarz" and suggest "Schwarzenegger" (even though you missed the 'c'). You can extend it to looking at multiple words instead of just letters, for correcting common word-use issues as well.
I recently realised I've been missing my "something" for a while.. ya I've not had a dopamine free moment since doom scrolling became a thing.
Not comparing somethings, I probably couldn't write a spell checker much less a beautiful one, but my creative juices are much less clogged up since allowing myself to get bored.
I believe it's being able to combine a learned skillset with raw creativity (boredom) that gives a person that something you refer to.
I often avoid things because I think they'll be hard, but then discover that they turn out to be easy. "Why didn't anyone tell me how easy this was! I could have done this ages ago!" was a running theme for me for a good while.
Of course, sometimes things are actually harder than you thought. But they're still doable! Whereas I have this cognitive bias where "difficult" is (emotionally) equivalent to "impossible", which is just really unfortunate. I'm sort of starting to see through that, that everything's made of atoms, and once you break a task down far enough, the individual steps are trivial.
So yes he's very talented, but if you study enough computer science, you can also do it. Or don't. It's totally fine to be interested in other parts of engineering instead.
The idea was to set up an auto-reply to my email that looked automated, but surely couldn't be because it messed up the sender's name. Not nearly as clever as Peter Norvig's program and even less useful.
I'd say the bias toward common American names is a bug, but given that the goal of the project is to be obnoxious it's probably a feature.
The hard part was fitting the dictionary in memory, and then searching all possible strings 1 and 2 edits away from the input to find the candidates.
The progress is that we don't have to care about storing 2.5MBytes (they ran on machines with 640k!) in RAM, or searching it 100,000 times (e.g. edits2('something')).
I challenge this, especially the "by definition" part. It depends on how many skills you recognize.
The chance of being the best artist (to the extent that such a statement is reasonable) might be one in eight billion.
The chance of being the best automotive sharpie artist is, similarly, one in eight billion.
The chance of being the best artist /of some particular skill set/ is, then, much higher -- if you recognize only a few thousand distinct skills here, you're already at one in a million.
Then realize that those who are likely to be surprised that there are better programmers than them are /not/ likely to be surprised that there are better artists than them. So we're assessing across all skills.
The chance of being on the far right of the bell curve of a specific skill is pretty small. The chance of being on the far right of the bell curve for /any/ skill is quite high, with only eight billion people around.
Find what you do better than anyone else, embrace it, and enjoy it.
Let's be real, in 5-6 hours he designed a very nice, simple algorithm to produce likely words from a dictionary based on frequency analysis, and produced 30 lines of Python code implementing it. A lot of engineers today could have done this.
The "specialness" was that he did it on his own time and enjoyed it.
There was an xkcd relevant here about enjoying Python: https://xkcd.com/353/
Complexity is the product of lesser stars in the firmament.
You can do similar things in domains where you’re so interested you can’t think of doing anything else.
Very few of us actually want to be the guy accumulating accolades for their engineering, we want to take flights to things we actually want to be doing, not opening our laptop once or even bringing it
Everything in between is a coping mechanism
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 your pleased two no It's letter perfect awl the weigh My chequer tolled me sew.
------
> Correct the spelling:
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 your pleased two no It's letter perfect awl the weigh My chequer tolled me sew.
> I have corrected the spelling errors in the poem:
"I have a spelling checker
It came with my PC
It plainly marks for my review
Mistakes I cannot see.
I strike a key and type a word
And wait for it to say
Whether I am wrong or right
It shows me straight away.
As soon as a mistake is made
It knows before too long
And I can put the error right
It's really ever wrong.
I have run this poem through it
I am sure you're pleased to know
It's letter perfect all the way
My checker told me so."
This means you had to store in a measly 64kb not only the code for the spell checker, the entire contents of the document, KERNAL overhead, and enough data for the spell checker to run. Remember that the Commodore 64 had an incredibly slow disk drive (300bps) and the disks only supported 160kb of data. Any scheme that required a lot of disk access would be terribly slow. Yet somehow it worked and wasn't outrageously slow. I suspect the program was unloading big chunks of its own program to aggressively reuse the memory space but even then it seems like magic.
[1] https://spectrumcomputing.co.uk/zxsr.php?id=4375
[2] 48k - 6.75k for the screen.
Way back when I wrote a DOS file manager that fit in 32K of assembly language. As I recall, at one point I upgraded it to use two different 64K segments when running by putting the code and in-memory information about the files in different segments.
Plus, few people had floor drives for the 100 —you had to operate from a cassette tape.
But then I found specs and its dictionary uses 384kB [1]. Then again it's from the latter 80s, maybe previous word processors attempted more constrained spellcheckers.
[1]: https://archive.org/details/kx-w1000-service-manual/KX-W1000...
typeaheads/autocomplete and spellchecking both need this so worth a read.
After months of setting up a new app, I've finally written a component in the past week. It's just a list item, icon, text and a chevron, but to get to that point took ages.
I just hope it was worth it. Probably not, I fully expect this code to be thrown away again in favor of whichever consultant comes next and/or because a designer says so within five years or so. At least I get paid monthly I guess.
A spellchecker used to be a major feat of software engineering (2008) - https://news.ycombinator.com/item?id=25296900 - Dec 2020 (143 comments)
A Spellchecker Used to Be a Major Feat of Software Engineering (2008) - https://news.ycombinator.com/item?id=10789019 - Dec 2015 (29 comments)
A Spellchecker Used to Be a Major Feat of Software Engineering - https://news.ycombinator.com/item?id=4640658 - Oct 2012 (70 comments)
A Spellchecker Used To Be A Major Feat of Software Engineering - https://news.ycombinator.com/item?id=3466388 - Jan 2012 (61 comments)
A Spellchecker Used to Be a Major Feat of Software Engineering - https://news.ycombinator.com/item?id=212221 - June 2008 (22 comments)
1980s memory models especially dos-era PC was a nightmare but you could at great effort work around it. The C / unix memory model is actually quite luxurious compared to programming on dos 3.3.
In the old days non-English support was pretty complicated. Now you rely on the OS to support UTF-8 and call it good, more or less. Was a bigger problem 'back in the day'.
In the old days you'd run a spell checker as a batch process, possibly not even part of the editor itself. The point I'm making is WRT speed, now a days speed doesn't matter, not because processors are faster (although they are, software always expands faster than hardware) but because we have integrated app with threading, so instead of saving this into a file, then exiting my browser and running a separate spell check app then exit and start the browser again and load this file back into it, the browser simply has a thread doing spell checking "on the fly". So in the old days it was VERY important WRT labor costs to spell check a 10000 word essay as fast as possible, and on a 8 mhz XT that was a trick indeed. But today my multi core multi ghz desktop merely needs to spell check on the fly as I'm typing and I can't be faster than 100 wpm or so. My desktop had "like one second or so" to decide that ghz and mhz are not words and put red squigglies under them whereas in the old days you'd have to spell check like 1000 words/second to keep the users happy.
So simple ineffective code survives in 2023 because it can lean on the OS, its not just that hardware is faster or larger.
I'd be so curious to hear what the change was. It's absolutely awful to use!
Now I couldn't tell you what it's doing, but it doesn't appear to be using history. For instance, the same technical terms get autocorrected again and again.
People regularly produce for fun what used to be a masters thesis level of work these days. I'll cite that YouTube video of someone making a reaction wheel system that can get an inverted Lego pendulum to stand up, and stay up under perturbations. The Lego part isn't the main work. The main work is software, a PID controller of the reaction wheel.
Something else has happened. There's enough people who know enough that the knowledge is just sloshing around, waiting for others to do cool things with it.
Fun part about this is that it might actually make it slower! Between cache misses, pre-fetchers and branch mispredictions the more naive search may make things significantly more predictable for the out of order execution on modern processors that the result is actually faster when you don't try to be clever with some of this.
You still have to benchmark and not do things completely wacky but it's kind of interesting how things have changed because of the scale of the pieces.
This does have me curious how big the ZDD for the dictionary would be. https://en.wikipedia.org/wiki/Zero-suppressed_decision_diagr...
Another example is the post on HN yesterday about old videogames and how they used a bunch of different hacks such as sprites and tiles because there wasn't enough memory for the whole screen. https://nicole.express/2023/yes-popeye-the-sailor-man.html
Even Grammarly can't write sentences for you as good as a native speaker. ChatGPT and language models can, but ironically, they still require way more memory than fits on a desktop. Simple cases like conjugation can certainly be handled but there is a lot of nuance to make a sentence "flow".
However usefully accurate LLMs are still too big to work locally in a laptop or PC, so once again we’re back to having to liberally apply black magic to squeeze the models into something an integrated GPU can run in its “tiny” VRAM that’s actually gigabytes in size.
The more things change, the more they stay the same.
PS: Spell check is a trivially solved problem for most languages, but not all! Hungarian is notoriously difficult, and there are ongoing projects to improve this: https://en.m.wikipedia.org/wiki/Hunspell
My KeenWrite editor, for instance, uses:
* https://github.com/DaveJarvis/KeenSpell (spell check, lexicon)
* https://github.com/DaveJarvis/KeenQuotes (curls straight quotes)
* https://github.com/DaveJarvis/KeenWrite/blob/main/R/pluraliz... (pluralization)
* https://lucene.apache.org/ (word segmentation)
I was looking at integrating LanguageTool[0] for grammar and realized that it has partial functionality for KeenQuotes (lexing and tokenization), duplicates the SymSpell algorithm used by KeenSpell, and because it offers grammar corrections it likely can pluralize words, as well.
Unifying those for English alone would be a massive undertaking. At present, KeenWrite parses prose in multiple, redundant passes. While this works, I think it'd be great to start with a basic lexer/tokenizer that can emit tokens at blazing speeds[1], which feeds into higher-level abstractions.
[0]: https://github.com/languagetool-org/languagetool
[1]: https://github.com/DaveJarvis/KeenQuotes/blob/main/src/main/...
I asked him afterwards how the guy got so rich and he told me that he wrote Microsoft's spellchecker.
Turbo Lighting, though, took advantage of the comparably large memory of the IBM PC to do something that really blew people away
https://books.google.com/books?id=MC8EAAAAMBAJ&pg=PA7&lpg=PA...
I don't know English well, but one single thing that immensely helps me memorizing English is instant feedback when I'm writing texts with errors. I bet that good spell checker in Chrome would do much more to the world than many English courses (also helps with any other language, of course, but English is special as it's world's lingua franca nowadays).
With the spellcheckers Google and Apple are using, it's rare that I can write a full paragraph of Finnish without them flagging something incorrectly. Whatever methods they are using, they seem to be incapable of handling cases, conjugation, and compound words. Which is ironic, since early Finnish spellcheckers were surprisingly good. There was a lot of research on those topics in Finland in the 80s and 90s, and early spellcheckers took advantage of that.
In it he demos the UI of a word processor of that era on a green screen monitor. As I had a CGA screen/PC at the time word processing was pretty novel to me ... in white and black, but most of my friends did not own computers and those that did had Commodore 64s[0].
[0] I sat jealous despite sitting before a $3,000 8088 w/FPU, 10MB HDD and 640k of RAM that took 2 minutes before it started booting from the hard drive (I learned to count in powers of two up to 640 that way).
> feet
Indeed.
https://atariemailarchive.org/thread/on-building-a-spellchec...
It's a game of problem whack-a-mole in this email thread!
One way to implement that is to store say a paragraph or more of your document at a time in RAM, then do a sequential read of the dictionary file on disk, compare to the stored paragraph words, and save any non-finds to the misspell report.
Saving the position could allow one to bring the editor back up and have the misspelled words highlighted, which is what WordStar did as I remember it.
We were all pretty amazed by it. He got some seed money to start a business and then was crushed like a year later when it was just built into wordstar.
It's probably easy mode compared with the original constraints in the article, but the problem is still somewhat challenging. It took me a sleepless night to get it right.
It really is mind blowing for those of us who remember spacer.gif and are still hacking today. The web has really grown up.
Anyone else remember Shift+F7? Bring out your Wordperfect templates.
I have always wondered if there is a way to recognize the word I am trying to spell by its shape (form) and length.