codingutf8 2023 the huggingface inc team 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 orglicenseslicense2 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 mgpstr model configuration from configurationutils import pretrainedconfig from utils import logging logger logging getloggername mgpstrpretrainedconfigarchivemap alibabadamomgpstrbase https huggingface coalibabadamomgpstrbaseresolvemainconfig json class mgpstrconfigpretrainedconfig r this is the configuration class to store the configuration of an mgpstrmodel it is used to instantiate an mgpstr model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the mgpstr alibabadamomgpstrbasehttps huggingface coalibabadamomgpstrbase architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args imagesize listint optional defaults to 32 128 the size resolution of each image patchsize int optional defaults to 4 the size resolution of each patch numchannels int optional defaults to 3 the number of input channels maxtokenlength int optional defaults to 27 the max number of output tokens numcharacterlabels int optional defaults to 38 the number of classes for character head numbpelabels int optional defaults to 50257 the number of classes for bpe head numwordpiecelabels int optional defaults to 30522 the number of classes for wordpiece head hiddensize int optional defaults to 768 the embedding dimension numhiddenlayers int optional defaults to 12 number of hidden layers in the transformer encoder numattentionheads int optional defaults to 12 number of attention heads for each attention layer in the transformer encoder mlpratio float optional defaults to 4 0 the ratio of mlp hidden dim to embedding dim qkvbias bool optional defaults to true whether to add a bias to the queries keys and values distilled bool optional defaults to false model includes a distillation token and head as in deit models layernormeps float optional defaults to 1e05 the epsilon used by the layer normalization layers droprate float optional defaults to 0 0 the dropout probability for all fully connected layers in the embeddings encoder attndroprate float optional defaults to 0 0 the dropout ratio for the attention probabilities droppathrate float optional defaults to 0 0 the stochastic depth rate outputa3attentions bool optional defaults to false whether or not the model should returns a3 module attentions initializerrange float optional defaults to 0 02 the standard deviation of the truncatednormalinitializer for initializing all weight matrices example python from transformers import mgpstrconfig mgpstrforscenetextrecognition initializing a mgpstr mgpstrbase style configuration configuration mgpstrconfig initializing a model with random weights from the mgpstrbase style configuration model mgpstrforscenetextrecognitionconfiguration accessing the model configuration configuration model config modeltype mgpstr def init self imagesize32 128 patchsize4 numchannels3 maxtokenlength27 numcharacterlabels38 numbpelabels50257 numwordpiecelabels30522 hiddensize768 numhiddenlayers12 numattentionheads12 mlpratio4 0 qkvbiastrue distilledfalse layernormeps1e5 droprate0 0 attndroprate0 0 droppathrate0 0 outputa3attentionsfalse initializerrange0 02 kwargs super initkwargs self imagesize imagesize self patchsize patchsize self numchannels numchannels self maxtokenlength maxtokenlength self numcharacterlabels numcharacterlabels self numbpelabels numbpelabels self numwordpiecelabels numwordpiecelabels self hiddensize hiddensize self numhiddenlayers numhiddenlayers self numattentionheads numattentionheads self mlpratio mlpratio self distilled distilled self layernormeps layernormeps self droprate droprate self qkvbias qkvbias self attndroprate attndroprate self droppathrate droppathrate self outputa3attentions outputa3attentions self initializerrange initializerrange coding utf 8 2023 the huggingface inc team 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 mgp str model configuration this is the configuration class to store the configuration of an mgpstrmodel it is used to instantiate an mgp str model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the mgp str alibaba damo mgp str base https huggingface co alibaba damo mgp str base architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args image_size list int optional defaults to 32 128 the size resolution of each image patch_size int optional defaults to 4 the size resolution of each patch num_channels int optional defaults to 3 the number of input channels max_token_length int optional defaults to 27 the max number of output tokens num_character_labels int optional defaults to 38 the number of classes for character head num_bpe_labels int optional defaults to 50257 the number of classes for bpe head num_wordpiece_labels int optional defaults to 30522 the number of classes for wordpiece head hidden_size int optional defaults to 768 the embedding dimension num_hidden_layers int optional defaults to 12 number of hidden layers in the transformer encoder num_attention_heads int optional defaults to 12 number of attention heads for each attention layer in the transformer encoder mlp_ratio float optional defaults to 4 0 the ratio of mlp hidden dim to embedding dim qkv_bias bool optional defaults to true whether to add a bias to the queries keys and values distilled bool optional defaults to false model includes a distillation token and head as in deit models layer_norm_eps float optional defaults to 1e 05 the epsilon used by the layer normalization layers drop_rate float optional defaults to 0 0 the dropout probability for all fully connected layers in the embeddings encoder attn_drop_rate float optional defaults to 0 0 the dropout ratio for the attention probabilities drop_path_rate float optional defaults to 0 0 the stochastic depth rate output_a3_attentions bool optional defaults to false whether or not the model should returns a 3 module attentions initializer_range float optional defaults to 0 02 the standard deviation of the truncated_normal_initializer for initializing all weight matrices example python from transformers import mgpstrconfig mgpstrforscenetextrecognition initializing a mgpstr mgp str base style configuration configuration mgpstrconfig initializing a model with random weights from the mgp str base style configuration model mgpstrforscenetextrecognition configuration accessing the model configuration configuration model config
from ...configuration_utils import PretrainedConfig
from ...utils import logging


logger = logging.get_logger(__name__)

MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "alibaba-damo/mgp-str-base": "https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json",
}


class MgpstrConfig(PretrainedConfig):
    r

    model_type = "mgp-str"

    def __init__(
        self,
        image_size=[32, 128],
        patch_size=4,
        num_channels=3,
        max_token_length=27,
        num_character_labels=38,
        num_bpe_labels=50257,
        num_wordpiece_labels=30522,
        hidden_size=768,
        num_hidden_layers=12,
        num_attention_heads=12,
        mlp_ratio=4.0,
        qkv_bias=True,
        distilled=False,
        layer_norm_eps=1e-5,
        drop_rate=0.0,
        attn_drop_rate=0.0,
        drop_path_rate=0.0,
        output_a3_attentions=False,
        initializer_range=0.02,
        **kwargs,
    ):
        super().__init__(**kwargs)

        self.image_size = image_size
        self.patch_size = patch_size
        self.num_channels = num_channels
        self.max_token_length = max_token_length
        self.num_character_labels = num_character_labels
        self.num_bpe_labels = num_bpe_labels
        self.num_wordpiece_labels = num_wordpiece_labels
        self.hidden_size = hidden_size
        self.num_hidden_layers = num_hidden_layers
        self.num_attention_heads = num_attention_heads
        self.mlp_ratio = mlp_ratio
        self.distilled = distilled
        self.layer_norm_eps = layer_norm_eps
        self.drop_rate = drop_rate
        self.qkv_bias = qkv_bias
        self.attn_drop_rate = attn_drop_rate
        self.drop_path_rate = drop_path_rate
        self.output_a3_attentions = output_a3_attentions
        self.initializer_range = initializer_range