Views
No views yet
We implement all our models in PyTorch (Paszke et al., 2017), and train them on 64 Volta GPUs for the language modeling tasks, and 8 GPUs for the MT tasks. We use float16 operations to speed up training and to reduce the memory usage of our models.
1@article{lample2019cross,
2 title={Cross-lingual language model pretraining},
3 author={Lample, Guillaume and Conneau, Alexis},
4 journal={arXiv preprint arXiv:1901.07291},
5 year={2019}
6}1import torch
2from transformers import XLMTokenizer, XLMWithLMHeadModel
3
4tokenizer = XLMTokenizer.from_pretrained("xlm-clm-ende-1024")
5model = XLMWithLMHeadModel.from_pretrained("xlm-clm-ende-1024")
6
7input_ids = torch.tensor([tokenizer.encode("Wikipedia was used to")]) # batch size of 1
8
9language_id = tokenizer.lang2id["en"] # 0
10langs = torch.tensor([language_id] * input_ids.shape[1]) # torch.tensor([0, 0, 0, ..., 0])
11
12# We reshape it to be of size (batch_size, sequence_length)
13langs = langs.view(1, -1) # is now of shape [1, sequence_length] (we have a batch size of 1)
14
15outputs = model(input_ids, langs=langs)