Date: 26-Oct-2025


Next level poetry game - Vietnamese Tang Poem tool check

Preface

This is one blog that I find tough to start. I am more logical in English and more creative in my mother tongue, Vietnamese. However, this time, I am approaching a creative activity programmatically. Deciding which language to write this post in is already tough enough. It is shameful that I find myself struggling to explain the tool in the same language that my poems are written in.

I have a good feeling that this tool is the very first of its kind, at least within the realm of my mother tongue. In the age of AI, many things are possible. However, I believe poetry, as well as any other forms of art, are domains that machines can hardly touch or just yet scratch on the surface.

In addition, in my previous blog Deploy my own blog finally, I mentioned that I am not a trained SWE. This is a good opportunity to introduce my background. I have been a spreadsheet guy for quite a while, and I am... pretty good at it.

The full repo can be found here.

Tang poetry introduction

The Vietnamese Tang poetry

Tang poetry refers to poetry written in a style originating from China's Tang Dynasty, the Golden Age of Chinese poetry. Vietnamese history, just like any other Asian culture, is partly influenced by Chinese culture. In Vietnamese literature, there are several types of Tang-Vietnamese poems, defined by the language the poems are written in:

  • Tang poems in Chinese (Hán)
  • Tang poems that are translated to Sino-Vietnamese form (Hán-Nôm)
  • Tang poems that are purely written in pure Vietnamese (Nôm)

In this blog, I am specifically referring to the third one: Vietnamese poems following Tang Poetry rules.

Rules - State of the art

The materials explaining the Tang poetry rules in English are really scarce. In this blog, I will try to set a foundation in the most succinct way to clarify why the tool is indeed very satisfying, from my perspective.

This section is only valuable to non-Vietnamese readers.

For Vietnamese readers, you may find this link to have a better grab of essence of Tang poetry

1st rule: Bang and Trac tone

  • In Vietnamese, there are 6 tones:

    • ngang - e.g: cam, ma, xin, ...
    • huyền - e.g: làm, thì, là, khùng ...
    • sắc - e.g: chó, má, cá, đá, ...
    • hỏi - e.g: cỏ, đỏ, thỏ, nhỏ, ...
    • ngã - e.g: võ, vẽ, sẽ, kẽ, đã, ...
    • nặng - e.g: lạ, tạ, mẹ, lẹ, ...
  • The 6 tones are classified into:

    • Bang: ngang and huyền.
    • Trac: the rest.

2nd rule: Rule

The tone of the 2nd word in the first sentence decides the poem rule type.

So the poem is either Bang rule or Trac rule

3rd rule: Rhyme

The final word in the first sentence decides the poem's rhyme type.

  • Bang rhyme requires the final word of 1st, 2nd, 4th, 6th and 8th sentences of the same rhyme.
  • Trac rhyme requires the final word of 2nd, 4th, 6th and 8th sentences of the same rhyme.

4th rule: Counterpoint

The 2nd and 6th words in each pair of sentences must counter one another in tone.

e.g: If one sentence's 2nd word is Bang, the 2nd word in another sentence must be Trac.

Below are pairs of sentences that must counter one another in tone.

  • 1st vs 8th
  • 2nd vs 3rd
  • 4th vs 5th
  • 6th vs 7th

The counterpoint even expands to meaning and sentence structure:

  • 1st vs 2nd and 7th vs 8th : must counter one another in tone.
  • 3rd vs 4th and 5th vs 6th: must counter one another in tone and sentence structure.

In fact, I usually miss the sentence structure counterpoint. The tone counter can be easily embedded in the tool I created. However, for the sentence structure and overall meaning, it requires a different level of expertise in the skill set.

5th rule: Exception - Add flexibility

The exceptions in tones can be added for more flexibility. The strict rule still requires correct tones.

  • 1st, 3rd, and 5th words are not necessarily to be of the right tone
  • 2nd, 4th, and 6th words must be of the right tone.

Application

Hence, there are a total of 4 variants when combining all the above rules:

  • Bang rule Trac rhyme
  • Bang rule Bang rhyme
  • Trac rule Bang rhyme
  • Trac rule Trac rhyme

Each of them has a specific set of tones and rhymes. They can be found in the spreadsheet's Rule sheet.

Other forms

As you might notice, the rules stated above are for "Thất ngôn bát cú" - 7-word-8-sentence poems.

However, it can be easily extended to "Thất ngôn tứ tuyệt" - 7-word-4-sentence poems. Any rules that require 5th sentences forward can be easily removed.

There are also other forms with only 5 words in each sentence instead of 7 words. We call them "Ngũ ngôn bát cú" and "Ngũ ngôn tứ tuyệt" accordingly. The rules are simple: use their respective 7-word form's rule and remove the first two words in each sentence.

For more details, you can take a look at the spreadsheet, which is presented in both English and Vietnamese.

The tool

Why?

I usually do poetry in more relaxed forms, mainly to express my sarcasm on matters at hand with speed. I use poetry the same way underground rappers battle one another - focusing on speed while keeping most essence in their song. From my experiences with different forms, I find Tang poetry hard yet extremely satisfying once you can finally catch it.

