Monthly Archives: July 2023

Navigating the Challenges of OCR-based Research in the Arabic Script and Language

By Maximilien Gudenburg

Editorial note: Maximilien Gudenburg is a student of Global History (M.A.) at the University of Heidelberg, with a special emphasis on American and German history. Before coming to Heidelberg, he completed his bachelor’s degree in History and Islamic Sciences at the University of Freiburg, with a semester abroad at Cairo’s Al-Azhar University. His bachelor’s thesis explored the portrayal of Islam and Middle Eastern countries in Nazi Germany’s largest weekly newspaper (“Das Reich”). He completed his internship at the GHI Washington in the summer of 2023.

With continuous advancements in OCR technology and an ever-growing corpus of digitized material, it comes as little surprise that more and more historians are making use of the ability to comfortably search decades’ worth of publications for keywords. Whether as a tool for quantitative assessments or to gather material for a qualitative analysis, OCR has become a staple in digital history. The technology remains a work in progress, however, and its results can sometimes be subject to severe limitations. This holds true even for Latin script, on which the majority of OCR-related research has been focused in the past. One can imagine the technology’s shortcomings when confronted with other scripts, of which Arabic has been identified as notoriously difficult to crack.[1]

This post aims to explain why Arabic script proves to be so difficult to capture by OCR programs, what problems the Arabic language itself can pose to historians, and how information technology can be used to mitigate these limitations. While neither of these topics can be explored here in full depth, one or two examples each shall serve to outline the general hurdles involved and explore one of the possible solutions at hand. The post assumes newspapers to be the source of choice, however the procedures explained can be applied to any type of digitized text.

Among the several characteristics that make Arabic script difficult to read for machines, two stick out in particular. First, the script is strictly cursive – in contrast to most other widely-used alphabets today. With few exceptions, all letters are directly connected to the letters preceding and succeeding them. This poses a severe challenge for OCR programs having to assess where one letter ends and the next begins – a problem further amplified by the fact that letters can, in some fonts, overlap vertically. Additionally, the cursive nature of the alphabet turns the relatively modest number of 28 letters into a much bigger set of glyphs, since most letters adopt different forms based on whether they appear at the beginning, the middle, or the end of a word.

 Illustration 1: Each of these words consists of the same letter three times in a row, illustrating the different forms they adopt depending on where in a word they are positioned.

Second, Arabic script relies on dots to distinguish between similar letters. As many as three different letters can have the same base form and differ only in the number and location of the dots surrounding them. Especially on older, weary material, these dots (and other small diacritics employed in the script) can easily be mistaken for background noise and thus be filtered out, or merge into hard-to-distinguish shapes.

Illustration 2: Two groups of three letters sharing the same base form.  

 Illustration 3: The left side shows a screenshot from the digitized version of a fifty-year-old newspaper. The right side shows the very same word depicted on the left, but written in computer font. While all glyphs are blurred on the left, the dots of the second and third letter are especially hard to discern.

It is not only the machine-readability of the script that poses problems, however. Even if OCR programs were capable of perfectly reading everything they are fed, challenges would still arise for those trying to process Arabic text with them. This has to do with the processes of transliteration and of translation, both of which entail a plethora of intricacies when it comes to the Arabic script and language. Transliteration (the act of converting words from one script to another) is an endeavor equally difficult in both directions, primarily because not all letters from one alphabet have a direct correspondence in the other.

To demonstrate this, it suffices to look at the name of the current head of state of Egypt. As one can imagine, it has only one correct spelling in Arabic, namely عبد الفتاح السيسي. Yet a brief glimpse into Western newspapers shows that the Latin spelling of his name could not be further from uniform. Variations as different as the following three can be found:

  • Abdul Fattah al-Sissi
  • Abd al-Fattah as-Sisi
  • Abdelfatah el-Sisi

Diversity in transliteration from Arabic to other languages is often increased by inconsistent treatment of what constitutes a proper word and what does not. This can readily be observed in the above example, where the exact same name consists of somewhere between three and five words when transliterated. Transliteration from Western languages into Arabic, in turn, is most often diluted by inconsistent treatment of vowels. While Arabic script contains diacritics to signal short vowels, these are in practice only used as reading aids in the Quran and in children’s books. Consequently, there is some leeway when transliterating short vowels, which must either be transformed into long vowels or skipped altogether.

