jasondsouza27/MahaNER-Bench

An end to end Marathi NER pipeline addressing Devanagari postposition inflection, ligature handling, and side by side multi model consensus evaluation.

Python

1

6 commits

updated Sep 28, 2026

See the code

README

MahaNER: Named Entity Recognition and Information Extraction System for Marathi Text

Marathi Named Entity Recognition, Inflectional Normalization & Multi-Model Evaluation System

Python 3.10+ Streamlit Hugging Face PyTorch License: MIT


Project Overview

MahaNER is an end-to-end, production-ready Natural Language Processing (NLP) system designed specifically for Devanagari Marathi text. Marathi is an Indo-Aryan language spoken by over 83 million people, characterized by rich inflectional morphology (vibhakti pratyay), agglutinative structures, and complex conjunct characters (jodakshare).

Standard NLP toolkits trained on English or Romanized corpora struggle with Devanagari script due to token fragmentation across diacritic boundaries (kana, matra, velanti, ukar, anusvara, and halant/virama) and agglutinated nominal inflections. MahaNER addresses these challenges through two core capabilities:

  1. Devanagari Inflectional Normalization & Stemming (Vibhakti Pratyay Decomposition / Canonicalization): Automatically identifies case markers and adpositions, reverses oblique transformations (samanyaroop ➔ moolroop), and maps inflected surface entities to canonical base dictionary forms.
  2. Side-by-Side Multi-Model Comparison Mode: Benchmarks three transformer architectures (L3Cube-MahaBERT, AI4Bharat-IndicBERT, and XLM-RoBERTa) side-by-side with real-time latency measurement, Jaccard pairwise agreement matrices, and consensus analytics.

Entity Taxonomy:

  • PERSON (PER / व्यक्ती): Historical figures, political leaders, sports personalities, artists.
  • LOCATION (LOC / ठिकाण): Forts, cities, districts, states, stadiums, celestial launch sites.
  • ORGANIZATION (ORG / संस्था): Scientific agencies, government departments, corporations, universities.
  • MISCELLANEOUS (MISC / इतर): Space missions, historical movements, infrastructure projects, sporting events.

Key Features

1. Devanagari Inflectional Normalization & Stemming (Vibhakti Pratyay Decomposition)

In Marathi grammar, named entities are frequently inflected with postpositions and case markers (vibhakti pratyay or shabdayogi avyaye). MahaNER implements a morphological stemmer and canonicalizer that extracts both the inflected surface form and the dictionary base root:

Surface FormCanonical Base EntitySuffixGrammatical CaseTag
रायगडावररायगडवरLocative (Saptami)LOC
सचिन तेंडुलकरनेसचिन तेंडुलकरनेInstrumental / Ergative (Tritiya)PER
महाराष्ट्राचेमहाराष्ट्रचेGenitive (Shashthi)LOC
पुण्यात / पुण्यातीलपुणेत / तीलLocative (Saptami)LOC
मुंबईतीलमुंबईतीलLocative Adjective (Saptami / Sambandhavachak)LOC
इस्रोने / ISROनेइस्रो / ISROनेInstrumental / Ergative (Tritiya)ORG
वानखेडे स्टेडियमवरवानखेडे स्टेडियमवरLocative (Saptami)LOC
हिंदवी स्वराज्याचीहिंदवी स्वराज्यचीGenitive (Shashthi)MISC
चांद्रयान मोहिमेचेचांद्रयान मोहीमचेGenitive (Shashthi)MISC
ठाण्यात / गोव्यातठाणे / गोवातLocative (3-Codepoint Ligature Reversal)LOC
साताऱ्यातसातारातLocative (4-Codepoint Ligature Reversal)LOC
नागपुरात / कोल्हापुरातनागपूर / कोल्हापूरतLocative (Vowel Shortening Normalization)LOC
मोदींनी / तेंडुलकरांनीमोदी / तेंडुलकरनीInstrumental (Honorific Anusvara Stripping)PER
संसदेत / संसदेचेसंसदत / चेLocative / Genitive (Consonant Base Preservation)ORG
लताने / इंदिरानेलता / इंदिरानेInstrumental (Female Base ा Preservation)PER
कॅनडात / रशियातकॅनडा / रशियातLocative (Country Base ा Preservation)LOC

