Skip to main content

A modern, high-performance Python library for Bengali dictionary operations.

Project description

Shobdo Banner

শব্দ | Shobdo

A high-performance Bengali dictionary library for Python

PyPI version Python Versions License Code Style: Ruff

45,000+ words • SQLite backend • 384D neural embeddings • Pydantic models


Shobdo Features

Overview

Shobdo provides fast, type-safe access to a comprehensive Bengali dictionary. The data is pre-compiled into SQLite and indexed, eliminating the startup cost of loading JSON into memory.

Metric JSON Loading Shobdo
Startup time ~1,200ms ~6ms
Memory footprint ~180MB <5MB
Return type dict Pydantic Word

Installation

pip install shobdo

For semantic search (optional):

pip install shobdo numpy sentence-transformers

Quick Start

from shobdo import Shobdo

d = Shobdo()
word = d.search("স্বাধীনতা")

print(word.word)                # স্বাধীনতা
print(word.pronunciation)       # শ্বাধীন্‌তা
print(word.meanings)            # ['স্বাধীন হওয়ার ভাব', ...]
print(word.english_translation) # Independence / Freedom
print(word.part_of_speech)      # বিশেষ্য

API Reference

search(word: str) -> Optional[Word]

Exact match lookup.

word = d.search("অ")
# Returns Word object or None

search_fuzzy(query: str, max_distance: int = 2) -> List[Word]

Levenshtein distance-based fuzzy matching. Useful for handling typos.

# User types "অরিন" instead of "অঋণ"
matches = d.search_fuzzy("অরিন", max_distance=2)

for m in matches:
    print(m.word, m.english_translation)
# অঋণ Debt-free
# অরণ্য Forest

search_english(query: str) -> List[Word]

Search by English translation (substring match).

words = d.search_english("freedom")

for w in words:
    print(w.word, w.english_translation)
# স্বাধীনতা Independence / Freedom
# মুক্তি Freedom / Release

lookup(query: str) -> List[Word]

Partial match on Bengali headwords.

words = d.lookup("ঋণ")

for w in words[:5]:
    print(w.word)
# ঋণ
# ঋণগ্রস্ত
# ঋণদাতা
# ঋণপত্র
# অঋণ

get_random() -> Word

Returns a random word from the dictionary.

word = d.get_random()
print(f"{word.word}: {word.meanings[0]}")

stats() -> Dict

Returns dictionary statistics.

print(d.stats())
# {'total_words': 45630, 'backend': 'sqlite', 'semantic_search': True}

Semantic Search

Semantic Intelligence

Shobdo includes pre-computed 384-dimensional embeddings (via paraphrase-multilingual-MiniLM-L12-v2) for all words. This enables meaning-based search.

search_semantic(query: str, top_k: int = 10) -> List[Tuple[Word, float]]

Search by concept. The query is encoded at runtime and compared against all word embeddings.

results = d.search_semantic("happiness and joy", top_k=5)

for word, score in results:
    print(f"{word.word}: {word.english_translation} ({score:.2f})")
# হর্ষোদয়: Rise of joy (19.86)
# আনন্দকন্দ: Root of joy (19.43)
# হর্ষাবিষ্ট: Overwhelmed with joy (19.26)
# সুখানুভব: Feeling of happiness (18.77)
# আনন্দ: Joy / Happiness (18.46)

Works cross-lingually (English query → Bengali results).


find_similar(word: str, top_k: int = 10) -> List[Tuple[Word, float]]

Find synonyms using pre-computed embeddings. No model inference required at runtime.

synonyms = d.find_similar("আনন্দ", top_k=5)

for word, score in synonyms:
    print(f"{word.word}: {word.english_translation}")
# হর্ষোদয়: Rise of joy
# তোষ: Satisfaction / Pleasure
# আনন্দকন্দ: Root of joy
# হরষিত: Delighted / Joyful
# শর্ম: Happiness / Shelter

Data Models

from shobdo.models import Word, Etymology

Word

Field Type Description
word str Bengali headword
pronunciation Optional[str] Phonetic pronunciation
part_of_speech Optional[str] Grammatical category
meanings List[str] List of definitions
english_translation Optional[str] English equivalent
examples List[str] Usage examples
etymology Optional[Etymology] Word origin

Etymology

Field Type Description
source_language Optional[str] e.g., সংস্কৃত, আরবি
derivation Optional[str] Morphological breakdown

Architecture

Architecture

Build-time artifacts:

  • dictionary.db (~15MB) — SQLite database with indexed word and english_translation columns
  • embeddings.npy (~67MB) — 45,630 × 384 float32 array
  • word_index.json (~3MB) — Vector index to database ID mapping

Runtime:

  • SQLite queries for exact/fuzzy/partial/reverse search
  • NumPy dot product for semantic similarity

Development

git clone https://github.com/InanXR/Shobdo-Library
cd Shobdo-Library
pip install -e ".[dev]"

# Run tests
pytest tests/

# Rebuild database
python scripts/build_db.py

# Regenerate embeddings (~10 min)
python scripts/generate_embeddings.py

Requirements

  • Python 3.9+
  • Core: pydantic
  • Semantic search: numpy, sentence-transformers

License

Apache License 2.0


Acknowledgments

Data source: ProjectShobdo


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

shobdo-0.1.0.tar.gz (71.3 MB view details)

Uploaded Source

Built Distribution

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

shobdo-0.1.0-py3-none-any.whl (71.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shobdo-0.1.0.tar.gz
  • Upload date:
  • Size: 71.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for shobdo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3e97c57fbc0bc0507f72cf943434abb783fcfd97773afbcb9aedda0145e1a7ae
MD5 f9172ac7bc21edf72313d6ee62cd7371
BLAKE2b-256 85f2c6902ffbc2d0a243788a5c41420a725d6b7ab488b6a498ca532c019bbe9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shobdo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 71.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for shobdo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dd457297ab0a36178d3ba662ccbba9c00e8ce976883eab7f2f493e01a1227e5
MD5 653ab6adbb18199b4bc2506b562c4589
BLAKE2b-256 5b9adaf25aac8f3e600ed629596d7ff43075d18a80ddbe395ed79ed106730763

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