configuration_bros.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright 2023-present NAVER Corp, The Microsoft Research Asia LayoutLM Team Authors and the HuggingFace Inc. team.
  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. """Bros 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="jinho8345/bros-base-uncased")
  19. @strict
  20. class BrosConfig(PreTrainedConfig):
  21. r"""
  22. dim_bbox (`int`, *optional*, defaults to 8):
  23. The dimension of the bounding box coordinates. (x0, y1, x1, y0, x1, y1, x0, y1)
  24. bbox_scale (`float`, *optional*, defaults to 100.0):
  25. The scale factor of the bounding box coordinates.
  26. n_relations (`int`, *optional*, defaults to 1):
  27. The number of relations for SpadeEE(entity extraction), SpadeEL(entity linking) head.
  28. Examples:
  29. ```python
  30. >>> from transformers import BrosConfig, BrosModel
  31. >>> # Initializing a BROS jinho8345/bros-base-uncased style configuration
  32. >>> configuration = BrosConfig()
  33. >>> # Initializing a model from the jinho8345/bros-base-uncased style configuration
  34. >>> model = BrosModel(configuration)
  35. >>> # Accessing the model configuration
  36. >>> configuration = model.config
  37. ```"""
  38. model_type = "bros"
  39. vocab_size: int = 30522
  40. hidden_size: int = 768
  41. num_hidden_layers: int = 12
  42. num_attention_heads: int = 12
  43. intermediate_size: int = 3072
  44. hidden_act: str = "gelu"
  45. hidden_dropout_prob: float | int = 0.1
  46. attention_probs_dropout_prob: float | int = 0.1
  47. max_position_embeddings: int = 512
  48. type_vocab_size: int = 2
  49. initializer_range: float = 0.02
  50. layer_norm_eps: float = 1e-12
  51. pad_token_id: int | None = 0
  52. dim_bbox: int = 8
  53. bbox_scale: float = 100.0
  54. n_relations: int = 1
  55. classifier_dropout_prob: float | int = 0.1
  56. is_decoder: bool = False
  57. add_cross_attention: bool = False
  58. def __post_init__(self, **kwargs):
  59. self.dim_bbox_sinusoid_emb_2d = self.hidden_size // 4
  60. self.dim_bbox_sinusoid_emb_1d = self.dim_bbox_sinusoid_emb_2d // self.dim_bbox
  61. self.dim_bbox_projection = self.hidden_size // self.num_attention_heads
  62. super().__post_init__(**kwargs)
  63. __all__ = ["BrosConfig"]