One Model is All You Need: ByT5-Sanskrit, a Unified Model for Sanskrit NLP Tasks

Sebastian Nehrdich, Oliver Hellwig, Kurt Keutzer · DOI

Introduction

Processing morphologically rich languages (MRLs) has long been a significant hurdle in the field of Natural Language Processing. Sanskrit, in particular, presents a unique set of challenges due to its complex word-merging rules and extensive compounding. Traditionally, Sanskrit NLP pipelines have relied on brittle, external linguistic lexicons to navigate these complexities. This paper introduces ByT5-Sanskrit, a byte-level pretrained language model that achieves state-of-the-art (SOTA) results across multiple Sanskrit NLP tasks—including word segmentation, dependency parsing, and OCR correction—within a unified multitask framework. By operating directly on bytes, this model eliminates the need for external lexical resources, providing a robust, data-driven alternative for Sanskrit analysis.

The Challenge of Morphological Complexity

Sanskrit is characterized by Sandhi, a linguistic phenomenon where adjacent words phonetically merge into longer strings, often altering their contact phonemes (e.g., the combination of a + a resulting in ā). Because Sandhi analysis is non-deterministic, Sanskrit Word Segmentation (SWS) is a mandatory prerequisite for downstream tasks such as lemmatization or dependency parsing.

Historically, the most effective SWS systems were lexicon-driven. While accurate, these models are difficult to deploy, struggle with out-of-vocabulary words, and often fail when faced with non-standard or historical texts. Conversely, pure data-driven models, while easier to implement, have historically lacked the precision of their lexicon-heavy counterparts. ByT5-Sanskrit aims to bridge this gap by serving as a single, data-driven foundation model capable of handling all low-level Sanskrit NLP tasks simultaneously.

Methodology: The ByT5-Sanskrit Framework

The authors utilize the ByT5 architecture, an encoder-decoder Transformer that operates directly on bytes rather than subword tokens. This tokenizer-free approach is particularly advantageous for MRLs, as standard subword tokenizers often disrupt complex morphological boundaries.

Several key innovations optimize this architecture for Sanskrit:

  • Transliteration for Efficiency: The model processes text in IAST (International Alphabet of Sanskrit Transliteration) rather than the native Devanagari script. This reduces the byte count per character by approximately half, significantly increasing training and inference speeds.
  • Multitask Sequence Generation: Tasks such as segmentation, lemmatization, and morphosyntactic tagging are framed as text-to-text generation problems. The model uses simple prefix prompts (e.g., "S" for segmentation) to switch between tasks.
  • Tag Serialization: To handle long morphosyntactic tags (averaging 46 characters), the authors mapped these tags to unused, short letter combinations in the IAST alphabet, achieving a 0.14 compression ratio and improving generation efficiency.
  • Pseudo-Paragraph Context: Rather than processing isolated sentences, the model concatenates adjacent sentences into "pseudo-paragraphs" of up to 512 characters. This allows the model to utilize broader contextual clues to resolve morphological ambiguities.

Data Strategy

The model's performance is rooted in a diverse and massive dataset strategy:

  • Pretraining: The model was trained on approximately 5.4 billion characters. This includes the Sangraha dataset—a collection of noisy, OCR-scanned texts from the Internet Archive—alongside high-quality human-input data from GRETIL and the Digital Sanskrit Buddhist Canon (DSBC).
  • Fine-Tuning: Evaluation and fine-tuning were conducted using the Digital Corpus of Sanskrit (DCS), which provides manually validated lexical and syntactic annotations.
  • New Benchmark: The study introduces a novel multitask dataset derived from the DCS, specifically designed for the joint evaluation of segmentation, lemmatization, and tagging.

Performance and Results

ByT5-Sanskrit established new SOTA benchmarks across several domains:

  • Word Segmentation: The model achieved a +8.8 point gain in Perfect Match (PM) score on the Hackathon SWS benchmark (94.29) and a +4.88 point gain on the DCS 2018 benchmark (90.11) compared to previous data-driven models.
  • Vedic Dependency Parsing: It outperformed previous SOTA biaffine parsers (which used gold linguistic data) by +2.18 UAS (89.04) and +2.60 LAS (84.58).
  • OCR Post-Correction: The model significantly reduced error rates in historical texts, reaching a Character Error Rate (CER) of 2.69 and a Word Error Rate (WER) of 20.03.
  • Cross-Lingual Generalization: To demonstrate the architecture's versatility, the authors applied the ByT5 approach to Bulgarian, Romanian, and Turkish, achieving new SOTA results in dependency parsing for all three languages.

Discussion and Future Work

One of the most significant findings of this research is that pretraining on massive amounts of noisy OCR data is highly effective for historical languages, as the model learns robust latent representations despite the noise. Furthermore, multitask learning was shown to create positive transfer; training on multiple tasks simultaneously yielded better results than training specialized models for individual tasks.

Limitations: Currently, the model struggles with homonyms. For instance, the word veda can refer to a text, the act of finding, or a person's name. Because the model currently merges these into a single lemma, some lexicographical nuance is lost.

Future Work: The authors plan to implement numeric affixes to lemmata to resolve homonym issues. The success of this byte-level, multitask framework provides a clear blueprint for developing NLP pipelines for other low-resource, morphologically rich languages.

Summary updated

BibTeX
@inproceedings{nehrdich2024one,
  author = {Sebastian Nehrdich and Oliver Hellwig and Kurt Keutzer},
  title = {{One Model is All You Need: ByT5-Sanskrit, a Unified Model for Sanskrit NLP Tasks}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.805},
}
Figure