Again, I must repeat that the art is hard to grasp. Eventually, I decided to approach the hobby with the same discipline I use to write my code:

  • Plan out the overall architecture
  • Write the test suite first

So I TDD - Test Driven Development my poetry hobby, giving birth to the tool presented here.

How?

The tool is created in a spreadsheet, planned to be a base for further future development into a more extensive tool. At the moment, the tool serves me well for my hobby.

I wrote this in Excel first, using Office Script (Typescript). However, considering a slow movement toward open-source, I decided to finalize one in LibreOffice. A macro is written in Python.

Below are the steps to utilize the tool. They are straightforward:

  • Place your poem in cell "poemInput" in sheet Check
  • Decide whether you want to show the statistics or not
  • Click the button to run the check script
  • Modify your "poemInput", rerun the check script until satisfaction

Demo

Let us test some familiar poems that most Vietnamese students encounter during their school life.

Bánh trôi nuớc - Hồ Xuân Hương

As seen in the above screenshot, the strict rule accuracy is 90% while the relaxed rule is 100%.

This is an excellent demonstration to showcase the effectiveness of the tool.

Đèo Ngang - Bà Huyện Thanh Quan

Đèo Ngang - Bà Huyện Thanh Quan analysis

As seen in the above screenshot, the strict rule accuracy is only 86%. What is the problem here? It is the rhyme that are causing the issue seen here. [, hoa, nhà, gia, ta] are a set of words that must be rhymed together. In fact, they sound very much alike. However, the tool considers hoa to be a different rhyme compared to others(oa vs a). This causes a drop in the overall accuracy.

As a poet using the tool, what can you do? Just fix column K in sheet Check to be 0, indicating a manual acceptance of the rhyme.

After the manual adjustment, the statistics will be updated accordingly. The strict rule accuracy is now 95%.

At the end of the day, the poet himself is the one who decides what is acceptable after all.

Tụng giá hoàn kinh sư - Trần Quang Khải

This is a Sino-Vietnamese Tang poem. Let us run a check on this.

Tụng giá hoàn kinh sư - Trần Quang Khải analysis

As seen in the screenshot, the strict rule is 90% while the relaxed rule is 100%. This is indeed a fine piece.

Điếu Bát - Unknown author

This is a poem that is widespread, and probably among one of my favorites due to its witty and lustful expression. From this, you can see the underground side of poetry where not just all beautiful words are painstakingly crafted. If you say I am tainting the fine art. Unfortunately, I am not. The art itself is already "tainted" by many others.

Điếu Bát analysis

The strict accuracy is up to 96% and the relaxed rule 100%. In fact, the author has already fathomed the art of Tang Poetry when crafting his piece.

Since this was created by an unknown author, I do not hesitate to adjust his piece to reach 100% accuracy under the strict rule. You might consider this a good demo on how I upped the game of poetry to the next level.

Điếu Bát analysis

Just by fixing a few words, the strict rule accuracy now reaches up to 100%. Such a small increment, yet the immeasurable satisfaction.

Trình - Me

I created the poem to diss someone else. Underground Hiphop much for poetry? The whole poem does not utilize a single nasty word. Along the way, it also shows the humility and humbleness of the author (me). However, combining the first letters from each sentence, you will know exactly that this is a dissing poem.

The first draft is: Trình-draft analysis

The strict rule accuracy is 84% and the relaxed rule is 100%. Usually, I would stop here. However, let us see the next fix.

The final fix is:

Trình-fixed analysis

The strict rule is up to 91%. The 9% short is due to the incorrect tone of the first words in sentences, which are nastily formed to "diss" another reader.

Nhậu - Me

This is another piece written by me. The poem describes the simple happiness of an office worker after his long hours of work

Nhậu-draft analysis

The first draft already sounds great. I love it to the very core of it. However, running a check shows a quite disappointing result: strict rule accuracy is 75% and relaxed rule accuracy is 90%.

Then I sat down and provided the fix as below:

Nhậu-fixed analysis

Now, both the strict rule and the relaxed rule accuracy reached 100%. Sounds better, feels better too.

Workflow

This is how I craft my poems now:

  • I go with the flow
  • Run the check
  • Then fix it if necessary
  • Rerun the check
  • Repeat until satisfaction.

Yes, I TDD my poetry game with the help of new tools.

Conclusion

To me, it has been a great journey in poetry so far:

  • I wrote some witty pieces since my secondary school, mostly to irritate my friends by using their own stories or materials.
  • I wrote some to help my friends propose.
  • I wrote some to diss people I dislike.
  • I wrote some to create a novel like "Truyện Kiều" or "Lục Vân Tiên".
  • I wrote some just for fun.
  • I wrote some just for the sake of the art itself.

Now I wrote a tool to remove my excuses to strict up my poems. Less free-style, less "Cổ Phong" from now on. Many pieces written before will soon be revised. Please wait for the next posts if I find them good to share.