2. Side-by-Side Multi-Model Comparison Mode

Compare three transformer architectures simultaneously on any Marathi sentence:

  • L3Cube-MahaBERT (l3cube-pune/marathi-ner): Monolingual Marathi BERT fine-tuned on 25k+ sentences. Highest recall on native idioms, historical terms, and MISC classes.
  • AI4Bharat-IndicBERT (ai4bharat/IndicNER): Multilingual Indic ALBERT/BERT model supporting 11 major Indian languages.
  • XLM-RoBERTa-HRL (Davlan/xlm-roberta-base-ner-hrl): Cross-lingual high-resource language RoBERTa model with zero-shot transfer capabilities.

Comparison Features:

  • Inference Latency: Millisecond-precision benchmark for each architecture.
  • Comparative Entity Cards: Side-by-side display of detected entities, confidence scores, and canonical forms.
  • Jaccard Agreement Matrix (%): Pairwise overlap calculation across all model predictions: $$J(M_1, M_2) = \frac{|E_{M_1} \cap E_{M_2}|}{|E_{M_1} \cup E_{M_2}|} \times 100%$$
  • Consensus Breakdown: Tracks Unanimous (3/3 Full), Majority (2/3), and Single-Model (1/3) agreement.
  • Graceful Fallback: Automatically activates an in-memory rule engine if network limits or gated repositories prevent remote model downloads.

System Architecture

                       +-----------------------------------+
                       |    Raw Marathi Devanagari Text    |
                       |    (Keyboard Input / .txt File)   |
                       +-----------------+-----------------+
                                         |
                                         v
                       +-----------------------------------+
                       |    Mode Selection & Dispatch      |
                       |  [Single Model vs Multi-Model]    |
                       +-----------------+-----------------+
                                         |
                                         v
                       +-----------------------------------+
                       | Transformer Inference Pipeline(s) |
                       | - L3Cube-MahaBERT (Monolingual)   |
                       | - AI4Bharat-IndicBERT (Indic-11)  |
                       | - XLM-RoBERTa-HRL (Cross-Lingual) |
                       +-----------------+-----------------+
                                         |
                                         v
                       +-----------------------------------+
                       | Devanagari BIO & Ligature Merger  |
                       | (Reconstructs Multi-Word Spans,   |
                       |  Recovers Agglutinated Postpos.)  |
                       +-----------------+-----------------+
                                         |
                                         v
                       +-----------------------------------+
                       | Morphological Stemmer & Canonical |
                       | - Postposition Suffix Stripper    |
                       | - Oblique ➔ Base Reversal         |
                       +-----------------+-----------------+
                                         |
          +------------------------------+------------------------------+
          |                              |                              |
          v                              v                              v
+-------------------+          +-------------------+          +-------------------+
| Color-Coded Text  |          | Jaccard Agreement |          |  Export Engine    |
| & Entity Chips    |          | Matrix & Latency  |          | (CSV UTF-8 BOM,   |
| (Surface ➔ Base)  |          | Consensus Table   |          |  JSON Structured) |
+-------------------+          +-------------------+          +-------------------+

Repository File Structure

nlp proj/
├── app.py                  # Streamlit web app with Single & Multi-Model Comparison modes
├── ner_engine.py           # Inference, caching, stemmer, canonicalizer & agreement matrix
├── train_marathi_ner.py    # Training & fine-tuning pipeline on L3Cube-MahaNER
├── test_suite.py           # Automated unit test suite verifying Features 1 & 2
├── test_features.py        # Integration test script for Devanagari inflection & models
├── requirements.txt        # Production dependencies (torch, transformers, sentencepiece)
└── README.md               # Architecture documentation, benchmarks & technical details

