Skip to main content

A machine translation library utilizing m2m100 models, equipped with features for generating diverse verb variants via VerbNet and Conditional Beam Search to enrich Virtual Assistant training sets.

Project description

Multiverb IVA MT

Generating diverse verb variants with VerbNet and Conditional Beam Search for enhanced performance of Intelligent Virtual Assistants (IVA) training set translation.

Installation

You can easily install multiverb_iva_mt from PyPI:

pip install iva_mt

This command will download and install the latest version of multiverb_iva_mt along with its required dependencies.

Usage

from iva_mt.iva_mt import IVAMT

translator = IVAMT(src_lang="en", tgt_lang="pl")
#for single-best translation
translator.translate("set the temperature on <a>my<a> thermostat")
#for multi-variant translation
translator.generate_alternative_translations("set the temperature on <a>my<a> thermostat")

Available languages (en2xx): pl, es, de, fr, pt, sv, zh, ja, tr, hi

To use GPU and batching, provide information about device:

IVAMT(src_lang="en", tgt_lang="pl", device="cuda:0", batch_size=16)

On V100 this allows to translate ~100 sentences/minute.

To use baseline M2M100:

IVAMT(src_lang="en", tgt_lang="pl", model_name="facebook/m2m100_418M")

To load a local model from an archive:

# If the model archive is located at /path/to/your/model.tgz, it will be automatically extracted
# to the ~/.cache/huggingface/hub directory. Specify this path using the `model_name` parameter.
IVAMT(src_lang="en", tgt_lang="pl", model_name="/path/to/your/model.tgz")

Note: When loading a local model, the tokenizer used will still be cartesinus/iva_mt_wslot-m2m100_418M-{src_lang}-{tgt_lang} to ensure compatibility and optimal performance.

Training M2M100 Model

In this repository, we provide a script train.py to facilitate the training of M2M100 models on your specified translation tasks. To run the training script, it is recommended to have a GPU for computational acceleration. When training on Google Colab, it's advisable to use an A100 GPU as V100 might not have sufficient memory.

Prerequisites

  • Ensure that you have installed the necessary libraries by running the following command:
pip install transformers datasets sacrebleu

Usage

  1. Customize your training configuration by creating a JSON file (e.g., config/iva_mt_wslot-m2m100_418M-en-pl.json). In this file, specify the source language, target language, learning rate, weight decay, number of training epochs, and other relevant parameters.

  2. Execute the training script by running the following command:

python train.py --config config/iva_mt_wslot-m2m100_418M-en-pl.json

Configuration File

The configuration file should contain the following parameters:

  • src_lang: Source language code (e.g., "en" for English).
  • tgt_lang: Target language code (e.g., "pl" for Polish).
  • learning_rate: Learning rate for the optimizer.
  • weight_decay: Weight decay for the optimizer.
  • num_train_epochs: Number of training epochs.
  • model_space: The namespace for the model.
  • model_name: The name of the model.
  • dataset: The name of the dataset to be used for training.

Example Configuration:

{
    "src_lang": "en",
    "tgt_lang": "pl",
    "learning_rate": 5e-5,
    "weight_decay": 0.01,
    "num_train_epochs": 3,
    "model_space": "facebook",
    "model_name": "m2m100_418M",
    "dataset": "wmt16"
}

Running on Google Colab

If you are running the script on Google Colab, ensure to switch to a runtime with a GPU for better performance. It is recommended to use an A100 GPU as V100 might have memory limitations depending on the size of the model and the dataset.

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

iva_mt-0.2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iva_mt-0.2.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file iva_mt-0.2.0.tar.gz.

File metadata

  • Download URL: iva_mt-0.2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.13

File hashes

Hashes for iva_mt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 47b10d73e43168677eeea76d97c048cb074e129c22fa06f885100acc630a475f
MD5 36711338eb193147e0d94c7737ac43a2
BLAKE2b-256 4af05a44c8836127b6552e701c9676b1e64af8659bd7631bf8883564996b70c7

See more details on using hashes here.

File details

Details for the file iva_mt-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: iva_mt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.13

File hashes

Hashes for iva_mt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e24166ef8938b78ad92eea3961e99b75f42701af63d61bba49467c05010d95e
MD5 46b5639d865ad495c1b249fe4284c7f7
BLAKE2b-256 b7ccca699c84c1f0ba2092e36f2a1c3125d8be8d1f473d78f1a91f5549a8429f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page