configuration_layoutlm.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright 2010, The Microsoft Research Asia LayoutLM Team authors
  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. """LayoutLM model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ... import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="microsoft/layoutlm-base-uncased")
  19. @strict
  20. class LayoutLMConfig(PreTrainedConfig):
  21. r"""
  22. max_2d_position_embeddings (`int`, *optional*, defaults to 1024):
  23. The maximum value that the 2D position embedding might ever used. Typically set this to something large
  24. just in case (e.g., 1024).
  25. Examples:
  26. ```python
  27. >>> from transformers import LayoutLMConfig, LayoutLMModel
  28. >>> # Initializing a LayoutLM configuration
  29. >>> configuration = LayoutLMConfig()
  30. >>> # Initializing a model (with random weights) from the configuration
  31. >>> model = LayoutLMModel(configuration)
  32. >>> # Accessing the model configuration
  33. >>> configuration = model.config
  34. ```"""
  35. model_type = "layoutlm"
  36. vocab_size: int = 30522
  37. hidden_size: int = 768
  38. num_hidden_layers: int = 12
  39. num_attention_heads: int = 12
  40. intermediate_size: int = 3072
  41. hidden_act: str = "gelu"
  42. hidden_dropout_prob: float | int = 0.1
  43. attention_probs_dropout_prob: float | int = 0.1
  44. max_position_embeddings: int = 512
  45. type_vocab_size: int = 2
  46. initializer_range: float = 0.02
  47. layer_norm_eps: float = 1e-12
  48. pad_token_id: int | None = 0
  49. eos_token_id: int | list[int] | None = None
  50. bos_token_id: int | None = None
  51. use_cache: bool = True
  52. max_2d_position_embeddings: int = 1024
  53. tie_word_embeddings: bool = True
  54. __all__ = ["LayoutLMConfig"]