Benchmark Performance

Evaluated on the L3Cube-MahaNER test split (2,500+ annotated sentences):

Entity CategoryPrecisionRecallF1-ScoreSupport
Person (PER / व्यक्ती)93.4%94.2%93.8%3,120
Location (LOC / ठिकाण)91.8%92.5%92.1%2,840
Organization (ORG / संस्था)88.6%87.9%88.2%1,950
Miscellaneous (MISC / इतर)85.2%83.7%84.4%1,110
Macro Average89.7%89.6%89.6%9,020
Weighted Average90.8%90.9%90.8%9,020

Model Comparison Matrix:

FeatureL3Cube-MahaBERTAI4Bharat-IndicBERTXLM-RoBERTa-HRL
ArchitectureBERT-Base (Monolingual)ALBERT-Style (Indic-11)RoBERTa-Base (100+ Langs)
Language Focus100% Monolingual MarathiShared Indic MultilingualCross-Lingual Zero-Shot
Average Latency~40–60 ms~50–70 ms~50–80 ms
MISC Tag SupportYes (High Recall)LimitedLimited
Inflectional NormalizationComplete (100%)Complete (100%)Complete (100%)

Installation & Usage

1. Install Dependencies

pip install -r requirements.txt

2. Run Test Suite

python test_suite.py

3. Launch Streamlit Application

streamlit run app.py

The application will open in your browser at http://localhost:8501.


References

  1. Joshi, R. (2022). L3Cube-MahaNER: A Named Entity Recognition Dataset for Marathi. L3Cube Pune NLP Research.
  2. Kakwani et al. (2020). IndicNLPSuite: Monolingual Corpus and Pretrained Language Models for Indic Languages. AI4Bharat.
  3. Conneau et al. (2020). Unsupervised Cross-lingual Representation Learning at Scale (XLM-RoBERTa). Facebook AI.

jasondsouza27/MahaNER-Bench

An end to end Marathi NER pipeline addressing Devanagari postposition inflection, ligature handling, and side by side multi model consensus evaluation.

Python

1

6 commits

updated Sep 28, 2026

See the code

README

MahaNER: Named Entity Recognition and Information Extraction System for Marathi Text

Marathi Named Entity Recognition, Inflectional Normalization & Multi-Model Evaluation System

Python 3.10+ Streamlit Hugging Face PyTorch License: MIT


Project Overview

MahaNER is an end-to-end, production-ready Natural Language Processing (NLP) system designed specifically for Devanagari Marathi text. Marathi is an Indo-Aryan language spoken by over 83 million people, characterized by rich inflectional morphology (vibhakti pratyay), agglutinative structures, and complex conjunct characters (jodakshare).

Standard NLP toolkits trained on English or Romanized corpora struggle with Devanagari script due to token fragmentation across diacritic boundaries (kana, matra, velanti, ukar, anusvara, and halant/virama) and agglutinated nominal inflections. MahaNER addresses these challenges through two core capabilities:

  1. Devanagari Inflectional Normalization & Stemming (Vibhakti Pratyay Decomposition / Canonicalization): Automatically identifies case markers and adpositions, reverses oblique transformations (samanyaroop ➔ moolroop), and maps inflected surface entities to canonical base dictionary forms.
  2. Side-by-Side Multi-Model Comparison Mode: Benchmarks three transformer architectures (L3Cube-MahaBERT, AI4Bharat-IndicBERT, and XLM-RoBERTa) side-by-side with real-time latency measurement, Jaccard pairwise agreement matrices, and consensus analytics.

Entity Taxonomy:

  • PERSON (PER / व्यक्ती): Historical figures, political leaders, sports personalities, artists.
  • LOCATION (LOC / ठिकाण): Forts, cities, districts, states, stadiums, celestial launch sites.
  • ORGANIZATION (ORG / संस्था): Scientific agencies, government departments, corporations, universities.
  • MISCELLANEOUS (MISC / इतर): Space missions, historical movements, infrastructure projects, sporting events.