Beyond transliteration, translation can also be a big obstacle when trying to come up with keywords for an OCR search. With Arabic belonging to an entirely different language family than all European languages (the Afroasiatic family), its syntax rarely allows for direct and obvious translations. An example for this is the Nation of Islam, a US-based Black nationalist organization. Though time has led to a consolidation of its name in Arabic (حركة أمة الإسلام, literally: Movement of the People of Islam), the corresponding translations during the organization’s first period of media coverage show impressive variety. One example would be جماعة أمة الإسلام السوداء (literally: Community of the Islamic Black People).[2] While some translations certainly take more creative freedom than others, a historian seeking to examine the reporting on an organization can hardly afford the luxury of discarding material solely because they disagree with the journalist’s rendition of the organization’s name.

For both the above issues (the imperfect state of OCR and the multitude of spellings and translations for most keywords), partial remedies exist. Since there are several competitive OCR programs for Arabic script, the deficits of one program can be ameliorated by employing a second one. While some are more generally potent than others, this does not imply strict superiority concerning individual words. Even if a software recognizes 70% of all words and another only recognizes 60%, this does not mean that all of the latter’s 60% are contained within the former’s 70%. Dual wielding these programs could thus increase the overall recognition, if only slightly. Utilizing more than two programs could well increase the yield even further, although diminishing returns are to be expected as the number of programs in use increases.

Concerning the multiple spelling variations for individual names, most OCR programs allow for the use of query syntax. This way, several different spellings can be searched for simultaneously. However, the total amount of characters per search is usually limited. This is especially bothersome since, with meticulous application of combinatorics, a single name can easily produce several dozen variations (an exercise for the curious would be to try and find all possible combinations for as-Sisi’s three transliterations above). Consequently, the process of running only one issue of a newspaper through all programs and then searching the results for all possible keyword variations might well take more time than it would have to just skim through the issue manually.

The question thus arises as to whether something can be done to improve the reliability of the OCR process without significantly increasing the overall workload. The answer to this is yes, and the concept is almost intriguingly plain: one simply needs to let the machine do even more work. The way to do so is to use a programming language to give the computer specific instructions, which is a lot easier than many people realize. While most historians react to the sheer prospect of coding about the same way a deer reacts to a headlight, this inherent fear of anything potentially involving mathematics is – as so often – unwarranted. Not all programming languages can be operated by only a small subset of well-trained and experienced people. In fact, many of them are designed specifically so that they can be relatively easily picked up by the general public.

One such language is Python, which is renowned for being comparatively easy to learn and an excellent choice for automating administrative and repetitive tasks.[3] With a lot of free learning resources, it is a matter of days, rather than weeks or months, for anyone to become sufficiently proficient in the language to automate simple tasks. With Python, a computer could, for instance, be instructed to perform the following tasks: open the digital archive of a newspaper, save every single issue under a specific, corresponding name, run all issues through all available OCR programs, save the results in a different set of documents, and then search and mark these for all possible name variations. While setting up a sequence like this might take a day or two, it can save weeks of manual labor in return – not to speak of preventing the mental fatigue from having to save, name, and search possibly thousands of documents by hand.

Of course, this still does not guarantee adequate results. Even the combined force of several OCR programs can fail to deliver sufficient results if the quality of the source material is too low. Whether the findings are suited for the task at hand is ultimately up to the researcher to decide. An easy way to get a first impression is to manually assemble a list of articles containing the relevant keywords, and then to check how many of those are found by the previously established process.

Even if this approach turns out to be futile for a specific project, basic programming skills are generally a valuable tool to acquire, especially in the field of digital history. While the necessity for automation is particularly apparent when it comes to Arabic script OCR, there are more than enough other situations where tech-savvy historians can rid themselves of strenuous tasks by adding only a few lines of well-constructed code.

[1] Faisal Alkhateeb, Iyad Abu Doush, Abdelraoaf Albsoul: Arabic Optical Character Recognition Software. A Review, pp. 764­–765, in: Pattern Recognition and Image Analysis Nr. 4 (2017), pp. 763–776.

[2] al-Ahram, April 12, 1968, p. 5.

[3] See for instance: Al Sweigart: Automate the Boring Stuff with Python. Practical Programming for Total Beginners, San Francisco 2015.