SanskritShala: A Neural Sanskrit NLP Toolkit with Web-Based Interface for Pedagogical and Annotation Purposes

Jivnesh Sandhan, Anshul Agarwal, Laxmidhar Behera, Tushar Sandhan, Pawan Goyal

Abstract

SanskritShala is the first neural-based NLP toolkit for Sanskrit that integrates state-of-the-art models for word segmentation, morphological tagging, dependency parsing, and compound identification into a single, user-friendly web interface. By combining deep learning with traditional linguistic rules, it provides a powerful platform for both students learning the language and researchers building the next generation of Sanskrit datasets.

Introduction

Sanskrit is a "low-resource" language in the AI world, but it is linguistically one of the most complex. It features the sandhi phenomenon (where word boundaries transform when joined), a massive system of 40,000+ possible morphological labels, frequent compounding, and a very flexible word order.

Existing tools for Sanskrit generally fall into two camps: rule-based systems that are precise but struggle with "out-of-vocabulary" words, and manual annotation tools that offer no automated help. SanskritShala addresses this gap by providing a neural-based "human-in-the-loop" system. It uses deep learning to make predictions but allows users to interactively correct them, making the process of analyzing ancient texts faster and more accurate.

Methodology

The toolkit consists of four primary neural modules, each designed to handle a specific linguistic challenge.

1. TransLIST (Tokenizer)

A Transformer-based model that handles word segmentation. It is "linguistically informed," meaning it doesn't just guess where words end; it uses a rule-based system (the Sanskrit Heritage Reader) to generate a space of possible candidates and then uses a soft-masked attention (SMA) mechanism to pick the best one.

TransLIST architecture with Soft-Masked Attention (SMA) for word segmentation.

2. LemmaTag (Morphological Tagger)

This module uses a multi-task learning framework with bidirectional RNNs. It simultaneously predicts the "lemma" (the base form of a word) and its morphological tags (gender, case, number, etc.) using both character-level and word-level representations.

3. Ensembled Dependency Parser and SaCTI (Compound Identifier)

To handle the lack of labeled data, the authors used an ensemble strategy including data augmentation and a novel pretraining task called LCM (Lemma, Case, and Morphological tag prediction). This helps the parser understand the syntactic structure of a sentence even with limited training examples.

Sanskrit is also famous for long compound words. The SaCTI module uses a multi-task approach that incorporates information from the morphological and dependency modules to identify the semantic relationship between components of a compound.

The LCM pretraining framework (c) and the downstream dependency parsing and compound identification tasks (d).

Datasets and Evaluation

The authors utilized several benchmark datasets for training and evaluation, including the Digital Corpus of Sanskrit (DCS). Beyond the models, they released significant new resources:

  • 7 Pretrained Word Embeddings: Including static models (word2vec, GloVe, fastText) and contextualized models (ELMo, ALBERT, and their own LCM).
  • 4 Intrinsic Evaluation Datasets: New benchmarks for Sanskrit word similarity, relatedness, categorization, and analogy prediction to help other researchers measure the quality of their word embeddings.

Results and Key Insights

SanskritShala's modules currently report state-of-the-art (SOTA) performance across all four tasks:

  • Word Segmentation: Achieved a 93.97% Perfect Match (PM) score.
  • Morphological Tagging: Ranked 1st on the Hackathon leaderboard with a 69.3 F1-score.
  • Dependency Parsing: Reached an 88.67 Unlabelled Attached Score (UAS).
  • Compound Identification: Achieved an 81.7 F1-score.

Hybrid Neural-Rule Systems

The "aha moment" here is that deep learning doesn't have to replace rule-based systems. By using rule-based systems to define a "candidate space" and neural models to rank those candidates, the authors achieved significantly higher accuracy than using either method in isolation. Furthermore, in low-resource settings, forcing the models to learn auxiliary tasks like case and lemma prediction (the LCM pretraining) provides essential linguistic anchors.

Limitations and Future Work

The authors note that while the system is robust for prose, it is "fragile" when applied to Sanskrit poetry. Because poetry often uses highly non-standard word orders to fit metrical constraints, the dependency parser's performance drops significantly in this domain.

Future work aims to expand the toolkit to include post-OCR correction (fixing errors from scanned manuscripts), Named Entity Recognition (NER), and machine translation for word order linearization (converting poetic word order back into standard prose).

Summary updated

BibTeX
@inproceedings{sandhan2023sanskritshala,
  author = {Jivnesh Sandhan and Anshul Agarwal and Laxmidhar Behera and Tushar Sandhan and Pawan Goyal},
  title = {{SanskritShala: A Neural Sanskrit NLP Toolkit with Web-Based Interface for Pedagogical and Annotation Purposes}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-demo.10},
}
Figure