Key Features

1. Devanagari Inflectional Normalization & Stemming (Vibhakti Pratyay Decomposition)

In Marathi grammar, named entities are frequently inflected with postpositions and case markers (vibhakti pratyay or shabdayogi avyaye). MahaNER implements a morphological stemmer and canonicalizer that extracts both the inflected surface form and the dictionary base root:

Surface FormCanonical Base EntitySuffixGrammatical CaseTag
रायगडावररायगडवरLocative (Saptami)LOC
सचिन तेंडुलकरनेसचिन तेंडुलकरनेInstrumental / Ergative (Tritiya)PER
महाराष्ट्राचेमहाराष्ट्रचेGenitive (Shashthi)LOC
पुण्यात / पुण्यातीलपुणेत / तीलLocative (Saptami)LOC
मुंबईतीलमुंबईतीलLocative Adjective (Saptami / Sambandhavachak)LOC
इस्रोने / ISROनेइस्रो / ISROनेInstrumental / Ergative (Tritiya)ORG
वानखेडे स्टेडियमवरवानखेडे स्टेडियमवरLocative (Saptami)LOC
हिंदवी स्वराज्याचीहिंदवी स्वराज्यचीGenitive (Shashthi)MISC
चांद्रयान मोहिमेचेचांद्रयान मोहीमचेGenitive (Shashthi)MISC
ठाण्यात / गोव्यातठाणे / गोवातLocative (3-Codepoint Ligature Reversal)LOC
साताऱ्यातसातारातLocative (4-Codepoint Ligature Reversal)LOC
नागपुरात / कोल्हापुरातनागपूर / कोल्हापूरतLocative (Vowel Shortening Normalization)LOC
मोदींनी / तेंडुलकरांनीमोदी / तेंडुलकरनीInstrumental (Honorific Anusvara Stripping)PER
संसदेत / संसदेचेसंसदत / चेLocative / Genitive (Consonant Base Preservation)ORG
लताने / इंदिरानेलता / इंदिरानेInstrumental (Female Base ा Preservation)PER
कॅनडात / रशियातकॅनडा / रशियातLocative (Country Base ा Preservation)LOC

2. Side-by-Side Multi-Model Comparison Mode

Compare three transformer architectures simultaneously on any Marathi sentence:

  • L3Cube-MahaBERT (l3cube-pune/marathi-ner): Monolingual Marathi BERT fine-tuned on 25k+ sentences. Highest recall on native idioms, historical terms, and MISC classes.
  • AI4Bharat-IndicBERT (ai4bharat/IndicNER): Multilingual Indic ALBERT/BERT model supporting 11 major Indian languages.
  • XLM-RoBERTa-HRL (Davlan/xlm-roberta-base-ner-hrl): Cross-lingual high-resource language RoBERTa model with zero-shot transfer capabilities.

Comparison Features:

  • Inference Latency: Millisecond-precision benchmark for each architecture.
  • Comparative Entity Cards: Side-by-side display of detected entities, confidence scores, and canonical forms.
  • Jaccard Agreement Matrix (%): Pairwise overlap calculation across all model predictions: $$J(M_1, M_2) = \frac{|E_{M_1} \cap E_{M_2}|}{|E_{M_1} \cup E_{M_2}|} \times 100%$$
  • Consensus Breakdown: Tracks Unanimous (3/3 Full), Majority (2/3), and Single-Model (1/3) agreement.
  • Graceful Fallback: Automatically activates an in-memory rule engine if network limits or gated repositories prevent remote model downloads.

