codingutf8 google ai and 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 canine model configuration from configurationutils import pretrainedconfig from utils import logging logger logging getloggername caninepretrainedconfigarchivemap googlecanines https huggingface cogooglecaninesresolvemainconfig json see all canine models at https huggingface comodels filtercanine class canineconfigpretrainedconfig r this is the configuration class to store the configuration of a caninemodel it is used to instantiate an canine 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 canine googlecanineshttps huggingface cogooglecanines architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args hiddensize int optional defaults to 768 dimension of the encoder layers and the pooler layer numhiddenlayers int optional defaults to 12 number of hidden layers in the deep transformer encoder numattentionheads int optional defaults to 12 number of attention heads for each attention layer in the transformer encoders intermediatesize int optional defaults to 3072 dimension of the intermediate i e feedforward layer in the transformer encoders hiddenact str or function optional defaults to gelu the nonlinear activation function function or string in the encoder and pooler if string gelu relu selu and gelunew are supported hiddendropoutprob float optional defaults to 0 1 the dropout probabilitiy for all fully connected layers in the embeddings encoders and pooler attentionprobsdropoutprob float optional defaults to 0 1 the dropout ratio for the attention probabilities maxpositionembeddings int optional defaults to 16384 the maximum sequence length that this model might ever be used with typevocabsize int optional defaults to 16 the vocabulary size of the tokentypeids passed when calling caninemodel initializerrange float optional defaults to 0 02 the standard deviation of the truncatednormalinitializer for initializing all weight matrices layernormeps float optional defaults to 1e12 the epsilon used by the layer normalization layers padtokenid int optional defaults to 0 padding token id bostokenid int optional defaults to 57344 beginning of stream token id eostokenid int optional defaults to 57345 end of stream token id downsamplingrate int optional defaults to 4 the rate at which to downsample the original character sequence length before applying the deep transformer encoder upsamplingkernelsize int optional defaults to 4 the kernel size i e the number of characters in each window of the convolutional projection layer when projecting back from hiddensize2 to hiddensize numhashfunctions int optional defaults to 8 the number of hash functions to use each hash function has its own embedding matrix numhashbuckets int optional defaults to 16384 the number of hash buckets to use localtransformerstride int optional defaults to 128 the stride of the local attention of the first shallow transformer encoder defaults to 128 for good tpuxla memory alignment example python from transformers import canineconfig caninemodel initializing a canine googlecanines style configuration configuration canineconfig initializing a model with random weights from the googlecanines style configuration model caninemodelconfiguration accessing the model configuration configuration model config modeltype canine def init self hiddensize768 numhiddenlayers12 numattentionheads12 intermediatesize3072 hiddenactgelu hiddendropoutprob0 1 attentionprobsdropoutprob0 1 maxpositionembeddings16384 typevocabsize16 initializerrange0 02 layernormeps1e12 padtokenid0 bostokenid0xe000 eostokenid0xe001 downsamplingrate4 upsamplingkernelsize4 numhashfunctions8 numhashbuckets16384 localtransformerstride128 good tpuxla memory alignment kwargs super initpadtokenidpadtokenid bostokenidbostokenid eostokenideostokenid kwargs self maxpositionembeddings maxpositionembeddings self hiddensize hiddensize self numhiddenlayers numhiddenlayers self numattentionheads numattentionheads self intermediatesize intermediatesize self hiddenact hiddenact self hiddendropoutprob hiddendropoutprob self attentionprobsdropoutprob attentionprobsdropoutprob self initializerrange initializerrange self typevocabsize typevocabsize self layernormeps layernormeps character config self downsamplingrate downsamplingrate self upsamplingkernelsize upsamplingkernelsize self numhashfunctions numhashfunctions self numhashbuckets numhashbuckets self localtransformerstride localtransformerstride coding utf 8 google ai and 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 canine model configuration see all canine models at https huggingface co models filter canine this is the configuration class to store the configuration of a caninemodel it is used to instantiate an canine 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 canine google canine s https huggingface co google canine s architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args hidden_size int optional defaults to 768 dimension of the encoder layers and the pooler layer num_hidden_layers int optional defaults to 12 number of hidden layers in the deep transformer encoder num_attention_heads int optional defaults to 12 number of attention heads for each attention layer in the transformer encoders intermediate_size int optional defaults to 3072 dimension of the intermediate i e feed forward layer in the transformer encoders hidden_act str or function optional defaults to gelu the non linear activation function function or string in the encoder and pooler if string gelu relu selu and gelu_new are supported hidden_dropout_prob float optional defaults to 0 1 the dropout probabilitiy for all fully connected layers in the embeddings encoders and pooler attention_probs_dropout_prob float optional defaults to 0 1 the dropout ratio for the attention probabilities max_position_embeddings int optional defaults to 16384 the maximum sequence length that this model might ever be used with type_vocab_size int optional defaults to 16 the vocabulary size of the token_type_ids passed when calling caninemodel initializer_range float optional defaults to 0 02 the standard deviation of the truncated_normal_initializer for initializing all weight matrices layer_norm_eps float optional defaults to 1e 12 the epsilon used by the layer normalization layers pad_token_id int optional defaults to 0 padding token id bos_token_id int optional defaults to 57344 beginning of stream token id eos_token_id int optional defaults to 57345 end of stream token id downsampling_rate int optional defaults to 4 the rate at which to downsample the original character sequence length before applying the deep transformer encoder upsampling_kernel_size int optional defaults to 4 the kernel size i e the number of characters in each window of the convolutional projection layer when projecting back from hidden_size 2 to hidden_size num_hash_functions int optional defaults to 8 the number of hash functions to use each hash function has its own embedding matrix num_hash_buckets int optional defaults to 16384 the number of hash buckets to use local_transformer_stride int optional defaults to 128 the stride of the local attention of the first shallow transformer encoder defaults to 128 for good tpu xla memory alignment example python from transformers import canineconfig caninemodel initializing a canine google canine s style configuration configuration canineconfig initializing a model with random weights from the google canine s style configuration model caninemodel configuration accessing the model configuration configuration model config good tpu xla memory alignment character config
from ...configuration_utils import PretrainedConfig
from ...utils import logging


