Handwritten Chinese Sentence Recognition Using CNN-CTC
Where one character ends
The direct way to read a line of Chinese is to cut it into characters and classify each one. On handwriting, the cut is the hard part. Strokes of neighboring characters run into one another, spacing changes with the writer and with how much room is left at the end of the line, and a cut in the wrong place costs two characters rather than one. Every later stage inherits whatever the cut got wrong.
The recognizer I built in 2024 never makes that cut. A line of handwriting goes in and a string of characters comes out, and nothing in between has to decide where one character ends and the next begins.
An alignment nobody labels
Connectionist temporal classification, CTC, is what removes the cut. The network predicts a distribution over characters for every narrow frame of the image, and the label is only the string the line says. Nothing in the data tells which frames belong to which character, and I wanted a system that never needed to be told.
A blank symbol closes the gap. Any frame may emit blank, meaning that nothing ends there, so one label stands for a whole family of frame sequences: a character may stretch over a single frame or many, with blanks anywhere between. Collapsing repeated classes and then dropping the blanks maps every member of the family back to the same string. The loss is the probability of the whole family, summed over every path rather than over one chosen alignment, and a forward recursion computes it in linear time instead of enumerating paths that grow exponentially. Training needs only the line and its text; where the characters fall is something the model settles for itself.
Two consequences run through the rest of the design. There have to be more frames than characters, or no path exists at all. And the two decoding steps must happen in that order, because collapsing before dropping blanks is what lets a genuinely doubled character survive: the blank the network places between the two is the only thing keeping them apart.
A network that keeps the width
A stack of convolutional layers reads the line image, with batch normalization where the channel count jumps. The pooling is where the design sits. Early pools shrink the image in both directions; the late ones shrink only its height. Height is what the convolutions are meant to absorb into a feature vector, while width is time, and time has to survive, since the frames reaching the recurrent layers must comfortably outnumber the characters on the line.
Each column of the resulting feature map becomes one time step. Two bidirectional LSTM layers read that sequence in both directions, because what a stroke is often depends on what follows it as much as on what precedes it, and a linear layer gives every frame a score for each character and for blank.
Reading CASIA-HWDB
The data is CASIA-HWDB, which ships in two binary formats, and I wrote a reader for each. Isolated characters arrive as records that pair an encoded character tag with a raw bitmap; the reader walks them one by one, keeps the characters in the vocabulary, caps how many samples each character contributes so none dominates, and splits training from test the same way on every run. Sentences arrive as pen strokes with their text, and the reader draws them into a line image, scaling the whole line at once rather than each character, which keeps one writer's spacing and slant intact.
The vocabulary is a fixed list of a few hundred characters rather than the whole national character set. That keeps the output layer small and leaves each character enough samples to learn from at this scale of data.
Training and reading out
The network trains on the CTC loss and keeps the checkpoint with the lowest validation loss. Every line is padded to a common width, so only the lengths of the target strings vary within a batch. Reading out is greedy: take the best class at each frame, collapse the runs, drop the blanks, and the string is what remains.