| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- # Copyright 2021 The HuggingFace Inc. team. All rights reserved.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- """TrOCR model configuration"""
- from huggingface_hub.dataclasses import strict
- from ...configuration_utils import PreTrainedConfig
- from ...utils import auto_docstring
- @auto_docstring(checkpoint="microsoft/trocr-base-handwritten")
- @strict
- class TrOCRConfig(PreTrainedConfig):
- r"""
- use_learned_position_embeddings (`bool`, *optional*, defaults to `True`):
- Whether or not to use learned position embeddings. If not, sinusoidal position embeddings will be used.
- layernorm_embedding (`bool`, *optional*, defaults to `True`):
- Whether or not to use a layernorm after the word + position embeddings.
- Example:
- ```python
- >>> from transformers import TrOCRConfig, TrOCRForCausalLM
- >>> # Initializing a TrOCR-base style configuration
- >>> configuration = TrOCRConfig()
- >>> # Initializing a model (with random weights) from the TrOCR-base style configuration
- >>> model = TrOCRForCausalLM(configuration)
- >>> # Accessing the model configuration
- >>> configuration = model.config
- ```"""
- model_type = "trocr"
- keys_to_ignore_at_inference = ["past_key_values"]
- attribute_map = {
- "num_attention_heads": "decoder_attention_heads",
- "hidden_size": "d_model",
- "num_hidden_layers": "decoder_layers",
- }
- vocab_size: int = 50265
- d_model: int = 1024
- decoder_layers: int = 12
- decoder_attention_heads: int = 16
- decoder_ffn_dim: int = 4096
- activation_function: str = "gelu"
- max_position_embeddings: int = 512
- dropout: float | int = 0.1
- attention_dropout: float | int = 0.0
- activation_dropout: float | int = 0.0
- decoder_start_token_id: int = 2
- init_std: float = 0.02
- decoder_layerdrop: float | int = 0.0
- use_cache: bool = True
- scale_embedding: bool = False
- use_learned_position_embeddings: bool = True
- layernorm_embedding: bool = True
- pad_token_id: int | None = 1
- bos_token_id: int | None = 0
- eos_token_id: int | list[int] | None = 2
- cross_attention_hidden_size: int | None = None
- is_decoder: bool = False
- tie_word_embeddings: bool = True
- __all__ = ["TrOCRConfig"]
|