Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Latest commit

 

History

History
115 lines (77 loc) · 4.23 KB

translation.rst

File metadata and controls

115 lines (77 loc) · 4.23 KB

Translation

The Task

Translation is the task of translating text from a source language to another, such as English to Romanian. This task is a subset of Sequence to Sequence tasks, which requires the model to generate a variable length sequence given an input sequence. In our case, the task will take an English sequence as input, and output the same sequence in Romanian.


Example

Let's look at an example. We'll use WMT16 English/Romanian, a dataset of English to Romanian samples, based on the Europarl corpora. The data set contains a train.csv and valid.csv. Each CSV file looks like this:

input,target
"Written statements and oral questions (tabling): see Minutes","Declaraţii scrise şi întrebări orale (depunere): consultaţi procesul-verbal"
"Closure of sitting","Ridicarea şedinţei"
...

In the above the input/target columns represent the English and Romanian translation respectively. Once we've downloaded the data using ~flash.core.data.download_data, we create the ~flash.text.seq2seq.translation.data.TranslationData. We select a pre-trained backbone to use for our ~flash.text.seq2seq.translation.model.TranslationTask and finetune on the WMT16 data. The backbone can be any Seq2Seq translation model from HuggingFace/transformers.

Note

When changing the backbone, make sure you pass in the same backbone to the ~flash.text.seq2seq.translation.data.TranslationData and the ~flash.text.seq2seq.translation.model.TranslationTask!

Next, we use the trained ~flash.text.seq2seq.translation.model.TranslationTask for inference. Finally, we save the model. Here's the full example:

../../../flash_examples/translation.py

To learn how to view the available backbones / heads for this task, see backbones_heads.


Flash Zero

The translation task can be used directly from the command line with zero code using flash_zero. You can run the above example with:

flash translation

To view configuration options and options for running the translation task with your own data, use:

flash translation --help

Serving

The ~flash.text.seq2seq.translation.model.TranslationTask is servable. This means you can call .serve to serve your ~flash.core.model.Task. Here's an example:

../../../flash_examples/serve/translation/inference_server.py

You can now perform inference from your client like this:

../../../flash_examples/serve/translation/client.py


Accelerate Training & Inference with Torch ORT

Torch ORT converts your model into an optimized ONNX graph, speeding up training & inference when using NVIDIA or AMD GPUs. Enabling Torch ORT requires a single flag passed to the TranslationTask once installed. See installation instructions here.

Note

Not all Transformer models are supported. See this table for supported models + branches containing fixes for certain models.

...

model = TranslationTask(backbone="t5-large", num_classes=datamodule.num_classes, enable_ort=True)