Builds a parallel text ePub with sentences aligned side-by-side from two ePubs of the same book in different languages.
bbb -s original.epub -t translation.epub
or,
online on HuggingFace (blocked in some regions, use proxy/VPN) (also, quite slow)
Languages restricted to that of the libraries and models used. Basically, there are 3 stages, each supporting their own set of languages. I tried to make bbb support as many languages as possible, so it mostly depends on configurable models.
- Language detector: lingua supports 75 languages (but you can specify languages manually to skip this)
- Sentence splitter: the simple one (
--simple-split) supports 24 languages; Wtpsplit depends on a model (--split-model) and currently supports 85 languages. Simple splitter is enough for regular books in some European language. - Sentence alignment: bertalign depends on a model (
--align-model) and currently supports 109 languages.
You can just give it a try and see if it works with your languages. Chances are it would even if some of the modules don't support them. That's how it's supposed to work anyway.
If you have a graphic card:
pip install "bbb[gpu] @ git+https://github.com/kerivin/bilingual-book-builder.git"
If you don't:
pip install "bbb[cpu] @ git+https://github.com/kerivin/bilingual-book-builder.git"
Development on Linux
- Python (tested on 3.14)
- pip
- git
git clone --recurse-submodules https://github.com/kerivin/bilingual-book-builder.git
cd bilingual-book-builder
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
python -m bbb --help
Run tests locally:
pytest tests/ -v
AMD ROCm support
# Install ROCm Torch
source .venv/bin/activate
pip install --upgrade pip
pip install --force-reinstall torch --index-url https://download.pytorch.org/whl/rocm7.0
# For running it
export HSA_OVERRIDE_GFX_VERSION=10.3.0 # Sample value for RX 6700 XT, only relevant for GPUs that require an override.
export LD_LIBRARY_PATH=/opt/rocm/core-7.14/lib:$LD_LIBRARY_PATH| Command | Description |
|---|---|
-s SOURCE--source SOURCE |
Path to source (original) EPUB |
-t TARGET--target TARGET |
Path to target (translation) EPUB |
-sl LANG--source-language LANG |
Source (original) language code. Auto-detect if omitted |
-tl LANG--target-language LANG |
Target (translation) language code. Auto-detect if omitted |
-o FILENAME--output FILENAME |
New EPUB name. Default: bilingual |
-m--manual |
Match chapters manually in the interactive mode. Default: off |
--threads THREADS |
Number of parallel threads. Default: 1 |
--auto-threshold THRESHOLD |
Similarity threshold value (0.0-1.0) for chapter auto-matching. Default: 0.6 |
--only {auto-match,extract} |
Only show extracted chapters or auto-matched chapters without generating a new EPUB |
--keep-source-chapters |
Keep source (original) chapters with no matching target (translation) chapters. Default: off |
--keep-target-chapters |
Keep target (translation) chapters with no matching source (original) chapters. Default: off |
--cover {source, target} |
Which book's cover to copy for the new EPUB. Default: source |
--align-model |
Name or path to sentence embedding model. Default: LaBSE |
--split-model |
Name or path to text-to-sentences splitter model. Default: sat-3l |
--simple-split |
Use simple sentence splitter (not the --split-model one) which works faster but with fewer languages.Default: off |
-v {silent,progress,verbose}--verbosity {silent,progress,verbose} |
How verbose logging is. Default: progress |
bbb --help
bbb -s original.epub -t translation.epub
bbb -s original.epub -t translation.epub -sl en -tl ru --simple-split --auto-threshold 0.6 --threads 4 --keep-target-chapters
- Specify languages with
-sland-tl - Set
--threads - Use
--simple-split(if simple-split supports your languages)
- Specify languages with
-sland-tl - Don't use
--simple-split - Optionally, you can use advanced aligner and splitter models. For now, they are LaBSE and sat-3l, but you can find models that work better with your languages and specify them with
--align-modeland--split-model - If chapters were mapped incorrectly, map them manually with
-mor keep auto-matching with a different--auto-threshold. To see how the similarity threshold affects the chapters mapping, use--only auto-match
The quality of the new book depends on the quality of the provided books. Some have a weird table of contents or don't have it at all, some duplicate a chapter title at the beginning of the chapter, some have no metadata, etc. Make sure the two books to merge are not broken.
The code is AI-assisted.
- Custom classes from the original CSS files are ignored
- Some readers still display the table borders even thought they are transparent
- Now I only build side-dy-side horizontal alignment, maybe I should add translation-after-original vertical alignment
- Convert other formats to EPUB