Manuscript Offprint
arXiv:2609.04755Vectorizing Classical Tamil: Representation Learning for Verse-Commentary Pairs
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
We construct a corpus of 1,262 verse-commentary (urai) pairs from five Classical Tamil source sections, ranging from technical grammatical prose to modern paraphrase, and ask what information representation learning can recover. We train recurrent and Transformer encoders, a Siamese-style pair-matching network, an mBART-style encoder-decoder, and a decoder-only language model. Each analysis is interpreted against an appropriate control on the same data. TF-IDF provides a strong no-training lexical retrieval baseline, alongside representation analyses and generation controls for the learned models. A fixed string containing the 25 most frequent commentary words scores higher on generation overlap than the decoder-only model. Canonical correlation reaches 1.000 on Gaussian noise at these sample sizes, token-F1 spans only about 0.02–0.20 on this corpus, and the encoder-decoder continues to lower training loss for sixteen epochs after validation loss has begun to rise. One narrow result remains: the decoder-only model prefers authentic word order in 107 of 112 minimal-pair comparisons (95.5%), but does not reproduce held-out commentary content. We release the extraction and evaluation protocol; redistribution of the source commentaries remains subject to permission.
1 Introduction
Throughout this paper, urai refers to the commentary associated with a verse.
Classical Tamil has a long textual and commentary tradition, but it remains largely absent from contemporary NLP. Tamil-capable models are trained mainly on Modern Tamil and web text, including the AI4Bharat/IndicNLP corpus (Kunchukuttan et al., 2020) and multilingual models such as mBERT (Devlin et al., 2019). Modelling Classical Tamil is therefore a small-data
problem in its own right, not a smaller version of modern-Tamil modelling.
We collected 1,262 verse–urai pairs from the Tamil Virtual University (Tamil Virtual University, 2024) and Project Madurai (Project Madurai, 2024). The corpus combines three explanatory registers: a modern paraphrase, gloss-and-gist material, and sectioned scholarly commentary. This variation matters because the same verse-to-urai task has different target formats across sources.
Our question is straightforward: when a model is trained on verse–urai pairs, does it learn anything beyond lexical overlap and recurring commentary forms? We examine recurrent and attention-based encoders, encoder–decoder generation, and decoder-only continuation. Cosine similarity, CCA, KCCA, and t-SNE provide views of the learned spaces; separate verse and urai encoders are compared with shared and Siamese-style settings.
The encoder–decoder lets us inspect how a verse is mapped to an urai and whether high attention weights reflect more than repeated vocabulary. We also test generalisation and use a pair-choice probe in which words or clauses are modified and reordered. That probe measures probability preference for the authentic order; it does not demonstrate grammatical understanding.
This is not a study of a deployable generator. It is a pilot study of a controls-first protocol for identifying what small-data models learn from verse–urai pairs, and what they do not.
Classical-language NLP is further developed for Sanskrit, with a dependency treebank, specialised tools for segmentation, tagging, parsing, and annotation, and pretrained models evaluated on Sanskrit tasks (Kulkarni et al., 2020; Sandhan et al., 2023; Nehrdich et al., 2024). Large Indian-language resources and multilingual models instead focus on modern text (Kunchukuttan et al., 2020; Kakwani et al., 2020; Dabre et al., 2022). Their existence does not establish transfer to a small historical corpus. Work on languages unseen during multilingual pretraining likewise shows that adaptation and evaluation matter beyond the presence of a multilingual model (Müller et al., 2021). This gap motivates in-domain data and careful controls.
We use paired-representation methods such as Siamese networks and CCA (Bromley et al., 1993; Hotelling, 1936; Hardoon et al., 2004), and a word-order probe grounded in Old Tamil regularities (Herring, 2000). Recoverability is not evidence that a model uses a linguistic property (Belinkov, 2022); our evaluation therefore distinguishes alignment, generation, and probability preference.
3 Dataset Construction
3.1 Sources
We construct a verse–commentary (urai) corpus from five Classical Tamil sources in two digital libraries: Project Madurai (Project Madurai, 2024) and the Tamil Virtual University (Tamil Virtual University, 2024). We parsed Naaladiyar from Project Madurai's Unicode text and used its trailing numerical markers (1–400) to recover verse–urai pairs. Thirukadukam and the three Tholkappiyam adhikarams used here – Eluttatikaram, Solathikaram, and Porulathikaram – were obtained from the Tamil Virtual University. The Tholkappiyam material was collected manually rather than through an automated crawler. We normalize all sources into JSONL records with verse, urai, and dataset fields.
3.2 Filtering
We drop rows with an empty verse or urai after parsing. This leaves 1,262 usable pairs from 1,277 parsed records. No additional length-based filtering is applied in the v3 experiments.
3.3 Statistics
Table 1 reports the number of valid verse–urai pairs used for the models after filtering.
| Source | Urai register | Pairs |
| Naaladiyar | Modern paraphrase | 393 |
| Tholk. Elutt. | Scholarly commentary | 379 |
| Tholk. Soll. | Scholarly commentary | 287 |
| Tholk. Porul. | Scholarly commentary | 103 |
| Thirukadukam | Gloss/gist/notes | 100 |
| Total | 1,262 |
Table 1: Verse–urai pairs used for training, counted at load time after filtering (Section 3). Thirukadukam's commentator and date remain unestablished; the Naaladiyar material is a modern paraphrase, not a traditional commentary.
The resulting corpus contains 1,262 verse–urai pairs.
Urai are substantially longer than their verses on average, as expected for prose explanations of terse, often aphoristic text. The gap is largest in Eluttatikaram, where short phonological sutras receive extended commentary.
4 Experimental Setup and Methodology
4.1 Controls before models
With 1,262 pairs, a score is interpretable only against a matched control. We use TF-IDF retrieval as a no-training lexical baseline, Gaussian matrices with the same and dimensionality for CCA, and a token-F1 null distribution from unigram sampling, random training urai, verse copying, a constant 25-word string, and a training-set oracle. TF-IDF provides a no-training lexical retrieval reference, while the learned-representation analyses reported below use different diagnostics and are not directly comparable as retrieval evaluations. The Gaussian control tests whether CCA is high because the problem is underconstrained. The token-F1 nulls show what overlap is attainable without conditioning on the verse.
4.2 Models
All models are trained from scratch on the corpus, with seed 3407.
We train separate LSTM, BiLSTM, and small Transformer encoders with a masked-word objective, extracting last-state and mean-pooled sentence vectors. We compare them with a Siamese Transformer trained to assign 1 to matched pairs and 0 to mismatches. For generation, we train a 256-dimensional, 6+6-layer mBART-style encoder-decoder with denoising followed by verse-to-urai fine-tuning, and a 256-dimensional, 4-layer decoder-only model trained on verse language modelling and verse-to-urai continuation.
4.3 Tokenisation
We tokenise on whitespace and keep whole words. Classical Tamil is agglutinative, so this is a limitation, and we return to it in Section 7.
All reported experiments use the v3 token set: <pad> <unk> <mask> <bos> <eos> <verse> <urai>.
4.4 Splits and evaluation
We use a deterministic 90/10 split: 1,136 training pairs and 126 held-out pairs. Generation and token-F1 use held-out verses only. The vocabulary is built on the full corpus, so we do not evaluate out-of-vocabulary words. The TF-IDF baseline is evaluated on the full corpus and reported by source because word-gloss commentary and paraphrase produce very different amounts of lexical overlap. No learned retrieval result is reported.
4.5 Grammar probe
Generation alone cannot determine whether the decoder prefers the word order of an original verse: a generated urai can differ from its reference in words, length, and meaning. We therefore use a pair-choice test. Each item contains a real verse and an equal-length version with one controlled perturbation, so the comparison is not driven by sequence length.
The 113 constructed pairs come from ten Naaladiyar and Porulathikaram verses. Thirteen target three regularities from Herring (2000); 99 randomly reorder one line, and one changes an inflection. The inflection item is excluded from the pooled word-order result because its perturbation contains an out-of-vocabulary token. We sum token log-probabilities and count a pair as correct when the original scores higher (chance 0.5). The set is small, dominated by random reorderings, and based on partly hand-checked language-model parses. It is therefore a diagnostic of local preference, not a measure of broad grammatical competence.
5 Results and Analysis
5.1 What the controls achieve
TF-IDF retrieves the correct urai at rank 1 in 35.3% of cases (Table 2), whereas chance is below 1%. Thirukadukam reaches 92.0% because its urai repeats verse words as gloss headwords; lexical retrieval is nearly solved there by construction. Eluttatikaram and Sollathikaram reach 28.0% and 32.1%, while Porulathikaram reaches 54.4%. TF-IDF is therefore the relevant baseline, not chance.
| Pool | n | R@1 | MRR |
| Naaladiyar | 393 | 0.389 | 0.472 |
| Tholk. Eluttatikaram | 379 | 0.280 | 0.382 |
| Tholk. Sollathikaram | 287 | 0.321 | 0.402 |
| Tholk. Porulathikaram | 103 | 0.544 | 0.614 |
| Thirukadukam | 100 | 0.920 | 0.945 |
| Combined | 1,262 | 0.353 | 0.429 |
Table 2: TF-IDF lexical retrieval, no training. Chance R@1 is below 0.01 in every pool. Thirukadukam is close to solved lexically because its commentary glosses the verse word by word.
5.2 Canonical correlation is not interpretable at this sample size
The vectors are 256-dimensional, while pools contain 100–393 pairs. CCA on matched Gaussian noise reaches 1.000 at both and . Reducing the data to 32 dimensions with PCA lowers these values only to 0.905 and 0.542. Raw CCA is not evidence of alignment in this setting; it must be interpreted against a random-data baseline with the same sample size and dimensionality.
5.3 Token-F1 requires a null baseline
On held-out rows, the decoder scores 0.060 token-F1, below TF-IDF retrieval (0.084) and a constant 25-word string (0.108; Table 3). The oracle is 0.195, leaving a narrow usable range of roughly 0.02–0.20. An identical rerun produced 0.057, so we do not interpret differences below about 0.02.
5.4 Separate encoders do not recover verse–urai alignment
The verse and urai encoders are trained separately, with no objective requiring a verse to be close to its corresponding commentary. We therefore test whether matched pairs are close in the learned vector spaces. They are not. For LSTM last-state vectors, mean cosine similarity for matched pairs
| System | token-F1 |
|---|---|
| Unigram-sampled words | 0.022 |
| Random training urai | 0.030 |
| Verse copied as its own urai | 0.044 |
| Random urai from the same text | 0.058 |
| Decoder-only model | 0.060 |
| TF-IDF retrieved urai | 0.084 |
| Constant top-25 words | 0.108 |
| Oracle (best training urai) | 0.195 |
Table 3: Null distribution for token-F1 on the same 30 held-out rows. The trained model scores below a fixed string that ignores the input, and below lexical retrieval. The oracle bounds what the metric can express on this corpus.
is 0.042 for Naaladiyar, 0.021 for Thirukadukam, and 0.045 for Tholkappiyam; it is 0.002 for the combined corpus. Mean-pooled vectors show the same pattern, with values from −0.042 to 0.018.
A small pair classifier also does not reliably distinguish a real pair from a random mismatch within a source. Its accuracy ranges from 0.500 to 0.600 across the individual source pools, where chance is 0.500. When all sources are pooled, accuracy rises to 0.842–0.845. This pooled result is not evidence of verse–urai alignment: negatives are sampled from the full corpus, so the classifier can use source-specific vocabulary, length, and commentary register instead of the relationship between a particular verse and its urai.
| Pool | Cosine | Classifier |
|---|---|---|
| Naaladiyar | 0.042 / −0.017 | 0.509 / 0.500 |
| Thirukadukam | 0.021 / 0.008 | 0.500 / 0.505 |
| Tholkappiyam | 0.045 / 0.018 | 0.554 / 0.600 |
| All sources | 0.002 / −0.042 | 0.842 / 0.845 |
Table 4: Separate-encoder diagnostics. Each entry is last-state / mean-pooled. Cosine values are mean similarities for matched verse–urai pairs. Classifier results use randomly mismatched pairs; the pooled classifier can exploit source identity.
5.5 t-SNE and Siamese matching show what the objective encourages
We use t-SNE only as a visual diagnostic. In the combined representation plots, points group more clearly by source text and commentary register than by their individual verse–urai pairing. This is consistent with the classifier result: the learned representations retain broad corpus distinctions, but the plots do not show that a verse is placed near its own urai. Since t-SNE reduces high-dimensional vectors to two dimensions and can exaggerate apparent clusters, it supports the quantitative results rather than serving as evidence on its own.
The Siamese attention model gives a different result because it is trained directly to separate matched from mismatched pairs. On the same pairs used for training, the mean cosine gap between a real pair and a random mismatch is 0.517 for Naaladiyar, 0.462 for Thirukadukam, and 0.500 for Tholkappiyam; the combined model has a smaller gap of 0.345. This shows that an explicit matching objective can fit the observed pair labels. It does not establish generalisation, because the model is evaluated on training pairs and the negative pairs are randomly sampled. A held-out, within-source retrieval or pair-classification test is needed before treating this as evidence of general verse–urai alignment.
Figure 1 provides a visual contrast between these two settings for Naaladiyar. The projection is included to show what the objectives encourage, not as an additional alignment test.
5.6 The encoder–decoder overfits after epoch 4
During supervised fine-tuning, training loss falls from 5.78 to 1.86. Held-out loss reaches its minimum at epoch 4 (9.42) and rises to 9.79 by epoch 20 (Table 5; Figure 3). We therefore restore the epoch-4 checkpoint. The epoch-20 training loss reflects memorisation rather than improved generalisation.
| Stage | train | val | val min |
|---|---|---|---|
| Denoising | 9.23 → 4.47 | 9.16 → 8.94 | 8.73 (ep. 16) |
| Fine-tune | 5.78 → 1.86 | 9.59 → 9.79 | 9.42 (ep. 4) |
Table 5: Encoder–decoder loss over 20 epochs per stage. In the fine-tuning stage validation loss reaches its minimum at epoch 4 and is worse at epoch 20 than at epoch 1, while training loss continues to fall.
5.7 Generated commentary reuses training material
We inspected five held-out generations to assess whether the decoder produced input-specific commentary or reused training material. Four outputs begin with the same phrase despite being generated for different Naaladiyar verses. The inspection also found long exact phrases from the training corpus, often from rows unrelated to the input verse. These


