Skip to main content

Sanskrit NLP library grounded in Pāṇinian grammar. Deterministic, Graph-based, and Neuro-symbolic.

Project description

Panini-NLP

A Deterministic, Graph-based, Neuro-symbolic implementation of Pāṇini's Grammar.

panini-nlp is a Python library that decodes the Aṣṭādhyāyī not as a static text, but as a computable Cyclic Directed Graph. It provides the complete structural context of the grammar—every Sūtra and Dhātu—alongside deterministic engines for Sandhi, Prosody, and Phonetics.

📖 About

This project decodes the 2,500-year-old Aṣṭādhyāyī as the world's first Deterministic Generative AI.

Pāṇini's grammar is not a mere set of rules; it is a formal generative system that produces infinite valid Sanskrit words from finite roots using a highly compressed, algebraic source code. panini-nlp implements this architecture:

  1. Universal Registry: A digital structural map of all 3,996 Sūtras and ~2,000 Dhātus.
  2. Deterministic Engine: Mathematical implementation of Sandhi (phonetics) and Chandas (prosody).
  3. Neuro-Symbolic Bridge: A GNN layer to handle ambiguity (Vipratisedha) where the deterministic path branches.

We are not inventing AI for Sanskrit; we are decoding the algorithm that was already written.


🚀 Key Features

1. The Complete "Source Code"

Unlike other tools that implement only a few rules, panini-nlp contains the Full Registry:

  • 3,996 Sūtras: Every rule from the Aṣṭādhyāyī is present as a Python function stub in panini_nlp/rules/.
  • ~2,000 Dhātus: Every root from the Dhātupāṭha is registered in panini_nlp/roots/.
  • Maheshvara Sutras: Implements the "Prime Number Architecture" (71.4% prime density) for phoneme compression.

2. Hybrid Neuro-Symbolic Architecture

  • Symbolic Core: Deterministic engines for Sandhi (Euphonic Junction) and Chandas (Prosody).
  • Neural Guidance: A Graph Neural Network (GNN) layer (panini_nlp/gnn) to resolve rule conflicts (Vipratisedha) by learning the graph topology.

3. "Seed Kernel" Efficiency

  • The core logic fits in < 50KB.
  • The entire structural knowledge base is generated from raw source texts.

📦 Installation

# Clone the repository
git clone https://github.com/meru-os/panini-nlp.git
cd panini-nlp

# Install mostly-pure Python core
pip install .

# Install with Neural Network support (PyTorch)
pip install .[gnn]

🛠️ Usage Examples

1. Deterministic Sandhi

Apply formal rules like Akaḥ Savarṇe Dīrghaḥ (6.1.101).

from panini_nlp import SandhiEngine

sandhi = SandhiEngine()
result = sandhi.apply("dev", "alaya")
print(result) 
# Output: devālaya (Rule 6.1.101 applied)

2. Derivation Simulation (Prakriya)

Trace the path of a word through the grammar graph.

# Run the included demo script
# python3 examples/derive_brahman.py

from panini_nlp.rules import registry as rule_registry

# Access Rule 1.1.1 (Growth Definitions)
rule = rule_registry.get("1.1.1")
print(f"{rule.id}: {rule.text}") 
# Output: 1.1.1: vṛddhir ādaic

3. Prosody Analysis (Chandas)

Analyze the binary rhythm of a verse (Laghu/Guru).

from panini_nlp import ChandasAnalyzer

analyzer = ChandasAnalyzer()
meter = analyzer.analyze("dharmakṣetre kurukṣetre samavetā yuyutsavaḥ")
print(meter.pattern)
# Output: G L G G L G G G ... (Binary Stream)

📂 Project Structure

panini-nlp/
├── panini_nlp/
│   ├── rules/          # 3996 Auto-generated Sutra stubs (Adhyaya 1-8)
│   ├── roots/          # ~2000 Auto-generated Root definitions (Gana 1-10)
│   ├── sandhi.py       # Deterministic Sandhi Engine
│   ├── chandas.py      # Pingala's Binary Prosody Algorithms
│   ├── maheshvara.py   # Prime Number Phonetic Analysis
│   ├── gnn/            # Graph Neural Network Models (PyTorch)
│   ├── data/           # Raw Source Texts (Ashtadhyayi.txt, Dhatupatha.txt)
│   └── validator.py    # Pipeline Orchestrator
├── examples/
│   ├── derive_brahman.py # Paper Example: Derivation of "Brahman"
│   └── derive_shuklam.py # Demo Example: "Shuklam Baradharam" analysis
├── requirements.txt
└── setup.py

License

MIT License. Free for research and education.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

panini_nlp-0.1.0.tar.gz (873.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

panini_nlp-0.1.0-py3-none-any.whl (882.0 kB view details)

Uploaded Python 3

File details

Details for the file panini_nlp-0.1.0.tar.gz.

File metadata

  • Download URL: panini_nlp-0.1.0.tar.gz
  • Upload date:
  • Size: 873.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for panini_nlp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 035620ad28e44a381737bdb5e40e134357696579cf68d223178bd3d46716e258
MD5 4e5b52b09f596eacb9ee6ec97dac6976
BLAKE2b-256 3b363209008a3b25c2ed6ad520720e9b73860581647e93e3380a9a9b3aa14247

See more details on using hashes here.

File details

Details for the file panini_nlp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: panini_nlp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 882.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for panini_nlp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da8f05acbad6250d2892a27c0593508d725d6e217fd64cc7f43cddf7d71470fd
MD5 0db03389c52e52e5aee320dbfbe5c4ce
BLAKE2b-256 d8eb7748d460c0c3bd0ce82996de9ccd34838eb0a3ffee6bd13260fe18494991

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page