klong4-K01: a two-layer canvas generator for Thai khlong si suphap (โคลงสี่สุภาพ)

This is the checkpoint of the paper A Two-Layer Canvas Generator for Thai Khlong Si Suphap with Hard Form Masks (Worasait Suwannik, 2026, manuscript). Given a short topic it writes one khlong si suphap stanza: four lines of 5 + 2 syllables (5 + 4 in the last line), with the seven ek and four tho positions and the three rhymes of the form.

It is the klon pad canvas model of the companion paper (the klon8-base checkpoint) adapted to khlong: the canvas has the khlong geometry, the hard masks enforce the ek/tho positions by the written tone mark (an unmarked dead syllable is accepted for ek) and the three rhymes, and the model was warm-started from the klon pad model and fine-tuned on 2,001 khlong stanzas, classical and modern. It does not use the respelling devices เอกโทษ and โทโทษ and writes no คำสร้อย. One sample is drawn per topic at temperature 0.4.

Files

File What it is
model/model.pt weights (sha256 f053475b9be734873050775abc9fcd51cc01f271ce80d22352126ed9e97e8916)
model/config.json, TRAINED.json, train.log model configuration, training record and log
lexicon.json the vocabulary: 62,856 words with their pronounced syllables
allow.json allowlist of the decoder's stutter ban
g2p_raw_cache.json pronunciation cache for the 62,856 vocabulary words (word -> phonemes)
config.json, configuration_klong4.py, modeling_klong4.py the transformers wrapper
src/klong4/ the project's code, used by the wrapper
SHA256SUMS checksums of the weight and data files above

Use

With the transformers package (the repository ships its own model code, hence trust_remote_code=True):

pip install torch transformers sentencepiece protobuf pythainlp
pip install --no-deps tltk
pip install nltk gensim sklearn-crfsuite scikit-learn pandas requests matplotlib

tltk is installed with --no-deps because its package metadata pins scikit-learn~=1.2.0, which cannot be installed on recent Python versions (pip then fails while building scikit-learn); it works with current scikit-learn, and the third line installs what it imports. pip may still print a warning about that pin; it can be ignored.

from transformers import AutoModel

model = AutoModel.from_pretrained("voraseth/klong4-k01", trust_remote_code=True)
for r in model.generate_poem("สายลมสีชมพู", n=3, seed=0):          # seeds 0, 1, 2 at temperature 0.4
    print(r["poem"], r["form_pass"], "\n")

generate_poem(topic, n=1, seed=0, temperature=None) returns a list of dicts (poem, the four lines; lines, the eight half-lines; form_pass; seed; retries). generate_poems(topics, seed=0) writes one stanza per topic, in order, exactly as the paper's decode: with the paper's topic lists and seeds it returns the paper's stanzas.

Notes:

  • The checkpoint is not a standard architecture, so it has no forward for general use: a stanza is produced by the project's own decoder (src/klong4/ in this repository, unchanged from the paper's code), which the wrapper calls.
  • The first load also downloads the WangchanBERTa encoder the model is built on.
  • Device: an NVIDIA GPU (cuda) when available, then the Apple GPU (mps), otherwise CPU; pass device="cuda", "mps" or "cpu" to from_pretrained to choose, or call model.to(device) after loading. Tested on mps and CPU; CUDA has not been tested. The decoder's masks and sampling run on the CPU, so a GPU speeds up only the network pass.
  • src/klong4/ also holds the form checker (form.py), the pronunciation layer (sound.py) and the model and training code (canvas.py).

Evaluation (from the paper)

On 75 held-out stanzas and their topics (63 distinct), one sample per item, judged by three independent runs of an LLM judge (Claude Opus 5.5) in the same pools as the human stanzas:

Model Human verse
Passes the form checker, three rhymes included 100% 100% (selected)
Lexically clean 66.7% 92.0%
On topic (alignment >= 4 of 5) 72.0% 88.0%
Clean and on topic 50.7% 81.3%

The difference in the last row is -30.7 points (95% CI [-44.0, -17.3]). No generated line equals a line of the corpora searched, and none shares more than five consecutive syllables with them.

Limitations

  • Every stanza passes the automatic form checker, which counts syllables as the pronunciation converter reads them (it misreads some words), but a third contain a line the judge considers ill-formed, and the vocabulary is narrower and more repetitive than human verse (6.8% rare words against 13.9%).
  • The training set is small (2,001 stanzas).
  • The numbers are judgments of one LLM judge family, not of expert readers.
  • Output is machine-written verse and should be labelled as such.

Training data

Classical khlong from public sources (Wikisource, the vajirayana.org digital library, the klongklon dataset, the Thai Literature Corpora) and modern stanzas publicly posted on a Thai verse forum. The verse itself is not redistributed here; this repository holds weights and word lists only.

Licence

The weights are derived from WangchanBERTa, whose authors provide their pretrained weights under CC-BY-SA 4.0 (Lowphansirikul et al., 2021); this checkpoint is released under the same licence.

Credit and citation

The research was directed by Worasait Suwannik; the programs were produced by Claude, Anthropic's AI model.

@unpublished{suwannik2026khlong,
  author = {Suwannik, Worasait},
  title  = {A Two-Layer Canvas Generator for Thai Khlong Si Suphap with Hard Form Masks},
  year   = {2026},
  note   = {Manuscript}
}
Downloads last month
3
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for voraseth/klong4-k01

Finetuned
(65)
this model