Figure 1: t-SNE diagnostics for Naaladiyar representations. In both panels, the horizontal axis is t-SNE dimension 1 and the vertical axis is t-SNE dimension 2; the coordinates are arbitrary projection coordinates, not interpretable linguistic features. Circles denote verse representations and triangles denote commentary representations. Left: separately trained LSTM verse and commentary encoders occupy distinct regions. Right: the Siamese model places many training verse-commentary pairs near one another because its objective explicitly rewards pair matching. These two-dimensional projections are not quantitative evidence of alignment or generalisation.

Figure 2: Siamese attention scores for matched (positive) and randomly mismatched (negative) training pairs. The matching objective separates these labels within each pool; the plot is not a held-out generalisation result.
examples suggest that the decoder combines familiar commentary fragments rather than producing an explanation specific to the verse.
The same pattern appears on out-of-domain Thirukkural couplets. The model produces outputs with a mean length of 102.4 tokens, but the mean token overlap between the input couplet and the generated output is 0.000. It therefore continues to produce commentary-like text without using vocabulary from the verse it is asked to explain.
5.8 Cross-attention recovers vocabulary overlap
Across 579,818 word pairs, the top twenty attention weights all come from Tholkappiyam; half link a word to the same word reused in the urai. The strongest attention patterns therefore reflect verbatim vocabulary reuse, not semantic alignment beyond TF-IDF.
| Top-attention property | Count |
|---|---|
| Eluttatikaram pairs | 16 / 20 |
| Sollathikaram pairs | 3 / 20 |
| Porulathikaram pairs | 1 / 20 |
| Exact verse-urai word matches | 10 / 20 |
Table 6: Composition of the twenty highest cross-attention word pairs. All twenty come from Tholkappiyam.
5.9 Form is learned where content is not
The decoder-only model prefers the original order in 107/112 pairs (95.5%), but its held-out token-F1 is 0.060, below the 0.108 constant baseline. It captures a preference for form without recovering commentary content. Preference is not evidence of use (Belinkov, 2022), and an unseen-bigram control is still needed to separate grammatical sensitivity from local distributional cues.

