Python¶
This document describes python bindings from bergamot-translator and a batteries included python package supplied for easy use. The library also provides entry point via a command-line making it easier for the average user to get started.
As bergamot-translator is built on top of marian, the python API should also work as python bindings for marian trained models, if they need to be integrated into python code-bases.
Disclaimer: The package is still in early stages and unstable. Functions and classes might move around quite fast. Use at your own risk.
Command Line Interface¶
usage: bergamot [-h] {translate,download,ls} ...
actions¶
The following actions are available through the bergamot package
- action
Possible choices: translate, download, ls
To obtain help on how to run these actions supply <cmd> -h.
Sub-commands¶
translate¶
translate using a given model. Multiple models mean pivoting
bergamot translate [-h] -m MODEL [MODEL ...] [-r {browsermt,opus}]
[--num-workers NUM_WORKERS] [--log-level LOG_LEVEL]
[--html HTML] [--alignment ALIGNMENT]
[--quality-scores QUALITY_SCORES]
Named Arguments¶
- -m, --model
Path to model file(s) to use in forward or pivot translation
- -r, --repository
Possible choices: browsermt, opus
Repository to download model from
Default: “browsermt”
- --num-workers
Number of worker threads to use to translate
Default: 4
- --log-level
Set verbosity level of logging: trace, debug, info, warn, err(or), critical, off
Default: “off”
response-options¶
- --html
Default: False
- --alignment
Default: False
- --quality-scores
Default: False
download¶
Download models from the web.
bergamot download [-h] [-m MODEL] [-r {browsermt,opus}]
Named Arguments¶
- -m, --model
Fetch model with given code. Use ls to list available models. Optional, if none supplied all models are downloaded.
- -r, --repository
Possible choices: browsermt, opus
Repository to download model from
Default: “browsermt”
ls¶
List available models.
bergamot ls [-h] [-r {browsermt,opus}]
Named Arguments¶
- -r, --repository
Possible choices: browsermt, opus
Repository to list models from
Default: “browsermt”
Module Documentation¶
-
bergamot.
REPOSITORY
= <bergamot.repository.Aggregator object>¶ REPOSITORY is a global object that aggregates multiple model-providers to provide a (model-provider: str, model-code: str) based query mechanism to get models.
bergamot-translator¶
The following components are exported from C++ via python-bindings and form library primitives that can be used to build translation workflows.
-
class
bergamot.
Service
¶ -
modelFromConfig
(self: bergamot._bergamot.Service, arg0: str) → marian::bergamot::TranslationModel¶
-
modelFromConfigPath
(self: bergamot._bergamot.Service, arg0: str) → marian::bergamot::TranslationModel¶
-
pivot
(self: bergamot._bergamot.Service, arg0: marian::bergamot::TranslationModel, arg1: marian::bergamot::TranslationModel, arg2: bergamot._bergamot.VectorString, arg3: bergamot._bergamot.ResponseOptions) → bergamot._bergamot.VectorResponse¶
-
translate
(self: bergamot._bergamot.Service, arg0: marian::bergamot::TranslationModel, arg1: bergamot._bergamot.VectorString, arg2: bergamot._bergamot.ResponseOptions) → bergamot._bergamot.VectorResponse¶
-
-
class
bergamot.
TranslationModel
¶
Model Inventory¶
-
class
bergamot.repository.
Repository
¶ An interface for several repositories. Intended to enable interchangable use of translateLocally and Mozilla repositories for usage through python.
-
abstract
download
(model_identifier: str)¶
-
abstract
model
(model_identifier: str) → Any¶ returns entry for the for available models
-
abstract
modelConfigPath
(model_identifier: str) → str¶ returns modelConfigPath for for a given model-identifier
-
abstract
models
() → List[str]¶ returns identifiers for available models
-
abstract property
name
¶
-
abstract
update
()¶ Updates the model list
-
abstract
-
class
bergamot.repository.
TranslateLocallyLike
(name, url)¶ This class implements Repository to fetch models from translateLocally. AppDirs is used to standardize directories and further specialization happens with translateLocally identifier.
-
download
(model_identifier: str)¶
-
model
(model_identifier: str) → Any¶ returns entry for the for available models
-
modelConfigPath
(model_identifier: str) → str¶ returns modelConfigPath for for a given model-identifier
-
models
(filter_downloaded: bool = True) → List[str]¶ returns identifiers for available models
-
property
name
¶
-
update
() → None¶ Updates the model list
-
Utilities¶
-
bergamot.utils.
patch_marian_for_bergamot
(marian_config_path: PathLike, bergamot_config_path: PathLike, quality: bool = False)¶ Accepts path to a config-file from marian-training and followign quantization and adjusts parameters for use in bergamot.