configuration_layoutlmv3.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright 2022 Microsoft Research and The HuggingFace Inc. team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """LayoutLMv3 model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="microsoft/layoutlmv3-base")
  19. @strict
  20. class LayoutLMv3Config(PreTrainedConfig):
  21. r"""
  22. max_2d_position_embeddings (`int`, *optional*, defaults to 1024):
  23. The maximum value that the 2D position embedding might ever be used with. Typically set this to something
  24. large just in case (e.g., 1024).
  25. coordinate_size (`int`, *optional*, defaults to `128`):
  26. Dimension of the coordinate embeddings.
  27. shape_size (`int`, *optional*, defaults to `128`):
  28. Dimension of the width and height embeddings.
  29. has_relative_attention_bias (`bool`, *optional*, defaults to `True`):
  30. Whether or not to use a relative attention bias in the self-attention mechanism.
  31. rel_pos_bins (`int`, *optional*, defaults to 32):
  32. The number of relative position bins to be used in the self-attention mechanism.
  33. max_rel_pos (`int`, *optional*, defaults to 128):
  34. The maximum number of relative positions to be used in the self-attention mechanism.
  35. rel_2d_pos_bins (`int`, *optional*, defaults to 64):
  36. The number of 2D relative position bins in the self-attention mechanism.
  37. max_rel_2d_pos (`int`, *optional*, defaults to 256):
  38. The maximum number of relative 2D positions in the self-attention mechanism.
  39. has_spatial_attention_bias (`bool`, *optional*, defaults to `True`):
  40. Whether or not to use a spatial attention bias in the self-attention mechanism.
  41. text_embed (`bool`, *optional*, defaults to `True`):
  42. Whether or not to add text embeddings.
  43. visual_embed (`bool`, *optional*, defaults to `True`):
  44. Whether or not to add patch embeddings.
  45. input_size (`int`, *optional*, defaults to `224`):
  46. The size (resolution) of the images.
  47. Example:
  48. ```python
  49. >>> from transformers import LayoutLMv3Config, LayoutLMv3Model
  50. >>> # Initializing a LayoutLMv3 microsoft/layoutlmv3-base style configuration
  51. >>> configuration = LayoutLMv3Config()
  52. >>> # Initializing a model (with random weights) from the microsoft/layoutlmv3-base style configuration
  53. >>> model = LayoutLMv3Model(configuration)
  54. >>> # Accessing the model configuration
  55. >>> configuration = model.config
  56. ```"""
  57. model_type = "layoutlmv3"
  58. vocab_size: int = 50265
  59. hidden_size: int = 768
  60. num_hidden_layers: int = 12
  61. num_attention_heads: int = 12
  62. intermediate_size: int = 3072
  63. hidden_act: str = "gelu"
  64. hidden_dropout_prob: float | int = 0.1
  65. attention_probs_dropout_prob: float | int = 0.1
  66. max_position_embeddings: int = 512
  67. type_vocab_size: int = 2
  68. initializer_range: float = 0.02
  69. layer_norm_eps: float = 1e-5
  70. pad_token_id: int | None = 1
  71. bos_token_id: int | None = 0
  72. eos_token_id: int | list[int] | None = 2
  73. max_2d_position_embeddings: int = 1024
  74. coordinate_size: int = 128
  75. shape_size: int = 128
  76. has_relative_attention_bias: bool = True
  77. rel_pos_bins: int = 32
  78. max_rel_pos: int = 128
  79. rel_2d_pos_bins: int = 64
  80. max_rel_2d_pos: int = 256
  81. has_spatial_attention_bias: bool = True
  82. text_embed: bool = True
  83. visual_embed: bool = True
  84. input_size: int = 224
  85. num_channels: int = 3
  86. patch_size: int | list[int] | tuple[int, int] = 16
  87. classifier_dropout: float | int | None = None
  88. __all__ = ["LayoutLMv3Config"]