Figure 3: Training and held-out loss for the two encoder–decoder stages. The supervised validation loss is lowest at epoch 4, while training loss continues to fall through epoch 20.
Figure 4 separates the small set of targeted regularities from the random line reorderings. The high pooled score should be read alongside the imbalance between these subsets.

Figure 4: Final v3 minimal-pair results. The inflection item is excluded because its perturbation contains an out-of-vocabulary token. The 95.5% pooled result is driven primarily by 99 random line reorderings.
5.10 The input does not specify the target register
The explanatory styles also differ sharply in length: urai are about longer than verses in Naaladiyar, longer in Thirukadukam, and longer across the Tholkappiyam sections. A verse does not reliably indicate which register it requires. A model may generate scholarly commentary-style language for a Naaladiyar verse even though its target is a modern paraphrase. Future work should either provide the target register as an input or train separate models for each register, then evaluate whether the output matches both the verse content and the intended explanatory style.
6 Reproducibility
All reported from-scratch results use v3 preprocessing: 1,262 pairs and seven special tokens. The run ledger and complete numerical record are in experiments_v2/RESULTS_AND_METHODOLOGY.txt. The release notebooks cover the controls, LSTM, BiLSTM/Siamese, encoder–decoder, and decoder-only experiments. The final encoder–decoder result comes from the executed Kaggle notebook, not the local copy. Model notebooks use seed 3407; the probe script uses seed 42. Exact token-F1 replication is not expected: an unchanged rerun moved 0.060 to 0.057. We preserve the executed notebooks, figure manifests, package requirements, and a source map with direct landing pages and parsers. The release contains neither source texts nor pair-level JSONL; users must obtain material from the named sources. Anonymous code and reproduction materials are available at https://anonymous.4open.science/r/Vectorisation-Classical-Tamil-NLP-7E69/.
7 Limitations
The corpus contains 1,262 usable verse–urai pairs from five source sections representing three major works: Naaladiyar, Tholkappiyam, and Thirukadukam. Under the reported whitespace tokenisation, it contains 75,099 word tokens: 14,576 verse tokens and 60,523 urai tokens. It is small and uneven: Porulathikaram contributes 103 pairs, whereas Naaladiyar contributes 393.
Each model is evaluated with one configuration and seed. The train–held-out split contains verses from the same source collections on both sides, so it does not test transfer to a new text, commentator, period, or editorial tradition. Token-F1 is evaluated