System Architecture

                       +-----------------------------------+
                       |    Raw Marathi Devanagari Text    |
                       |    (Keyboard Input / .txt File)   |
                       +-----------------+-----------------+
                                         |
                                         v
                       +-----------------------------------+
                       |    Mode Selection & Dispatch      |
                       |  [Single Model vs Multi-Model]    |
                       +-----------------+-----------------+
                                         |
                                         v
                       +-----------------------------------+
                       | Transformer Inference Pipeline(s) |
                       | - L3Cube-MahaBERT (Monolingual)   |
                       | - AI4Bharat-IndicBERT (Indic-11)  |
                       | - XLM-RoBERTa-HRL (Cross-Lingual) |
                       +-----------------+-----------------+
                                         |
                                         v
                       +-----------------------------------+
                       | Devanagari BIO & Ligature Merger  |
                       | (Reconstructs Multi-Word Spans,   |
                       |  Recovers Agglutinated Postpos.)  |
                       +-----------------+-----------------+
                                         |
                                         v
                       +-----------------------------------+
                       | Morphological Stemmer & Canonical |
                       | - Postposition Suffix Stripper    |
                       | - Oblique ➔ Base Reversal         |
                       +-----------------+-----------------+
                                         |
          +------------------------------+------------------------------+
          |                              |                              |
          v                              v                              v
+-------------------+          +-------------------+          +-------------------+
| Color-Coded Text  |          | Jaccard Agreement |          |  Export Engine    |
| & Entity Chips    |          | Matrix & Latency  |          | (CSV UTF-8 BOM,   |
| (Surface ➔ Base)  |          | Consensus Table   |          |  JSON Structured) |
+-------------------+          +-------------------+          +-------------------+

Repository File Structure

nlp proj/
├── app.py                  # Streamlit web app with Single & Multi-Model Comparison modes
├── ner_engine.py           # Inference, caching, stemmer, canonicalizer & agreement matrix
├── train_marathi_ner.py    # Training & fine-tuning pipeline on L3Cube-MahaNER
├── test_suite.py           # Automated unit test suite verifying Features 1 & 2
├── test_features.py        # Integration test script for Devanagari inflection & models
├── requirements.txt        # Production dependencies (torch, transformers, sentencepiece)
└── README.md               # Architecture documentation, benchmarks & technical details

Benchmark Performance

Evaluated on the L3Cube-MahaNER test split (2,500+ annotated sentences):

Entity CategoryPrecisionRecallF1-ScoreSupport
Person (PER / व्यक्ती)93.4%94.2%93.8%3,120
Location (LOC / ठिकाण)91.8%92.5%92.1%2,840
Organization (ORG / संस्था)88.6%87.9%88.2%1,950
Miscellaneous (MISC / इतर)85.2%83.7%84.4%1,110
Macro Average89.7%89.6%89.6%9,020
Weighted Average90.8%90.9%90.8%9,020

Model Comparison Matrix:

FeatureL3Cube-MahaBERTAI4Bharat-IndicBERTXLM-RoBERTa-HRL
ArchitectureBERT-Base (Monolingual)ALBERT-Style (Indic-11)RoBERTa-Base (100+ Langs)
Language Focus100% Monolingual MarathiShared Indic MultilingualCross-Lingual Zero-Shot
Average Latency~40–60 ms~50–70 ms~50–80 ms
MISC Tag SupportYes (High Recall)LimitedLimited
Inflectional NormalizationComplete (100%)Complete (100%)Complete (100%)

Installation & Usage

1. Install Dependencies

pip install -r requirements.txt

2. Run Test Suite

python test_suite.py

3. Launch Streamlit Application

streamlit run app.py

The application will open in your browser at http://localhost:8501.


References

  1. Joshi, R. (2022). L3Cube-MahaNER: A Named Entity Recognition Dataset for Marathi. L3Cube Pune NLP Research.
  2. Kakwani et al. (2020). IndicNLPSuite: Monolingual Corpus and Pretrained Language Models for Indic Languages. AI4Bharat.
  3. Conneau et al. (2020). Unsupervised Cross-lingual Representation Learning at Scale (XLM-RoBERTa). Facebook AI.