Skip to main content

A Byte Pair Encoding (BPE) library for the Bengali language.

Project description

Bengali BPE

bengali_bpe is a Python library for Byte Pair Encoding (BPE) specifically designed for the Bengali language.
It enables you to train BPE models on Bengali text, encode words and sentences into subword units, and decode them back.
This helps improve NLP model performance for Bengali text processing, tokenization, and embedding preparation.


✨ Features

  • 🧠 Train a Byte Pair Encoding model on Bengali text corpus
  • 🔠 Encode Bengali sentences or words into subword tokens
  • 🔁 Decode subword tokens back into full Bengali words
  • ⚙️ Simple, lightweight, and easy to integrate into your NLP pipelines
  • 🪶 Supports Bengali Unicode normalization

📦 Installation

Install directly from PyPI:

pip install bengali_bpe

from bengali_bpe import BengaliBPE
from bengali_bpe.utils import normalize_bengali_text

# Sample Bengali corpus
corpus = [
    "বাংলা ভাষা সুন্দর",
    "আমি বাংলা পড়ি",
    "বাংলা ভয়ানক নয়"
]

# Normalize text
corpus = [normalize_bengali_text(sentence) for sentence in corpus]

# Initialize and train the model
bpe = BengaliBPE(num_merges=10)
bpe.train(corpus)

# Encode a sentence
sentence = "বাংলা ভাষা সুন্দর"
encoded = bpe.encode(sentence)
print("Encoded:", encoded)

# Decode back
decoded = bpe.decode(encoded)
print("Decoded:", decoded)


Encoded: [['বা', 'ংলা'], ['ভা', 'ষা'], ['সু', 'ন্', 'দর']]
Decoded: বাংলা ভাষা সুন্দর


from bengali_bpe import BengaliBPE

bpe = BengaliBPE(num_merges=5)
bpe.train(["বাংলা ভাষা সুন্দর"])
encoded_word = bpe.encode_word("বাংলা")
print("Encoded Word:", encoded_word)

decoded_word = bpe.decode([encoded_word])
print("Decoded Word:", decoded_word)


Encoded Word: ['বা', 'ংলা']
Decoded Word: বাংলা

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

bengali_bpe-0.1.2.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

bengali_bpe-0.1.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file bengali_bpe-0.1.2.tar.gz.

File metadata

  • Download URL: bengali_bpe-0.1.2.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for bengali_bpe-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d69a7b5ea2cf788010ea2e531fbab7eea1d2f1dbe685644ed89a3305dde5f3e6
MD5 7dda2c28abb7ae253a2b6cf9813558cb
BLAKE2b-256 d4a16f786f8a9a54e6bf85ec7b0f1d7e9c704ab8cdbef204602932b56880cd39

See more details on using hashes here.

File details

Details for the file bengali_bpe-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: bengali_bpe-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for bengali_bpe-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eb133d5ae033093ac1c3b9ca2ee337ec0c25d0e3cf5bd9c3e44847b10566825e
MD5 a06f851f71166a49a8f11710a2778947
BLAKE2b-256 e8872554cb0659b95aea96c8ab0381aa2bc74650e1d32f08d50bb3d74c84b712

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