Figure 5: Mean verse and urai lengths under the v3 word tokeniser. The ratio above each source is mean urai length divided by mean verse length. The target format differs substantially by source before a model sees the input verse.
on 30 held-out rows rather than the complete held-out split. The vocabulary is built from the full corpus before splitting to avoid unknown-token failures; consequently, the experiments do not test out-of-vocabulary generalisation.
The representation and Siamese analyses are measured on training pairs. Their negative examples are random mismatches, and pooled mismatches may come from another source text. A high score can therefore reflect source identity, length, vocabulary, or commentary register rather than alignment between a verse and its own urai. t-SNE is likewise a qualitative projection, not a statistical test of clustering or alignment. Repeated seeds and held-out, within-source retrieval are needed before making stronger claims about representation learning.
Whole-word tokenisation is a poor fit for agglutinative Tamil: a meaningful stem or suffix change can receive zero whole-word overlap while preserving much of the intended content. The preprocessing also does not retain verse line structure. Work on metre or prosody will need a representation that handles line structure consistently across original and perturbed text.
The grammar probe is narrow. It contains 112 usable word-order pairs and is dominated by random line reorderings. Some parses were machine-generated and only partly checked by hand. Although the model assigns higher probability to the original string under these alterations, this does not establish broad grammatical competence or show
that the preference is used when generating urai.
Finally, urai are not uniform ground-truth labels. The corpus combines modern paraphrase, lexically overlapping gloss material, and scholarly commentary. These are historically and generically different ways of explaining a verse. A plausible output in one style may be inappropriate in another, even if it has lexical overlap with the gold text. The paper does not include independent expert adjudication of every extracted pair or generated explanation.
8 Conclusion
No held-out learned verse–urai retrieval result is reported for this 1,262-pair corpus. TF-IDF establishes a strong lexical retrieval baseline, while the representation and Siamese analyses are non-comparable diagnostics; a constant string outperforms the decoder-only model on generation overlap. The study instead identifies conditions for interpreting small-data results: CCA requires matched noise controls, token-F1 requires a null distribution, compared inputs must be tokenised identically, and epoch selection requires held-out curves.
The decoder prefers authentic order in 95.5% of minimal pairs while failing to reproduce commentary content. That separation between form and content is a diagnostic, not evidence of grammatical competence.
References
Yonatan Belinkov. 2022. Probing classifiers: Promises, shortcomings, and advances. Computational Linguistics, 48(1):207–219.
Jane Bromley, Isabelle Guyon, Yann LeCun, Eduard Säckinger, and Roopak Shah. 1993. Signature verification using a “Siamese” time delay neural network. In Advances in Neural Information Processing Systems, volume 6.
Raj Dable, Himani Shrotriya, Anoop Kunchukuttan, Ratish Puduppully, Mitesh M. Khapra, and Pratyush Kumar. 2022. IndicBART: A pre-trained model for indic natural language generation. In Findings of the Association for Computational Linguistics: ACL 2022, pages 1849–1863. Association for Computational Linguistics.
Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 4171–4186. Association for Computational Linguistics.
David R. Hardoon, Sandor Szedmak, and John Shawe-Taylor. 2004. Canonical correlation analysis: An overview with application to learning methods. Neural Computation, 16(12):2639–2664.
Susan C. Herring. 2000. Poeticality and word order in old Tamil. In Susan C. Herring, Pieter van Reenen, and Lene Schøsler, editors, Textual Parameters in Older Languages, volume 195 of Current Issues in Linguistic Theory, pages 197–236. John Benjamins, Amsterdam.
Harold Hotelling. 1936. Relations between two sets of variates. Biometrika, 28(3/4):321–377.
Divyanshu Kakwani, Anoop Kunchukuttan, Satish Golla, Gokul N.C., Avik Bhattacharyya, Mitesh M. Khapra, and Pratyush Kumar. 2020. IndicNLPSuite: Monolingual corpora, evaluation benchmarks and pre-trained multilingual language models for indian languages. In Findings of the Association for Computational Linguistics: EMNLP 2020, pages 4948–4961. Association for Computational Linguistics.
Amba Kulkarni, Pavankumar Satuluri, Sanjeev Panchal, Malay Maity, and Amruta Malvade. 2020. Dependency relations for Sanskrit parsing and treebank. In Proceedings of the 19th International Workshop on Treebanks and Linguistic Theories, pages 135–150. Association for Computational Linguistics.
Anoop Kunchukuttan, Divyanshu Kakwani, Satish Golla, Gokul N.C., Avik Bhattacharyya, Mitesh M. Khapra, and Pratyush Kumar. 2020. AI4Bharat-IndicNLP corpus: Monolingual corpora and word embeddings for indic languages.
Benjamin Müller, Antonios Anastasopoulos, Benoît Sagot, and Djamé Seddah. 2021. When being unseen from mBERT is just the beginning: Handling new languages with multilingual language models. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 448–462.
Sebastian Nehrdich, Oliver Hellwig, and Kurt Keutzer. 2024. One model is all you need: ByT5-Sanskrit, a unified model for Sanskrit NLP tasks. In Findings of the Association for Computational Linguistics: EMNLP 2024, pages 13742–13751. Association for Computational Linguistics.
Project Madurai. 2024. Project madurai: Free electronic library for thamizh literature. Online digital library.
Jivnesh Sandhan, Anshul Agarwal, Laxmidhar Behera, Tushar Sandhan, and Pawan Goyal. 2023. Sanskrit-Shala: A neural Sanskrit NLP toolkit with web-based interface for pedagogical and annotation purposes. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations), pages 103–112. Association for Computational Linguistics.
Tamil Virtual University. 2024. Tamil virtual university digital library. Online digital library.
Kamil Zvelebil. 1975. Tamil Literature, volume 10 of A History of Indian Literature. Otto Harrassowitz, Wiesbaden.