configuration_vilt.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright 2022 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. """VilT 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="dandelin/vilt-b32-mlm")
  19. @strict
  20. class ViltConfig(PreTrainedConfig):
  21. r"""
  22. modality_type_vocab_size (`int`, *optional*, defaults to 2):
  23. The vocabulary size of the modalities passed when calling [`ViltModel`]. This is used after concatenating the
  24. embeddings of the text and image modalities.
  25. max_image_length (`int`, *optional*, defaults to -1):
  26. The maximum number of patches to take as input for the Transformer encoder. If set to a positive integer,
  27. the encoder will sample `max_image_length` patches at maximum. If set to -1, will not be taken into
  28. account.
  29. num_images (`int`, *optional*, defaults to -1):
  30. The number of images to use for natural language visual reasoning. If set to a positive integer, will be
  31. used by [`ViltForImagesAndTextClassification`] for defining the classifier head.
  32. Example:
  33. ```python
  34. >>> from transformers import ViLTModel, ViLTConfig
  35. >>> # Initializing a ViLT dandelin/vilt-b32-mlm style configuration
  36. >>> configuration = ViLTConfig()
  37. >>> # Initializing a model from the dandelin/vilt-b32-mlm style configuration
  38. >>> model = ViLTModel(configuration)
  39. >>> # Accessing the model configuration
  40. >>> configuration = model.config
  41. ```"""
  42. model_type = "vilt"
  43. vocab_size: int = 30522
  44. type_vocab_size: int = 2
  45. modality_type_vocab_size: int = 2
  46. max_position_embeddings: int = 40
  47. hidden_size: int = 768
  48. num_hidden_layers: int = 12
  49. num_attention_heads: int = 12
  50. intermediate_size: int = 3072
  51. hidden_act: str = "gelu"
  52. hidden_dropout_prob: float | int = 0.0
  53. attention_probs_dropout_prob: float | int = 0.0
  54. initializer_range: float = 0.02
  55. layer_norm_eps: float = 1e-12
  56. image_size: int | list[int] | tuple[int, int] = 384
  57. patch_size: int | list[int] | tuple[int, int] = 32
  58. num_channels: int = 3
  59. qkv_bias: bool = True
  60. max_image_length: int = -1
  61. tie_word_embeddings: bool = True
  62. num_images: int = -1
  63. pad_token_id: int | None = None
  64. def __post_init__(self, **kwargs):
  65. kwargs.pop("tie_word_embeddings", None)
  66. self.tie_word_embeddings = True # force it
  67. super().__post_init__(**kwargs)
  68. __all__ = ["ViltConfig"]