".github/workflows/windows_release_cu118_dependencies.yml" did not exist on "7bd3defc1465e6bdcf597ff6b8274301d4d16ff7"
lxmert.rst 5.62 KB
Newer Older
1
LXMERT
Sylvain Gugger's avatar
Sylvain Gugger committed
2
-----------------------------------------------------------------------------------------------------------------------
3
4

Overview
Sylvain Gugger's avatar
Sylvain Gugger committed
5
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6

Sylvain Gugger's avatar
Sylvain Gugger committed
7
8
9
10
The LXMERT model was proposed in `LXMERT: Learning Cross-Modality Encoder Representations from Transformers
<https://arxiv.org/abs/1908.07490>`__ by Hao Tan & Mohit Bansal. It is a series of bidirectional transformer encoders
(one for the vision modality, one for the language modality, and then one to fuse both modalities) pretrained using a
combination of masked language modeling, visual-language text alignment, ROI-feature regression, masked
Sylvain Gugger's avatar
Sylvain Gugger committed
11
12
visual-attribute modeling, masked visual-object modeling, and visual-question answering objectives. The pretraining
consists of multiple multi-modal datasets: MSCOCO, Visual-Genome + Visual-Genome Question Answering, VQA 2.0, and GQA.
13
14
15

The abstract from the paper is the following:

Sylvain Gugger's avatar
Sylvain Gugger committed
16
17
18
19
20
21
*Vision-and-language reasoning requires an understanding of visual concepts, language semantics, and, most importantly,
the alignment and relationships between these two modalities. We thus propose the LXMERT (Learning Cross-Modality
Encoder Representations from Transformers) framework to learn these vision-and-language connections. In LXMERT, we
build a large-scale Transformer model that consists of three encoders: an object relationship encoder, a language
encoder, and a cross-modality encoder. Next, to endow our model with the capability of connecting vision and language
semantics, we pre-train the model with large amounts of image-and-sentence pairs, via five diverse representative
22
pretraining tasks: masked language modeling, masked object prediction (feature regression and label classification),
Sylvain Gugger's avatar
Sylvain Gugger committed
23
24
25
26
27
28
cross-modality matching, and image question answering. These tasks help in learning both intra-modality and
cross-modality relationships. After fine-tuning from our pretrained parameters, our model achieves the state-of-the-art
results on two visual question answering datasets (i.e., VQA and GQA). We also show the generalizability of our
pretrained cross-modality model by adapting it to a challenging visual-reasoning task, NLVR, and improve the previous
best result by 22% absolute (54% to 76%). Lastly, we demonstrate detailed ablation studies to prove that both our novel
model components and pretraining strategies significantly contribute to our strong results; and also present several
29
30
31
32
attention visualizations for the different encoders*

Tips:

Sylvain Gugger's avatar
Sylvain Gugger committed
33
34
35
36
37
38
39
40
41
- Bounding boxes are not necessary to be used in the visual feature embeddings, any kind of visual-spacial features
  will work.
- Both the language hidden states and the visual hidden states that LXMERT outputs are passed through the
  cross-modality layer, so they contain information from both modalities. To access a modality that only attends to
  itself, select the vision/language hidden states from the first input in the tuple.
- The bidirectional cross-modality encoder attention only returns attention values when the language modality is used
  as the input and the vision modality is used as the context vector. Further, while the cross-modality encoder
  contains self-attention for each respective modality and cross-attention, only the cross attention is returned and
  both self attention outputs are disregarded.
42

Sylvain Gugger's avatar
Sylvain Gugger committed
43
The original code can be found `here <https://github.com/airsplay/lxmert>`__.
44
45
46


LxmertConfig
Sylvain Gugger's avatar
Sylvain Gugger committed
47
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48
49
50
51
52
53

.. autoclass:: transformers.LxmertConfig
    :members:


LxmertTokenizer
Sylvain Gugger's avatar
Sylvain Gugger committed
54
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
56

.. autoclass:: transformers.LxmertTokenizer
Sylvain Gugger's avatar
Sylvain Gugger committed
57
58
59
60
61
62
63
64
    :members:


LxmertTokenizerFast
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoclass:: transformers.LxmertTokenizerFast
    :members:
65
66
67


Lxmert specific outputs
Sylvain Gugger's avatar
Sylvain Gugger committed
68
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69

Sylvain Gugger's avatar
Sylvain Gugger committed
70
.. autoclass:: transformers.models.lxmert.modeling_lxmert.LxmertModelOutput
71
72
    :members:

Sylvain Gugger's avatar
Sylvain Gugger committed
73
.. autoclass:: transformers.models.lxmert.modeling_lxmert.LxmertForPreTrainingOutput
74
75
    :members:

Sylvain Gugger's avatar
Sylvain Gugger committed
76
.. autoclass:: transformers.models.lxmert.modeling_lxmert.LxmertForQuestionAnsweringOutput
77
78
    :members:

Sylvain Gugger's avatar
Sylvain Gugger committed
79
.. autoclass:: transformers.models.lxmert.modeling_tf_lxmert.TFLxmertModelOutput
80
81
    :members:

Sylvain Gugger's avatar
Sylvain Gugger committed
82
.. autoclass:: transformers.models.lxmert.modeling_tf_lxmert.TFLxmertForPreTrainingOutput
83
84
85
86
    :members:


LxmertModel
Sylvain Gugger's avatar
Sylvain Gugger committed
87
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88
89

.. autoclass:: transformers.LxmertModel
Sylvain Gugger's avatar
Sylvain Gugger committed
90
    :members: forward
91
92

LxmertForPreTraining
Sylvain Gugger's avatar
Sylvain Gugger committed
93
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
95

.. autoclass:: transformers.LxmertForPreTraining
Sylvain Gugger's avatar
Sylvain Gugger committed
96
    :members: forward
97
98

LxmertForQuestionAnswering
Sylvain Gugger's avatar
Sylvain Gugger committed
99
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100
101

.. autoclass:: transformers.LxmertForQuestionAnswering
Sylvain Gugger's avatar
Sylvain Gugger committed
102
    :members: forward
103
104
105


TFLxmertModel
Sylvain Gugger's avatar
Sylvain Gugger committed
106
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107
108

.. autoclass:: transformers.TFLxmertModel
Sylvain Gugger's avatar
Sylvain Gugger committed
109
    :members: call
110
111

TFLxmertForPreTraining
Sylvain Gugger's avatar
Sylvain Gugger committed
112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113
114

.. autoclass:: transformers.TFLxmertForPreTraining
Sylvain Gugger's avatar
Sylvain Gugger committed
115
    :members: call