modeling¶
Modeling classes for LayoutXLM model.
-
class
LayoutXLMModel
(with_pool='tanh', use_visual_backbone=True, **kwargs)[source]¶ Bases:
paddlenlp.transformers.layoutxlm.modeling.LayoutXLMPretrainedModel
The bare LayoutXLM Model outputting raw hidden-states.
This model inherits from
PretrainedModel
. Refer to the superclass documentation for the generic methods.This model is also a Paddle paddle.nn.Layer subclass. Use it as a regular Paddle Layer and refer to the Paddle documentation for all matter related to general usage and behavior.
- Parameters
vocab_size (
int
) – Vocabulary size of the XLNet model. Defines the number of different tokens that can be represented by theinputs_ids
passed when calling XLNetModel.hidden_size (
int
, optional) – Dimensionality of the encoder layers and the pooler layer. Defaults to768
.num_hidden_layers (
int
, optional) – Number of hidden layers in the Transformer encoder. Defaults to12
.num_attention_heads (
int
, optional) – Number of attention heads for each attention layer in the Transformer encoder. Defaults to12
.intermediate_size (
int
, optional) – Dimensionality of the “intermediate” (often named feed-forward) layer in the Transformer encoder. Defaults to3072
.hidden_act (
str
, optional) – The non-linear activation function in the feed-forward layer."gelu"
,"relu"
and any other paddle supported activation functions are supported. Defaults to"gelu"
.hidden_dropout_prob (
float
, optional) – The dropout probability for all fully connected layers in the embeddings and encoder. Defaults to0.1
.attention_probs_dropout_prob (
float
, optional) – The dropout probability for all fully connected layers in the pooler. Defaults to0.1
.initializer_range (
float
, optional) – The standard deviation of the truncated_normal_initializer for initializing all weight matrices. Defaults to0.02
.
-
resize_position_embeddings
(new_num_position_embeddings)[source]¶ Resizes position embeddings of the model if
new_num_position_embeddings != config["max_position_embeddings"]
.- Parameters
new_num_position_embeddings (
int
) – The number of new position embedding matrix. If position embeddings are learned, increasing the size will add newly initialized vectors at the end, whereas reducing the size will remove vectors from the end.
-
forward
(input_ids=None, bbox=None, image=None, token_type_ids=None, position_ids=None, attention_mask=None, head_mask=None, output_hidden_states=False, output_attentions=False)[source]¶ Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-
class
LayoutXLMPretrainedModel
(*args, **kwargs)[source]¶ Bases:
paddlenlp.transformers.model_utils.PretrainedModel
-
base_model_class
¶ alias of
paddlenlp.transformers.layoutxlm.modeling.LayoutXLMModel
-
-
class
LayoutXLMForTokenClassification
(layoutxlm, num_classes=2, dropout=None)[source]¶ Bases:
paddlenlp.transformers.layoutxlm.modeling.LayoutXLMPretrainedModel
-
get_input_embeddings
()[source]¶ get input embedding of model
- Returns
embedding of model
- Return type
nn.Embedding
-
resize_position_embeddings
(new_num_position_embeddings)[source]¶ Resizes position embeddings of the model if
new_num_position_embeddings != config["max_position_embeddings"]
.- Parameters
new_num_position_embeddings (
int
) – The number of new position embedding matrix. If position embeddings are learned, increasing the size will add newly initialized vectors at the end, whereas reducing the size will remove vectors from the end.
-
forward
(input_ids=None, bbox=None, image=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, labels=None)[source]¶ Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-
-
class
LayoutXLMForSequenceClassification
(layoutxlm, num_classes=2, dropout=None)[source]¶ Bases:
paddlenlp.transformers.layoutxlm.modeling.LayoutXLMPretrainedModel
-
get_input_embeddings
()[source]¶ get input embedding of model
- Returns
embedding of model
- Return type
nn.Embedding
-
resize_position_embeddings
(new_num_position_embeddings)[source]¶ Resizes position embeddings of the model if
new_num_position_embeddings != config["max_position_embeddings"]
.- Parameters
new_num_position_embeddings (
int
) – The number of new position embedding matrix. If position embeddings are learned, increasing the size will add newly initialized vectors at the end, whereas reducing the size will remove vectors from the end.
-
forward
(input_ids=None, bbox=None, image=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, labels=None)[source]¶ Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-
-
class
LayoutXLMForPretraining
(layoutxlm)[source]¶ Bases:
paddlenlp.transformers.layoutxlm.modeling.LayoutXLMPretrainedModel
-
resize_position_embeddings
(new_num_position_embeddings)[source]¶ Resizes position embeddings of the model if
new_num_position_embeddings != config["max_position_embeddings"]
.- Parameters
new_num_position_embeddings (
int
) – The number of new position embedding matrix. If position embeddings are learned, increasing the size will add newly initialized vectors at the end, whereas reducing the size will remove vectors from the end.
-
forward
(input_ids=None, bbox=None, image=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, masked_positions=None)[source]¶ Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-
-
class
LayoutXLMForRelationExtraction
(layoutxlm, hidden_size=768, hidden_dropout_prob=0.1, dropout=None)[source]¶ Bases:
paddlenlp.transformers.layoutxlm.modeling.LayoutXLMPretrainedModel
-
resize_position_embeddings
(new_num_position_embeddings)[source]¶ Resizes position embeddings of the model if
new_num_position_embeddings != config["max_position_embeddings"]
.- Parameters
new_num_position_embeddings (
int
) – The number of new position embedding matrix. If position embeddings are learned, increasing the size will add newly initialized vectors at the end, whereas reducing the size will remove vectors from the end.
-
forward
(input_ids, bbox, image=None, attention_mask=None, entities=None, relations=None, token_type_ids=None, position_ids=None, head_mask=None, labels=None)[source]¶ Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-
-
class
LayoutXLMForQuestionAnswering
(layoutxlm, num_classes=2, dropout=None, has_visual_segment_embedding=False)[source]¶ Bases:
paddlenlp.transformers.layoutxlm.modeling.LayoutXLMPretrainedModel
-
get_input_embeddings
()[source]¶ get input embedding of model
- Returns
embedding of model
- Return type
nn.Embedding
-
forward
(input_ids=None, bbox=None, image=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, start_positions=None, end_positions=None)[source]¶ Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
-