logger = logging.get_logger(__name__)

CANINE_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "google/canine-s": "https://huggingface.co/google/canine-s/resolve/main/config.json",
    
}


class CanineConfig(PretrainedConfig):
    r

    model_type = "canine"

    def __init__(
        self,
        hidden_size=768,
        num_hidden_layers=12,
        num_attention_heads=12,
        intermediate_size=3072,
        hidden_act="gelu",
        hidden_dropout_prob=0.1,
        attention_probs_dropout_prob=0.1,
        max_position_embeddings=16384,
        type_vocab_size=16,
        initializer_range=0.02,
        layer_norm_eps=1e-12,
        pad_token_id=0,
        bos_token_id=0xE000,
        eos_token_id=0xE001,
        downsampling_rate=4,
        upsampling_kernel_size=4,
        num_hash_functions=8,
        num_hash_buckets=16384,
        local_transformer_stride=128,  
        **kwargs,
    ):
        super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)

        self.max_position_embeddings = max_position_embeddings
        self.hidden_size = hidden_size
        self.num_hidden_layers = num_hidden_layers
        self.num_attention_heads = num_attention_heads
        self.intermediate_size = intermediate_size
        self.hidden_act = hidden_act
        self.hidden_dropout_prob = hidden_dropout_prob
        self.attention_probs_dropout_prob = attention_probs_dropout_prob
        self.initializer_range = initializer_range
        self.type_vocab_size = type_vocab_size
        self.layer_norm_eps = layer_norm_eps

        
        self.downsampling_rate = downsampling_rate
        self.upsampling_kernel_size = upsampling_kernel_size
        self.num_hash_functions = num_hash_functions
        self.num_hash_buckets = num_hash_buckets
        self.local_transformer_stride = local_transformer_stride