transformerxl.rst 2.45 KB
Newer Older
1
2
3
Transformer XL
----------------------------------------------------

Lysandre's avatar
Lysandre committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
The Transformer-XL model was proposed in
`Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context`_
by Zihang Dai*, Zhilin Yang*, Yiming Yang, Jaime Carbonell, Quoc V. Le, Ruslan Salakhutdinov.
It's a causal (uni-directional) transformer with relative positioning (sinuso茂dal) embeddings which can reuse
previously computed hidden-states to attend to longer context (memory).
This model also uses adaptive softmax inputs and outputs (tied).

The abstract from the paper is the following:

*Transformers have a potential of learning longer-term dependency, but are limited by a fixed-length context in the
setting of language modeling. We propose a novel neural architecture Transformer-XL that enables learning dependency
beyond a fixed length without disrupting temporal coherence. It consists of a segment-level recurrence mechanism and
a novel positional encoding scheme. Our method not only enables capturing longer-term dependency, but also resolves
the context fragmentation problem. As a result, Transformer-XL learns dependency that is 80% longer than RNNs and
450% longer than vanilla Transformers, achieves better performance on both short and long sequences, and is up
to 1,800+ times faster than vanilla Transformers during evaluation. Notably, we improve the state-of-the-art results
of bpc/perplexity to 0.99 on enwiki8, 1.08 on text8, 18.3 on WikiText-103, 21.8 on One Billion Word, and 54.5 on
Penn Treebank (without finetuning). When trained only on WikiText-103, Transformer-XL manages to generate reasonably
coherent, novel text articles with thousands of tokens.*

Tips:

- Transformer-XL uses relative sinusoidal positional embeddings so it's usually advised to pad the inputs on
  the left rather than the right.

29

30
31
``TransfoXLConfig``
~~~~~~~~~~~~~~~~~~~~~
32

33
.. autoclass:: transformers.TransfoXLConfig
34
    :members:
35
36


37
38
39
``TransfoXLTokenizer``
~~~~~~~~~~~~~~~~~~~~~~~~~~

40
.. autoclass:: transformers.TransfoXLTokenizer
41
    :members:
42
43


44
``TransfoXLModel``
45
46
~~~~~~~~~~~~~~~~~~~~~~~~~~

47
.. autoclass:: transformers.TransfoXLModel
48
49
50
    :members:


51
``TransfoXLLMHeadModel``
52
53
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

54
.. autoclass:: transformers.TransfoXLLMHeadModel
55
    :members:
LysandreJik's avatar
LysandreJik committed
56
57
58
59
60


``TFTransfoXLModel``
~~~~~~~~~~~~~~~~~~~~~~~~~~

61
.. autoclass:: transformers.TFTransfoXLModel
LysandreJik's avatar
LysandreJik committed
62
63
64
65
66
67
    :members:


``TFTransfoXLLMHeadModel``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

68
.. autoclass:: transformers.TFTransfoXLLMHeadModel
LysandreJik's avatar
LysandreJik committed
69
    :members: