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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d69a7b5ea2cf788010ea2e531fbab7eea1d2f1dbe685644ed89a3305dde5f3e6
|
|
| MD5 |
7dda2c28abb7ae253a2b6cf9813558cb
|
|
| BLAKE2b-256 |
d4a16f786f8a9a54e6bf85ec7b0f1d7e9c704ab8cdbef204602932b56880cd39
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb133d5ae033093ac1c3b9ca2ee337ec0c25d0e3cf5bd9c3e44847b10566825e
|
|
| MD5 |
a06f851f71166a49a8f11710a2778947
|
|
| BLAKE2b-256 |
e8872554cb0659b95aea96c8ab0381aa2bc74650e1d32f08d50bb3d74c84b712
|