Furigana in go: The Right Reading Over the Right Kanji
Small kana over a kanji tell a learner how to say it.
By Daniel Chiwuzoh ·
Open a hymn book in almost any church and look under the music. The words aren't printed as normal sentences. They're chopped into syllables, with little hyphens between them, and each syllable sits under exactly one note: Hal-le-lu-jah, four syllables, four notes. Nobody thinks about it, because when it's done right you just sing.
Now imagine the printer slips by one. Hal sits under the second note, le under the third, and by the end of the line the congregation is either rushing to catch up or holding a note that has no word left. Every word is spelled correctly. Every note is right. The line is still wrong, because the words and the notes no longer line up.
That's the problem this article is about. In go (the language app I'm building, named for 語, the suffix that means "language"), every Japanese sentence carries small readings above its harder characters, and each reading has to sit over the right one. It took four rounds of fixes to get right, and every round started with something wrong on screen.
What furigana is
Japanese is written with three scripts at once. There are two sets of kana, hiragana (ひらがな) and katakana (カタカナ), where each character stands for a sound, like letters do. And there are kanji, the characters borrowed from Chinese, where each one carries a meaning and, annoyingly, several possible pronunciations.

Take 食べる (taberu, to eat). The 食 is a kanji; べる is hiragana. If you've never met 食, you can't say the word. So Japanese books for children and learners print small kana above the kanji to tell you how it's read:
た
食べるThose small kana are called furigana. The web has a tag for exactly this, <ruby>, which puts the reading above the text, and go uses it everywhere.
Here's the catch. You can't look up each kanji and print its reading, because a kanji's reading depends on the word it's in. 日 (sun, day) is にち in 日曜日 (nichiyoubi, Sunday) and ひ on its own, and in 明日 (ashita, tomorrow) the two kanji together read あした with no way to say which part belongs to which. The code's own example is 大人 (otona, adult): おとな doesn't divide across 大 and 人 at all, and a guess would put と over 大, in front of someone trying to learn the word.
So readings belong to words, and the hard part is cutting a sentence's reading into the right piece for each word.
Five ways to read a line
Before the plumbing, what the learner sees. Every line in the app follows one setting, with five choices:
Always: readings over every kanji.
Unknown: readings only over kanji you haven't learned yet.
Never: no readings. What reading practice actually needs.
Hiragana: kanji written out in kana, so every line is hiragana reading practice.
Romaji: readings in latin letters, over every kanji and every kana.
Since mid-October, new learners start in Hiragana mode. The setting lives in the database and each user can configure it for themselves.

Every one of those modes leans on the same cut, and Hiragana is the least forgiving: it replaces each kanji with its reading, so a reading on the wrong word doesn't just sit in the wrong place, it prints the wrong text.
Where the readings come from
Lines arrive in two shapes.
Imported sentences (from Tatoeba, an open collection of example sentences) are cut into words at import (the code calls this tokenising), and each word's furigana is aligned then and stored.
Authored lines (lesson examples, conversations, Speak, the read-aloud speeches) are different. They come with one reading for the whole line, written in kana with spaces between the words. 母は先生です。 (haha wa sensei desu, my mother is a teacher) is authored as:
はは わ せんせい です。Notice the わ. The particle は is spoken wa, so the reading writes it the way it sounds. Hold on to that, because it caused the first bug.
For these lines the whole-line reading is what's stored, and the cut into words happens on the server when the line is served, by the same function every page uses. The browser never guesses where ruby goes; it receives each word already carrying its furigana.
How you line a reading up
The basic method is anchoring. Kana in the written word must appear literally in the reading, and that pins the boundaries down. In 食べる / たべる, the べる is kana, so it must match the end of たべる; whatever is left, た, belongs to 食. The kana are the bar lines in the hymn book: they tell you where each stretch starts and stops.
It works until a kana appears more than once, or until the reading says something differently from how it's written. Both happened.
Bug one: 母 read は
The first serious bug came from a verification pass over new content. 母 (haha, mother) was annotated は, just the first character of はは, and 先生 (sensei, teacher) got " わ せんせい". It was already live in the lesson example sentences.
Wrong furigana is worse than none: it teaches a misreading with the authority of an answer.
There were two causes. The first was that particle わ. The code that cut the reading turned は into わ on both sides, the written text and the reading. The text needs that (the written は is spoken わ), but the reading is already spoken, so the only は it can meet is one inside a word, like はは. Turning that into わわ meant the anchor わ matched at the first character instead of the third, and every word whose reading contains は, を or へ got cut short.

