Skip to main content

Byte Pair Encoding for Natural Language Processing.

Project description

test coverage
test results

Byte Pair Encoding for Natural Language Processing.


Install with pip:

pip install bpelib


Uninstall with pip:

pip uninstall bpelib


Import the BPE class.
from bpelib import bpe
Learn encoding on construct or at a later time:
bpe = BPE(['start', 'learning', 'now'])
# or ...
bpe.learn_encoding(['start', 'learning', 'now'])
To encode or decode a word, simply call the BPE object.
encoded = bpe('encode')  # '<w/> e n c o d e </w>'
decoded = bpe(encoded)  # 'encode'
assert 'encode' == decoded
You can call encode or decode explicitly, too.
encoded = bpe.encode('encode')  # '<w/> e n c o d e </w>'
decoded = bpe.decode(encoded)  # 'encode'
assert 'encode' == decoded
You can also specify maximum vocabulary size and the used encoding.
bpe = BPE(max_vocab_size=1024, encoding='ascii')

Project details

Download files

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

Files for bpelib, version v0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size bpelib-v0.1.2.tar.gz (1.6 MB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page