liveBook · Manning

Machine translation

As explained in Inside Deep Learning: Math, Algorithms, Models

Machine translation is the automated computational conversion of text or speech from one natural language into another.

Machine translation converts text or speech from one natural language into another. In a sequence-to-sequence model, the source sequence X becomes a target sequence Y; the sequences can differ in length, and multiple valid translations may exist. section 11.0 section 11.2

Sequence-to-sequence models handle translation by separating the input and output stages, rather than requiring one output per input token. English-to-French translation illustrates the need to model different word orders and non-one-to-one relationships between words. section 11.0 section 11.2

A small translation dataset can be prepared for training by:

  • Loading paired English and French sentences, then lowercasing text and removing punctuation. section 11.2.1
  • Limiting sentence length and assigning vocabulary IDs to words. section 11.2.1
  • Adding start-of-sentence, end-of-sentence, and padding tokens; padding batches to a shared length. section 11.2.1

Translation is not one-to-one

“What a nice day” can translate as “quelle belle journée.” A single English word such as “run” can also have multiple French translations. section 11.2 section 11.2.1

for i in range(10): 
   print(all_data[i])

('go', 'va') 
('run', 'cours') 
('run', 'courez') 
('wow', 'ça alors') 
('fire', 'au feu') 
('help', "à l'aide") 
('jump', 'saute') 
('stop', 'ça suffit') 
('stop', 'stop') 
('stop', 'arrête toi')

Inspect sample English-French pairs, including several different translations for “stop.” section 11.2.1

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Defines unequal-length mappings and details dataset preparation, while leaving recurrent-network and attention implementation to subsequent steps.
Examples
Uses English–French sentence pairs and ambiguous words such as “run” to illustrate translation variation.
What it assumes
Assumes familiarity with attention mechanisms and PyTorch modules, while defining source and target sequences and showing data preparation.
What you can do after
Build a small English–French translation dataset with paired sentences, vocabulary IDs, boundary tokens, and padded batches.
How it connects
Connects machine translation to sequence-to-sequence models, recurrent neural networks, and attention mechanisms.

Also explained in

Compare how 10 books explain machine translation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Inside Deep Learning: Math, Algorithms, Models. The section links point to the parts of the book it draws on.