Let's take a look at what happens inside the "black box" of the neural network in a text recognition system
The performance of modern text recognition systems implemented using neural networks is impressive. They can be trained on medieval documents and read them with very few errors. This task is extremely difficult for most of us. Take a look at Figure 2 and give it a try!
Figure 2: Difficult for most people to read, but easy for a text recognition system trained on this dataset.
How do these systems work? How do they recognize text by looking at different parts of an image? Do they utilize clever patterns or shortcuts specific to the dataset? In the following article, we will explore two experiments to gain a better understanding of what happens inside such a neural network.
Experiment 1: Pixel Relevance
In our first experiment, we ask the following question: Given an input image and the correct class (ground-truth text), which pixels in the input image support the correct text and which pixels oppose it?
We can calculate the influence of individual pixels on the result by comparing the scores of the correct class in two scenarios:
1. When the pixel is included in the image.
2. When the pixel is excluded from the image (by marginalizing all possible grayscale values of that pixel).
By comparing these two scores, we can determine whether a pixel supports or opposes the correct class. Figure 3 shows the pixel relevance to the ground-truth text "are" in the image. Red pixels vote in favor of the text, while blue pixels vote against it.
Figure 3: Top: Input image. Bottom: Pixel relevance and blended input image. Red pixels vote in favor, while blue pixels vote against the correct text "are".
Now, let's examine some key regions (deep red and deep blue) to understand which image features are crucial for the neural network to make decisions:
1. The red region above the "a" is white in the input image and is crucial for the correct result "are". If a black dot appears on the vertical line of the "a", it can be interpreted as an "i".
2. The connection between "r" and "e" confuses the neural network with the blue region. Disconnecting these two characters should increase the score for "are".
3. The gray pixels inside the "a" (bottom left) slightly oppose "are". If the hole inside the "a" were completely white, it would increase the score.
4. The top right region of the image is an important area for correct voting. It is still unclear how to interpret this region.
Let's investigate hypotheses 1-3 and clarify their meanings. For hypothesis 4, we will change some pixel values in these regions. Figure 4 shows the original and modified images, the scores for the correct text, and the recognized text. The first row displays the original image with a score of 0.87 for the text "are".
1. Drawing a dot on the vertical line of the "a" decreases the score for "are" by a factor of 10, resulting in the recognized text "aive". Therefore, the neural network heavily relies on superscripts to determine whether a vertical line is an "i" or something else.
2. Removing the connection between "r" and "e" increases the score to 96. Even though the neural network can implicitly segment characters, disconnected characters seem to simplify the task.
3. The hole inside the "a" is important for detecting the "a". Swapping the gray pixels with white pixels increases the score to 88.
4. Drawing some gray pixels in the top right corner of the image causes the system to recognize "ane" and decreases the score for "are" to 13. In this case, the system has apparently learned features unrelated to the text.
Figure 4: Changing pixels in key regions and observing the effects.
In summary, our first experiment shows that the system learns meaningful text features, such as recognizing superscripts for the character "i". However, it also learns meaningless features to us. Nevertheless, these features still help the system recognize text in the dataset it was trained on. These features allow the system to take shortcuts instead of learning true text features.
Experiment 2: Translation Invariance
Translation-invariant text recognition systems can correctly recognize text regardless of its position in the image. Figure 5 shows three different horizontal translations of the text. We expect the neural network to recognize all three positions of the word "to".
Figure 5: Three horizontal translations of the text.
Let's revisit the image from the first experiment, which contains the text "are". We will move it pixel by pixel to the right and observe the scores for the correct class and the predicted text, as shown in Figure 6.
Figure 6: Scores for the text "are" as the image is translated pixel by pixel to the right. The x-axis labels indicate the number of pixels the image has been moved and the recognizable text (using the best path decoding).
It can be observed that the system is not translation-invariant. The score for the original image is 0.87. Moving the image one pixel to the right decreases the score to 0.53. Moving it one more pixel to the right reduces the score to 0.28. The neural network can recognize the correct text until a translation of four pixels. After that, the system occasionally outputs incorrect results, starting with "aare" five pixels from the right.
The neural network was trained on the IAM dataset, where all words are left-aligned. Therefore, the system has never learned how to handle images with whitespace on the left. Ignoring whitespace may seem obvious to us, but it is a skill that needs to be learned. If the system has never been forced to deal with such cases, why would it learn it?
Another interesting feature of the score function is the periodicity of four pixels. These four pixels correspond to the reduction factor of the convolutional network, from a width of 128 pixels to a sequence length of 32 pixels. Further investigation is needed to explain this behavior, but it may be due to the discontinuity of pooling layers: when a pixel is moved one position to the right, it may either stay in the same pool cluster or step into the next one, depending on its position.
Conclusion
Text recognition systems learn anything that helps improve the accuracy on their trained dataset. If random pixels contribute to recognizing the correct class, the system will use them. If the system only needs to handle left-aligned text, it will not learn any other type of alignment. Sometimes, it learns features that we humans consider useful for reading, which can be generalized as broad text styles. However, it also learns shortcuts that are only useful for a specific dataset.
We need to provide different data (e.g., mixing multiple datasets or using data augmentation) to ensure that the system truly learns text features instead of just tricks.
References:
- Article on text recognition models: [link](https://towardsdatascience.com/build-a-handwritten-text-recognition-system-using-tensorflow-2326a3487cd5)
- Text recognition model code: [link](https://github.com/githubharald/SimpleHTR)
Original article link: [link](https://towardsdatascience.com/what-a-text-recognition-system-actually-sees-6c04864b8a98)
Alphabet Q1 paid subscribers reached 350M, fueled by YouTube & Google One. YouTube ad revenue slightly missed at $9.88B amid Premium growth. Total Q1 revenue hit $109.9B, beating forecasts.
Anthropic releases Claude connectors for Adobe, Blender, and Ableton, enabling AI workflow automation and app control. It also sponsors the Blender Development Foundation.
Apple introduces an App Store model splitting 12-month plans into monthly installments. On iOS 26.4+, it lowers upfront costs without reducing total price, adding billing tracking.
Google launches Aadhaar digital IDs in Wallet for India, enabling secure QR/NFC verification. A phased partner rollout targets key sectors, while passport-based credentials expand globally.
YouTube tests "Ask YouTube," an AI tool blending text and video for complex queries. Initially for US Premium users, it supports interactive follow-ups, expanding Google's AI search.
Google grants US DoD classified AI access, joining OpenAI and xAI in defense deals amid Anthropic's dispute. Contractual safeguards against surveillance and lethal weapons remain unenforceable.
Mistral AI launches Workflows, a Temporal-powered orchestration platform for secure, Python-driven enterprise AI automation featuring human-in-the-loop approvals.