modular_layoutxlm.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright 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. from huggingface_hub.dataclasses import strict
  15. from ...utils import auto_docstring
  16. from ..layoutlmv2.configuration_layoutlmv2 import LayoutLMv2Config
  17. @auto_docstring(checkpoint="microsoft/layoutxlm-base")
  18. @strict
  19. class LayoutXLMConfig(LayoutLMv2Config):
  20. r"""
  21. max_2d_position_embeddings (`int`, *optional*, defaults to 1024):
  22. The maximum value that the 2D position embedding might ever be used with. Typically set this to something
  23. large just in case (e.g., 1024).
  24. max_rel_pos (`int`, *optional*, defaults to 128):
  25. The maximum number of relative positions to be used in the self-attention mechanism.
  26. rel_pos_bins (`int`, *optional*, defaults to 32):
  27. The number of relative position bins to be used in the self-attention mechanism.
  28. fast_qkv (`bool`, *optional*, defaults to `True`):
  29. Whether or not to use a single matrix for the queries, keys, values in the self-attention layers.
  30. max_rel_2d_pos (`int`, *optional*, defaults to 256):
  31. The maximum number of relative 2D positions in the self-attention mechanism.
  32. rel_2d_pos_bins (`int`, *optional*, defaults to 64):
  33. The number of 2D relative position bins in the self-attention mechanism.
  34. convert_sync_batchnorm (`bool`, *optional*, defaults to `True`):
  35. Whether or not to convert batch normalization layers to synchronized batch normalization layers.
  36. image_feature_pool_shape (`list[int]`, *optional*, defaults to `[7, 7, 256]`):
  37. The shape of the average-pooled feature map.
  38. coordinate_size (`int`, *optional*, defaults to 128):
  39. Dimension of the coordinate embeddings.
  40. shape_size (`int`, *optional*, defaults to 128):
  41. Dimension of the width and height embeddings.
  42. has_relative_attention_bias (`bool`, *optional*, defaults to `True`):
  43. Whether or not to use a relative attention bias in the self-attention mechanism.
  44. has_spatial_attention_bias (`bool`, *optional*, defaults to `True`):
  45. Whether or not to use a spatial attention bias in the self-attention mechanism.
  46. has_visual_segment_embedding (`bool`, *optional*, defaults to `False`):
  47. Whether or not to add visual segment embeddings.
  48. detectron2_config_args (`dict`, *optional*):
  49. Dictionary containing the configuration arguments of the Detectron2 visual backbone. Refer to [this
  50. file](https://github.com/microsoft/unilm/blob/master/layoutlmft/layoutlmft/models/layoutxlm/detectron2_config.py)
  51. for details regarding default values.
  52. Example:
  53. ```python
  54. >>> from transformers import LayoutXLMConfig, LayoutXLMModel
  55. >>> # Initializing a LayoutXLM microsoft/layoutxlm-base style configuration
  56. >>> configuration = LayoutXLMConfig()
  57. >>> # Initializing a model (with random weights) from the microsoft/layoutxlm-base style configuration
  58. >>> model = LayoutXLMModel(configuration)
  59. >>> # Accessing the model configuration
  60. >>> configuration = model.config
  61. ```"""
  62. pass
  63. __all__ = ["LayoutXLMConfig"]