configuration_luke.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright Studio Ousia 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. """LUKE configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="studio-ousia/luke-base")
  19. @strict
  20. class LukeConfig(PreTrainedConfig):
  21. r"""
  22. entity_vocab_size (`int`, *optional*, defaults to 500000):
  23. Entity vocabulary size of the LUKE model. Defines the number of different entities that can be represented
  24. by the `entity_ids` passed when calling [`LukeModel`].
  25. entity_emb_size (`int`, *optional*, defaults to 256):
  26. The number of dimensions of the entity embedding.
  27. use_entity_aware_attention (`bool`, *optional*, defaults to `True`):
  28. Whether or not the model should use the entity-aware self-attention mechanism proposed in [LUKE: Deep
  29. Contextualized Entity Representations with Entity-aware Self-attention (Yamada et
  30. al.)](https://huggingface.co/papers/2010.01057).
  31. Examples:
  32. ```python
  33. >>> from transformers import LukeConfig, LukeModel
  34. >>> # Initializing a LUKE configuration
  35. >>> configuration = LukeConfig()
  36. >>> # Initializing a model from the configuration
  37. >>> model = LukeModel(configuration)
  38. >>> # Accessing the model configuration
  39. >>> configuration = model.config
  40. ```"""
  41. model_type = "luke"
  42. vocab_size: int = 50267
  43. entity_vocab_size: int = 500000
  44. hidden_size: int = 768
  45. entity_emb_size: int = 256
  46. num_hidden_layers: int = 12
  47. num_attention_heads: int = 12
  48. intermediate_size: int = 3072
  49. hidden_act: str = "gelu"
  50. hidden_dropout_prob: float | int = 0.1
  51. attention_probs_dropout_prob: float | int = 0.1
  52. max_position_embeddings: int = 512
  53. type_vocab_size: int = 2
  54. initializer_range: float = 0.02
  55. layer_norm_eps: float = 1e-12
  56. use_entity_aware_attention: bool = True
  57. classifier_dropout: float | int | None = None
  58. pad_token_id: int | None = 1
  59. bos_token_id: int | None = 0
  60. eos_token_id: int | list[int] | None = 2
  61. tie_word_embeddings: bool = True
  62. __all__ = ["LukeConfig"]