The second cause: ruby was taken from a per-character reading that exists to space out romaji. Inside a run of kanji, that one deliberately puts the whole run's reading on the first character, which is fine for romaji and wrong for ruby: 毎朝早く (maiasa hayaku, early every morning) came back with 毎朝 annotated まいあさ はや. The fix preferred the dictionary reading, fell back to the sentence's cut for words whose ending changes (the dictionary knows 行く, iku, to go; only the sentence knows this one says 行きます), and showed no reading at all when neither lined up.
Bug two: fixing one sentence and breaking 528
The fix for bug one stopped normalising the reading side. That's only right for the authored format. A cloze card (a sentence with a blank to fill) rebuilds its reading from furigana and keeps the particle は as は, so the next verification pass found that the fix had repaired one sentence and broken 528: 520 lines across dialogues and cloze prompts lost their alignment entirely, and 8 came back actively wrong, with 私 (watashi, I) read たし and 教えて (oshiete, tell me) read しえて.
Trading one wrong sentence for eight newly wrong ones is not a fix.
The real fix was the spaces. はは わ せんせい です。 says exactly where はは ends, which is better information than any guess. So a match that starts at a word boundary now beat an earlier one that didn't, but only as a preference. If that walk failed, the original walk ran, so a line could gain a better cut and never lose the one it had.
The bigger change was how it was checked. Instead of trusting a handful of examples, the new version was run against the old one over all 6,677 lines in the database that carry a reading. 18 lines changed, none lost alignment, and every one was a repair: 昨日 (kinou, yesterday) had been annotated き, 電話 (denwa, telephone) had been でん. From then on, every change to the cut was measured across everything before it went in.
I hope you are still with me, because the next one is the strangest.
Bug three: 猫がいます in five pieces
Writing the examples for the lesson on あります and います (arimasu and imasu, both "there is"; います for living things) turned out to be impossible. 猫がいます。 (neko ga imasu, there's a cat) came apart into 猫 | が | い | ま | す. You can't write a lesson around a word the app won't keep in one piece 😅
Two sensible rules met in the wrong place. The dictionary (JMdict, the open Japanese dictionary the app is built on) writes いる with the kanji 居る, but tags that spelling rK, rare kanji, so that row was dropped. Its kana form いる was then refused by a different rule, "only conjugate the main spelling", which exists to stop odd spellings producing forms nobody writes. Between them, いる conjugated from neither spelling, and います matched nothing at all.

The fix leaned on JMdict's own marker: a word tagged uk ("usually written in kana") gets its kana spelling conjugated, because that's exactly the spelling people do write. Measured over the same 6,677 lines: 1,564 changed, 868 had fewer runs of shredded single kana, none lost alignment, and exactly one got marginally worse (いただきたい, garbled either way). わかりました, あります, いません and します had all been spelled out one kana at a time across the dialogues.
A smaller bug turned up next to it. A word with no kanji was taking its dictionary reading, which is the plain form: あります was stored as reading ある, and います as いる. You'd never see it as ruby, because nothing draws ruby over kana, but that reading feeds romaji and the answers dictation accepts. Now a word with no kanji reads as itself.
Bug four: じかんえいご英語
In October, when Hiragana became the default mode, a new kind of bug became visible. In Hiragana mode each word's kanji is replaced by its reading. Take 毎日三時間英語を勉強します (mainichi sanjikan eigo o benkyou shimasu, I study English for three hours every day). Inside it, 時間 (jikan, hours) and 英語 (eigo, English) are two words that sit side by side as one unbroken run of kanji, and the anchor walk has no kana in the middle to cut at. So the whole reading じかんえいご landed on 時間, and 英語 got nothing. Replace, print, and the learner saw:
じかんえいご英語
The first fix was a small patch: take the words after the first from the end of the run's reading, using their dictionary readings, and give the first word what's left. Nine minutes later, another one: 今起きた (ima okita, just woke up) read いまお + きた, because the patch gave 今 the お of 起きた. The second patch gave a word ending a run the front of its reading back, and was checked across every published sentence: two-word kanji runs read right in 71 of 77, up from 17.
71 of 77 is better. It also left six still wrong, and each patch so far had fixed one shape and exposed another.
One aligner for every line
So within the hour the patches were deleted and replaced with one function used for every line the app shows. It takes the words, the line's reading and the dictionary, and it no longer makes one left-to-right guess.
For imported sentences that already carry aligned furigana, it uses that alignment as it stands. Nothing is re-guessed.
For authored readings, it finds every way the reading could line up with the text and picks the one that agrees best with the dictionary and with the author's own spaces. Each piece of the line gets a score, and the rules are written in the code:
* - +2 a run reads as the dictionary has that word (−1 if it does not);
* - −1 an author's space that falls inside a word;
* − 2 a word's own reading with a space in it;
* − 4 は read わ (を お, へ え) anywhere but the end of a word, where particles go;
* +1 a run across words split cleanly; −3 one that can only be shown whole.Read that −4 again. It's bug one, written as a rule: は may be read わ only where a particle can go, at the end of a word, and an alignment that reads it わ anywhere else pays a heavy price. The search can still pick it if nothing else fits, but it won't pick it by accident.
Trying every alignment sounds slow, but the score of each piece depends only on that piece. So the search walks (position in the text, position in the reading) and remembers the best way to finish the line from each point. It's the trick for finding the cheapest route on a map without trying every road: once you know the best way home from a junction, you never work it out again.
Two more decisions in it are worth naming.
When a reading can't be divided, the words are shown as one. If a run of kanji spans two words and neither the author's spaces nor the dictionary says exactly where the reading splits. The test for it uses 山本 (yamamoto, a surname), which the tokeniser splits into 山 and 本: the result is one word, 山本, read やまもと. No word is ever shown with a piece of its neighbour's reading.
The author's spaces don't always win. 十二日 (juuninichi, the 12th) authored as じゅうに にち has two spaced words over the tokens 十 and 二日. Following the spaces would read 二日 as にち, which the dictionary contradicts, so the spaces are ignored and the run is shown as one. And 時間英語 reads じかん + えいご.
Kana are never rewritten. A kana word is shown as written, katakana stays katakana, and the particle は stays は on the page even though its reading underneath is わ. Only kanji (and numerals, and ヶ as in 一ヶ月) get readings.
A checker that reads everything
The aligner came with a checker. It reads what's actually in the database (conversations, Speak, the read-aloud speeches, grammar examples, example sentences on word pages and every cloze card's sentence) and cuts each line with the same function the pages use. Then it reports two numbers per surface:
broken: a word with kanji and no reading, or a reading that doesn't fit the line at all. These must be zero, and the script exits with a failure if they aren't.
differs: a word whose reading isn't the dictionary's. Often that's right (今日 can be こんにち as well as きょう), sometimes it's an authoring or import mistake, so these are listed for a person to look at.
Corrections go through the review queue
"Differs" is where the last piece comes in. The Tatoeba sentences got their readings from a tokeniser at import, and a tokeniser can be confidently wrong. So a first reviewer read all 1,826 of them in context and proposed fixes, and a second, independent reviewer confirmed each one. That produced 110 sentences that needed a change: 五時 (goji, five o'clock) read ごとき, 来た (kita, came) read くた, 来て下さい (kite kudasai, please come) with 来 read く instead of き, and 22 names that had no reading at all. The conversation checker also found five lines whose reading didn't say what the line said: お使いください read as つかって ください, a reply missing ごめん, a stray よ.
The tempting move is to write those fixes straight into the database. go doesn't. Nothing AI-generated reaches a learner unreviewed, and a correction to something already live is no exception. So these became a new kind of item in the admin review queue, a correction, shown to the reviewer as now versus proposed, with readings over every kanji whatever the reviewer's own setting, and the reason for each change written out (te-form of 来る is きて).
Approving one applies it, and a reading doesn't live in one place. A sentence's readings sit on its tokens, but each cloze card cut from that sentence keeps its own copy of the furigana, split at the blank, and the reading of the blank is one of the card's accepted answers. A conversation line's reading is copied into the study queue's own copy of that conversation. Fix the source and not the copies, and the wrong reading stays on screen. So approval rebuilds every copy from the corrected source and guards each change by the value it replaces:
Back to the hymn book
A printed hymn has two jobs that look like one: the right words, and each syllable under the right note. Furigana is the same. The reading can be correct and still teach the wrong thing if it sits over the wrong kanji, and in Hiragana mode a reading on the wrong word prints the wrong sentence.
What holds it together now is one aligner for every line, a checker that reads every line the app serves and must find zero broken, and a queue where any correction to something live waits for a person to say yes.
So they read in the book in the law of God distinctly, and gave the sense, and caused them to understand the reading. - Nehemiah 8:8