xlm.rst 4.34 KB
Newer Older
1
2
XLM
----------------------------------------------------
3

Lysandre's avatar
Lysandre committed
4
5
6
7
Overview
~~~~~~~~~~~~~~~~~~~~~

The XLM model was proposed in `Cross-lingual Language Model Pretraining <https://arxiv.org/abs/1901.07291>`_
Lysandre's avatar
Lysandre committed
8
9
by Guillaume Lample*, Alexis Conneau*. It's a transformer pre-trained using one of the following objectives:

Lysandre's avatar
Lysandre committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
- a causal language modeling (CLM) objective (next token prediction),
- a masked language modeling (MLM) objective (Bert-like), or
- a Translation Language Modeling (TLM) object (extension of Bert's MLM to multiple language inputs)

The abstract from the paper is the following:

*Recent studies have demonstrated the efficiency of generative pretraining for English natural language understanding.
In this work, we extend this approach to multiple languages and show the effectiveness of cross-lingual pretraining.
We propose two methods to learn cross-lingual language models (XLMs): one unsupervised that only relies on monolingual
data, and one supervised that leverages parallel data with a new cross-lingual language model objective. We obtain
state-of-the-art results on cross-lingual classification, unsupervised and supervised machine translation. On XNLI,
our approach pushes the state of the art by an absolute gain of 4.9% accuracy. On unsupervised machine translation,
we obtain 34.3 BLEU on WMT'16 German-English, improving the previous state of the art by more than 9 BLEU. On
supervised machine translation, we obtain a new state of the art of 38.5 BLEU on WMT'16 Romanian-English, outperforming
the previous best approach by more than 4 BLEU. Our code and pretrained models will be made publicly available.*
Lysandre's avatar
Lysandre committed
25

Lysandre's avatar
Lysandre committed
26
Tips:
Lysandre's avatar
Lysandre committed
27

Lysandre's avatar
Lysandre committed
28
29
30
31
- XLM has many different checkpoints, which were trained using different objectives: CLM, MLM or TLM. Make sure to
  select the correct objective for your task (e.g. MLM checkpoints are not suitable for generation).
- XLM has multilingual checkpoints which leverage a specific `lang` parameter. Check out the
  `multi-lingual <../multilingual.html>`__ page for more information.
Lysandre's avatar
Lysandre committed
32

33
34
The original code can be found `here <https://github.com/facebookresearch/XLM/>`_.

Lysandre's avatar
Lysandre committed
35
36

XLMConfig
37
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38

39
.. autoclass:: transformers.XLMConfig
40
41
    :members:

Lysandre's avatar
Lysandre committed
42
XLMTokenizer
43
44
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

45
.. autoclass:: transformers.XLMTokenizer
Lysandre Debut's avatar
Lysandre Debut committed
46
47
    :members: build_inputs_with_special_tokens, get_special_tokens_mask,
        create_token_type_ids_from_sequences, save_vocabulary
48

49
50
51
52
53
54
55
56

XLM specific outputs
~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.modeling_xlm.XLMForQuestionAnsweringOutput
    :members:


Lysandre's avatar
Lysandre committed
57
XLMModel
58
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59

60
.. autoclass:: transformers.XLMModel
61
62
63
    :members:


Lysandre's avatar
Lysandre committed
64
XLMWithLMHeadModel
65
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66

67
.. autoclass:: transformers.XLMWithLMHeadModel
68
69
70
    :members:


Lysandre's avatar
Lysandre committed
71
XLMForSequenceClassification
72
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73

74
.. autoclass:: transformers.XLMForSequenceClassification
75
76
77
    :members:


78
79
80
81
82
83
84
85
86
87
88
89
90
91
XLMForMultipleChoice
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.XLMForMultipleChoice
    :members:


XLMForTokenClassification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.XLMForTokenClassification
    :members:


Lysandre's avatar
Lysandre committed
92
XLMForQuestionAnsweringSimple
Lysandre's avatar
Lysandre committed
93
94
95
96
97
98
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.XLMForQuestionAnsweringSimple
    :members:


Lysandre's avatar
Lysandre committed
99
XLMForQuestionAnswering
100
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101

102
.. autoclass:: transformers.XLMForQuestionAnswering
103
    :members:
LysandreJik's avatar
LysandreJik committed
104
105


Lysandre's avatar
Lysandre committed
106
TFXLMModel
LysandreJik's avatar
LysandreJik committed
107
108
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

thomwolf's avatar
thomwolf committed
109
.. autoclass:: transformers.TFXLMModel
LysandreJik's avatar
LysandreJik committed
110
111
112
    :members:


Lysandre's avatar
Lysandre committed
113
TFXLMWithLMHeadModel
LysandreJik's avatar
LysandreJik committed
114
115
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

116
.. autoclass:: transformers.TFXLMWithLMHeadModel
LysandreJik's avatar
LysandreJik committed
117
118
119
    :members:


Lysandre's avatar
Lysandre committed
120
TFXLMForSequenceClassification
LysandreJik's avatar
LysandreJik committed
121
122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

123
.. autoclass:: transformers.TFXLMForSequenceClassification
LysandreJik's avatar
LysandreJik committed
124
125
126
    :members:


Sylvain Gugger's avatar
Sylvain Gugger committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
TFXLMForMultipleChoice
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.TFXLMForMultipleChoice
    :members:


TFXLMForTokenClassification
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.TFXLMForTokenClassification
    :members:



Lysandre's avatar
Lysandre committed
142
TFXLMForQuestionAnsweringSimple
LysandreJik's avatar
LysandreJik committed
143
144
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

145
.. autoclass:: transformers.TFXLMForQuestionAnsweringSimple
LysandreJik's avatar
LysandreJik committed
146
    :members: