BPEmb provides byte-pair encodings (BPE) from raw text and maps subword units to pre-trained embeddings for 275 languages. It's designed for NLP tasks requiring efficient subword tokenization and embedding. The current version is 0.3.6, with releases occurring sporadically based on updates to models or features.
pip install bpembVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize BPEmb, encode a sentence into subwords, and retrieve embeddings for individual words or lists of words. The first initialization for a specific (lang, dim, vs) combination will trigger a large model download.
Ensure stable internet connection and sufficient disk space. Models are cached locally for subsequent uses. Consider using smaller `dim` or `vs` values if disk space is a concern.
If encountering `MemoryError` or performance issues, try reducing the `dim` (embedding dimension) and/or `vs` (vocabulary size) parameters during `BPEmb` initialization. Process large texts in batches if possible.
Be aware of the distinct behaviors: `encode` will break unknown words into subwords using BPE, while `embed` will yield a zero vector for any word not in its vocabulary. Handle OOV words explicitly in your application logic based on the desired outcome.
Verify your internet connection. Check firewall settings to ensure Python can make outbound connections. If behind a proxy, configure proxy settings for your environment or Python requests.
Ensure the `~/.cache/bpemb` directory (or your custom cache path) is intact and accessible. If files are missing, `BPEmb` will attempt to re-download them automatically upon initialization.
Consult the `bpemb` documentation or its source code for an accurate list of supported language codes. Ensure the language code matches one of the officially available options (e.g., 'en' for English, 'es' for Spanish).
Reduce the `dim` (embedding dimension) and/or `vs` (vocabulary size) parameters when initializing `BPEmb`. Consider processing text in smaller, manageable batches if possible to distribute memory load.