Some time ago, while scrolling mindlessly on Twitter, I stumbled across a transcribed letter of Sultan Agung of Mataram to Philip IV of Spain in 1636. The original letter is written in Portuguese, but the transcriber also translated it into Indonesian.
However, even though I understand the Indonesian translation, I need an objective second opinion. What if I translated the Portuguese to English first by using ChatGPT or something?
Alright. So, I have to retranscribe the Portuguese letter manually and then feed it to ChatGPT. However, I'm too lazy to do that. Let's find another AI-based solution instead.
Go to Github.com, search for "OCR." Got it. Paddle OCR.
python -m pip install paddlepaddle -i https://pypi.tuna.tsinghua.edu.cn/simple
Collecting paddlepaddle
Collecting httpx
Requirement already satisfied : numpy>=1.13
Requirement already satisfied : Pillow
Collecting decorator
Collecting astor
Collecting opt-einsum==3.3.0
Collecting protobuf<=3.20.2,>=3.1.0
Collecting anyio
Requirement already satisfied : certifi
Collecting httpcore
Requirement already satisfied : idna
Collecting sniffio
Collecting h11<0.15,>=0.13
Collecting exceptiongroup>=1.0.2
pip install "paddleocr>=2.0.1"
Collecting paddleocr>=2.0.1
Requirement already satisfied : shapely
Collecting skikit-image
Collecting imgaug
Collecting pyclipper
Collecting lmdb
Requirement already satisfied : tqdm
Requirement already satisfied : numpy
Collecting visualdb
Collecting rapidfuzz
Collecting opencv-python<=4.6.0.66
Collecting opencv-contrib-python<=4.6.0.66
Collecting cython
Requirement already satisfied : lxml
Collecting premailer
Requirement already satisfied : openpyxl
Collecting attrdict
Collecting PyMuPDF
Collecting Pillow>=10.0.0
Requirement already satisfied : pyyaml
Collecting python-docx
Requirement already satisfied : beautifulsoup4
Requirement already satisfied : fonttools>=4.24.0
Requirement already satisfied : fire>=0.3.0
Collecting pdf2docx
Requirement already satisfied : six
Requirement already satisfied : termcolor
Requirement already satisfied : soupsieve>1.2
Collecting scipy
Requirement already satisfied : matplotlib
Collecting imageio
Collecting networkx>=2.8
Collecting tifffile>=2022.8.12
Requirement already satisfied : packaging>=21
Collecting lazy_loader>=0.3
Requirement already satisfied : et-xmlfile
Requirement already satisfied : typing-extensions
Collecting cssselect
Collecting cssutils
Requirement already satisfied : request
Requirement already satisfied : cachetools
Requirement already satisfied : colorama
Collecting bce-python-sdk
Requirement already satisfied : flask>=1.1.1
Collecting Flask-Babel>=3.0.0
Requirement already satisfied : protobuf>=3.20.0
Requirement already satisfied : pandas
Collecting rarfile
Collecting psutil
Requirement already satisfied : Werkzeug>=3.0.0
Requirement already satisfied : Jinja2>=3.1.2
Requirement already satisfied : itsdangerous>=2.1.2
Requirement already satisfied : click>=8.1.3
Requirement already satisfied : blinker>=1.6.2
Requirement already satisfied : importlib-metadata>=3.6.0
Collecting Babel>=2.12
Collecting pytz>=2022.7
Requirement already satisfied : pyparsing!=3.0.5,>=2.0.2
Requirement already satisfied : pycryptodome>=3.8.0
Requirement already satisfied : future>=0.6.0
Requirement already satisfied : countourpy>=1.0.1
Requirement already satisfied : cycler>=0.10
Requirement already satisfied : kiwisolver>=1.3.1
Requirement already satisfied : python-dateutil>=2.7
Requirement already satisfied : importlib-resources>=3.2.0
Requirement already satisfied : tzdata>=2022.1
Requirement already satisfied : charset-normalizer<3,>=2
Requirement already satisfied : idna<4,>=2.5
Requirement already satisfied : urlib3<1.27,>=1.21.1
Requirement already satisfied : certifi>=2017.4.17
Requirement already satisfied : zipp>=0.5
Requirement already satisfied : MarkupSafe>=2.0
Let's take an example Python script directly from its documentation and make a few small edits here and there (such as the image path and language code). Additionally, since my Python interpreter doesn't automatically output proper UTF-8, I've added some encoding configuration script at the beginning.
from paddleocr import PaddleOCR
import sys
sys.stdout.reconfigure(encoding='utf-8')
ocr = PaddleOCR(lang="pt")
img_path ='a.jfif'
result = ocr.ocr(img_path)
for line in result:
print(line)
txts = [line[1][0] for line in result]
for i in txts:
print(i)
The process is quite unexpectedly... long (well, I don't have a CUDA GPU, so I have to resort to CPU-based processing).
After waiting patiently and anxiously, here's what I got instead.
[[[[135.0, 155.0], [1124.0, 158.0], [1124.0, 187.0], [135.0, 184.0]], ('Traslado de la carta de Mataram, emperador de Java, que trajo Jorge', 0.9929443001747131)], [[[133.0, 191.0], [1124.0, 193.0], [1124.0, 223.0], [133.0, 222.0]], ('da Cunha en respuesta a la embajada que hizo y que mand6 el conde', 0.9879414439201355)], [[[132.0, 225.0], [288.0, 229.0], [287.0, 260.0], [131.0, 256.0]], ('de Linares.', 0.9970541000366211)], [[[137.0, 301.0], [1126.0, 303.0], [1126.0, 332.0], [137.0, 330.0]], ('Carta del emperador, el rey de Mataram, Principe, que reina en la tierra de Java con ayuda de',...
Quite confusing. But I'm pretty sure that there is some actual text over there. So, I need to clean up this output so that I can extract the text.
Let's copy-paste this entire array into a Python variable and then conduct a small experiment to extract the text.
# coding=utf-8
import sys
sys.stdout.reconfigure(encoding='utf-8')
a = [[[[135.0, 155.0], [1124.0, 158.0],... # paste the entire array here
for i in a:
print(i[1][0],end=" ")
By using that script, I finally managed to print out the actual text, properly.
Oh, that "# coding=utf-8" line is quite mandatory if our Python script contains UTF-8 characters.
Alright. Now we have the transcribed Portuguese text. It's not 100% perfect (as I still have to do some manual correction and verification here and there) but it's perfect enough, so much so that I don't need to retype all of it manually.
Traslado de la carta de Mataram, emperador de Java, que trajo Jorge da Cunha en respuesta a la embajada que hizo y que mando el conde de Linares.
Carta del emperador, el rey de Mataram, Principe, que reina en la tierra de Java con ayuda de Dios Nuestro Senor, que asiste tambien con amor a todos los pobres y cristianos y ampara a todos los hijos, huerfanos y ademas es el mas afamado en las guerras del sur contra la gente holandesa, y ademas tiene el favor de Dios Nuestro Senor, el rey de Mataram con ayuda y ruegos de todos los profetas (walis) para mi y para siempre. Amin.
Brindo a vuestro rey ocasión, persona de grande titulo y muy estimado, el rey de Portugal que es afamado en los territorios y campos de guerra de Norte a Sur, y asi también es afamado por concertar y unir alianzas con todos los reyes y por querer destruir a todos los enemigos de nosotros dos, con favor de Dios, haré oraciones de Vitoria en todos estos anos contra nuestros enemigos la gente holandesa antes dicha.Â
Tiempo antes el virrey mando a Jorge da Cunha da Costa venir a mi, el emperador, para traer una carta y llego con todas vuestras bendiciones y vuestros regalos, que todo llego bien a mi, el emperador y rey en buena hora, en agosto, y el emperador recibio todo lo mandado. El cofre de Sumatra lo recibi con mucha felicidad. Asi el emperador recibio todo lo demas mandado por el virrey: un reloj, una espingarda (arma de fuego), muchos mosquetes, una capa, un sombrero y las mujeres con sus cosas de plata y mucha ropa.
Tenga también vuestro virrey la noticia que juntamente podemos hacer un cerco a la gente holandesa en Yakarta. Asi mismo el emperador también esta muy contento y con voluntad de poder hacerlo con el favor de Dios y que llegue la hora en que la armada de vuestro rey ira a Yakarta porque que la gente de Mataram también estara alerta y preparada esperando ver la armada. Si de verdad vuestro rey quiere ayudarme, debe venir en estos dos monzones porque el emperador solo esperara dentro de estos dos monzones. Tienes que venir en dos monzones por la promesa hecha y el amor que tienes al emperador.
El virrey tiene que poder hacerlo y prometerme a mi el emperador que no va a dar marcha atras en esto y que quiere al emperador. Yo espero de dia y de noche que vuestra armada de Goa pueda venir y poder poner cerco a Yacarta. Después de hacer esto, yo ya no me quedara nada mas que hacer en mi Imperio. Os regalo dos krises con la empunadura de oro y dos espadas en senal que nos amamos y nos queremos.Â
The final step: let's feed it to ChatGPT. Here's the translation.
Transfer of the letter from Mataram, Emperor of Java, brought by Jorge da Cunha in response to the embassy sent by the Count of Linares.
Letter from the Emperor, the King of Mataram, the Prince, who reigns in the land of Java with the help of Our Lord God, who also lovingly assists all the poor and Christians and protects all the children, orphans, and is renowned in the wars of the south against the Dutch people. Furthermore, he enjoys the favor of Our Lord God, the King of Mataram, with the assistance and prayers of all the prophets (walis), for me and forever. Amen.
I toast to your king, a person of great title and much esteem, the king of Portugal who is renowned in the territories and battlefields from North to South. He is also famous for arranging and uniting alliances with all kings and for wanting to destroy all our common enemies. With the favor of God, I will offer prayers for victory in all these years against our aforementioned Dutch enemies.
Some time ago, the viceroy sent Jorge da Cunha da Costa to me, the emperor, to bring a letter, and he arrived with all your blessings and gifts, which all reached me, the emperor and king, in good time, in August. The emperor received everything as instructed. I received the chest from Sumatra with great happiness. Thus, the emperor received all the other items sent by the viceroy: a clock, a firearm (gun), many muskets, a cloak, a hat, and the women with their silver belongings and a lot of clothing.
Let your viceroy also have the news that together we can besiege the Dutch people in Jakarta. Likewise, the emperor is also very pleased and willing to do so with the favor of God, and the time will come when the fleet of your king will go to Jakarta because the people of Mataram will also be alert and prepared, eagerly awaiting the sight of the fleet. If your king truly wants to help me, he must come in these two monsoons because the emperor will only wait within these two monsoons. You have to come in two monsoons because of the promise made and the love you have for the emperor.
The viceroy must be able to do this and promise me, the emperor, that he will not backtrack on this and that he loves the emperor. I hope day and night that your fleet from Goa can come and besiege Jakarta. After doing this, I will have nothing more to do in my Empire. I give you two krises with golden handles and two swords as a sign that we love and care for each other.
Epilogue
Using the exact same method as above, I attempted to translate a small portion of the 1891 Dutch East Indies State Gazette by simply changing the language code from "pt" to "nl". Here are the results.
List of Laws and Decrees Contained in the State Gazette of the Dutch East Indies for the Year 1891.
Exemption of the attendants at the school for the education of Indigenous medical practitioners in Weltevreden from personal military service.Approval of the new articles of association of the General Burial Fund established in Surabaya
Determination that the civilian main guard in Banda-Neira is abolished and the non-commissioned officers and enlisted men of the militia who have been sentenced to arrest there will henceforth undergo their punishment in the detention facilities of the "Belgica" fort in Banda-Neira.
Supplement and amendment of the provisions regulating the leasehold of lands belonging to the State Domain on properties outside Java and Madura
Rules to be observed in applying for the leasehold of lands belonging to the State Domain on properties outside Java and Madura
Law dated November 12, 1890 (Netherlands State Gazette No. 169), confirming the agreement concluded on June 9, 1890, with Mr. D. Croll regarding the leasehold of a portion of the harbor area in Tandiong-Priok and the provision of dry docks.
Decree dated January 13, 1891, No. 18. Free passage in the Dutch East Indies to the destination for the missionaries destined for the Sangi and Talauer Islands, who are granted an allowance from the public funds.
Decree dated January 29, 1891, No. 3. Determining that the Clerks of the Land Courts in Tangerang and Bandoeng will also serve as such, respectively, at the Land Court in Meester-Cornelis and at the Land Courts in Tjitialengka and Soemedang. Also, the Clerk of the Land Courts in Meester-Cornelis and Bekasi will henceforth serve as such at the Land Courts in Poerwakarta and Bekasi.
Appointment of a Clerk for the Land Courts in Garoet, Mangoenredja, Tasikmalaja, Manondjaja, and Tjiamis.
Decree dated January 29, 1891, No. 17. Increase in the amount for the remuneration of subordinate personnel for active supervision in the service of import and export duties and excise, and for allowances to Receivers for office expenses, clerical fees, and remuneration of personnel for the supervision and cleanliness of warehouse premises.
Decree dated January 30, 1891, No. 7. Increase in the salary of the Panghulu at the Land Courts in Medan and Bindjei.
Decree dated January 30, 1891, No. 17. Appointment of a second Assistant Public Prosecutor in the regency of Sidhoardjo.
Decree dated January 30, 1891, No. 18. Supplement to the provisions regarding the write-off of claims.
Decree dated January 31, 1891, No. 16. Stipulation that in the two highest classes of the Ambonese civilian school, instruction in the Malay language will be provided, and that the allowed teaching staff for that school will be increased by one Native Teacher of the first rank.
Glancing through the past by using publicly available digitized archive of primary sources through the lens of AI technology... is fun.