codingutf8 2022 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 mctct model configuration from configurationutils import pretrainedconfig from utils import logging logger logging getloggername mctctpretrainedconfigarchivemap speechbrainmctctlarge https huggingface cospeechbrainmctctlargeresolvemainconfig json see all mctct models at https huggingface comodels filtermctct class mctctconfigpretrainedconfig r this is the configuration class to store the configuration of a mctctmodel it is used to instantiate an mctct 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 mctct speechbrainmctctlargehttps huggingface cospeechbrainmctctlarge architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args vocabsize int optional defaults to 8065 vocabulary size of the mctct model defines the number of different tokens that can be represented by the inputsids passed when calling mctctmodel hiddensize int optional defaults to 1536 dimension of the encoder layers and the pooler layer numhiddenlayers int optional defaults to 36 number of hidden layers in the transformer encoder intermediatesize int optional defaults to 6144 dimension of the intermediate i e feedforward layer in the transformer encoder numattentionheads int optional defaults to 4 number of attention heads for each attention layer in the transformer encoder attentionheaddim int optional defaults to 384 dimensions of each attention head for each attention layer in the transformer encoder maxpositionembeddings int optional defaults to 920 the maximum sequence length that this model might ever be used with after logmel spectrogram extraction layernormeps float optional defaults to 1e05 the epsilon used by the layer normalization layers layerdrop float optional defaults to 0 3 the probability of dropping an encoder layer during training the default 0 3 value is used in the original implementation hiddenact str or function optional defaults to relu the nonlinear activation function function or string in the encoder and pooler if string gelu relu selu and gelunew are supported initializerrange float optional defaults to 0 02 the standard deviation of the truncatednormalinitializer for initializing all weight matrices hiddendropoutprob float optional defaults to 0 3 the dropout probabilitiy for all fully connected layers in the embeddings encoder and pooler attentionprobsdropoutprob float optional defaults to 0 3 the dropout ratio for the attention probabilities padtokenid int optional defaults to 1 the tokenizer index of the pad token bostokenid int optional defaults to 0 the tokenizer index of the bos token eostokenid int optional defaults to 2 the tokenizer index of the eos token convgludim int optional defaults to 1 the dimension of the output of the conv1dsubsampler layer in which glu is applied on though the original flashlight code uses the value of 2 here it s adapted to 1 due to transposition differences convdropout int optional defaults to 0 3 the probability of randomly dropping the conv1dsubsampler layer during training numconvlayers int optional defaults to 1 number of convolution layers before applying transformer encoder layers convkernel sequenceint optional defaults to 7 the kernel size of the 1d convolution applied before transformer layers lenconvkernel must be equal to numconvlayers convstride sequenceint optional defaults to 3 the stride length of the 1d convolution applied before transformer layers lenconvstride must be equal to numconvlayers inputfeatperchannel int optional defaults to 80 feature dimensions of the channels of the input to the conv1d layer inputchannels int optional defaults to 1 number of input channels of the input to the conv1d layer convchannels listint optional channel sizes of intermediate conv1d layers ctclossreduction str optional defaults to sum specifies the reduction to apply to the output of torch nn ctcloss only relevant when training an instance of mctctforctc ctczeroinfinity bool optional defaults to false whether to zero infinite losses and the associated gradients of torch nn ctcloss infinite losses mainly occur when the inputs are too short to be aligned to the targets only relevant when training an instance of mctctforctc example python from transformers import mctctconfig mctctmodel initializing a mctct mctctlarge style configuration configuration mctctconfig initializing a model with random weights from the mctctlarge style configuration model mctctmodelconfiguration accessing the model configuration configuration model config modeltype mctct def init self vocabsize8065 hiddensize1536 numhiddenlayers36 intermediatesize6144 numattentionheads4 attentionheaddim384 maxpositionembeddings920 layernormeps1e5 layerdrop0 3 hiddenactrelu initializerrange0 02 hiddendropoutprob0 3 attentionprobsdropoutprob0 3 padtokenid1 bostokenid0 eostokenid2 convgludim1 convdropout0 3 numconvlayers1 convkernel7 convstride3 inputfeatperchannel80 inputchannels1 convchannelsnone ctclossreductionsum ctczeroinfinityfalse kwargs super initkwargs padtokenidpadtokenid bostokenidbostokenid eostokenideostokenid self vocabsize vocabsize self hiddensize hiddensize self numhiddenlayers numhiddenlayers self intermediatesize intermediatesize self numattentionheads numattentionheads self attentionheaddim attentionheaddim self maxpositionembeddings maxpositionembeddings self layernormeps layernormeps self layerdrop layerdrop self hiddenact hiddenact self initializerrange initializerrange self hiddendropoutprob hiddendropoutprob self attentionprobsdropoutprob attentionprobsdropoutprob self padtokenid padtokenid self bostokenid bostokenid self eostokenid eostokenid self convgludim convgludim self convdropout convdropout self numconvlayers numconvlayers self inputfeatperchannel inputfeatperchannel self inputchannels inputchannels self convchannels convchannels self ctclossreduction ctclossreduction self ctczeroinfinity ctczeroinfinity prevents config testing fail with exporting to json self convkernel listconvkernel self convstride listconvstride if lenself convkernel self numconvlayers raise valueerror configuration for convolutional module is incorrect it is required that lenconfig convkernel config numconvlayers fbut is lenconfig convkernel lenself convkernel fconfig numconvlayers self numconvlayers coding utf 8 2022 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 m ctc t model configuration see all m ctc t models at https huggingface co models filter mctct this is the configuration class to store the configuration of a mctctmodel it is used to instantiate an m ctc t 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 m ctc t speechbrain m ctc t large https huggingface co speechbrain m ctc t large architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args vocab_size int optional defaults to 8065 vocabulary size of the m ctc t model defines the number of different tokens that can be represented by the inputs_ids passed when calling mctctmodel hidden_size int optional defaults to 1536 dimension of the encoder layers and the pooler layer num_hidden_layers int optional defaults to 36 number of hidden layers in the transformer encoder intermediate_size int optional defaults to 6144 dimension of the intermediate i e feed forward layer in the transformer encoder num_attention_heads int optional defaults to 4 number of attention heads for each attention layer in the transformer encoder attention_head_dim int optional defaults to 384 dimensions of each attention head for each attention layer in the transformer encoder max_position_embeddings int optional defaults to 920 the maximum sequence length that this model might ever be used with after log mel spectrogram extraction layer_norm_eps float optional defaults to 1e 05 the epsilon used by the layer normalization layers layerdrop float optional defaults to 0 3 the probability of dropping an encoder layer during training the default 0 3 value is used in the original implementation hidden_act str or function optional defaults to relu the non linear activation function function or string in the encoder and pooler if string gelu relu selu and gelu_new are supported initializer_range float optional defaults to 0 02 the standard deviation of the truncated_normal_initializer for initializing all weight matrices hidden_dropout_prob float optional defaults to 0 3 the dropout probabilitiy for all fully connected layers in the embeddings encoder and pooler attention_probs_dropout_prob float optional defaults to 0 3 the dropout ratio for the attention probabilities pad_token_id int optional defaults to 1 the tokenizer index of the pad token bos_token_id int optional defaults to 0 the tokenizer index of the bos token eos_token_id int optional defaults to 2 the tokenizer index of the eos token conv_glu_dim int optional defaults to 1 the dimension of the output of the conv1dsubsampler layer in which glu is applied on though the original flashlight code uses the value of 2 here it s adapted to 1 due to transposition differences conv_dropout int optional defaults to 0 3 the probability of randomly dropping the conv1dsubsampler layer during training num_conv_layers int optional defaults to 1 number of convolution layers before applying transformer encoder layers conv_kernel sequence int optional defaults to 7 the kernel size of the 1d convolution applied before transformer layers len conv_kernel must be equal to num_conv_layers conv_stride sequence int optional defaults to 3 the stride length of the 1d convolution applied before transformer layers len conv_stride must be equal to num_conv_layers input_feat_per_channel int optional defaults to 80 feature dimensions of the channels of the input to the conv1d layer input_channels int optional defaults to 1 number of input channels of the input to the conv1d layer conv_channels list int optional channel sizes of intermediate conv1d layers ctc_loss_reduction str optional defaults to sum specifies the reduction to apply to the output of torch nn ctcloss only relevant when training an instance of mctctforctc ctc_zero_infinity bool optional defaults to false whether to zero infinite losses and the associated gradients of torch nn ctcloss infinite losses mainly occur when the inputs are too short to be aligned to the targets only relevant when training an instance of mctctforctc example python from transformers import mctctconfig mctctmodel initializing a m ctc t mctct large style configuration configuration mctctconfig initializing a model with random weights from the mctct large style configuration model mctctmodel configuration accessing the model configuration configuration model config prevents config testing fail with exporting to json
from ....configuration_utils import PretrainedConfig
from ....utils import logging


logger = logging.get_logger(__name__)

MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "speechbrain/m-ctc-t-large": "https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json",
    
}


class MCTCTConfig(PretrainedConfig):
    r

    model_type = "mctct"

    def __init__(
        self,
        vocab_size=8065,
        hidden_size=1536,
        num_hidden_layers=36,
        intermediate_size=6144,
        num_attention_heads=4,
        attention_head_dim=384,
        max_position_embeddings=920,
        layer_norm_eps=1e-5,
        layerdrop=0.3,
        hidden_act="relu",
        initializer_range=0.02,
        hidden_dropout_prob=0.3,
        attention_probs_dropout_prob=0.3,
        pad_token_id=1,
        bos_token_id=0,
        eos_token_id=2,
        conv_glu_dim=1,
        conv_dropout=0.3,
        num_conv_layers=1,
        conv_kernel=(7,),
        conv_stride=(3,),
        input_feat_per_channel=80,
        input_channels=1,
        conv_channels=None,
        ctc_loss_reduction="sum",
        ctc_zero_infinity=False,
        **kwargs,
    ):
        super().__init__(**kwargs, pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id)
        self.vocab_size = vocab_size
        self.hidden_size = hidden_size
        self.num_hidden_layers = num_hidden_layers
        self.intermediate_size = intermediate_size
        self.num_attention_heads = num_attention_heads
        self.attention_head_dim = attention_head_dim
        self.max_position_embeddings = max_position_embeddings
        self.layer_norm_eps = layer_norm_eps
        self.layerdrop = layerdrop
        self.hidden_act = hidden_act
        self.initializer_range = initializer_range
        self.hidden_dropout_prob = hidden_dropout_prob
        self.attention_probs_dropout_prob = attention_probs_dropout_prob
        self.pad_token_id = pad_token_id
        self.bos_token_id = bos_token_id
        self.eos_token_id = eos_token_id
        self.conv_glu_dim = conv_glu_dim
        self.conv_dropout = conv_dropout
        self.num_conv_layers = num_conv_layers
        self.input_feat_per_channel = input_feat_per_channel
        self.input_channels = input_channels
        self.conv_channels = conv_channels
        self.ctc_loss_reduction = ctc_loss_reduction
        self.ctc_zero_infinity = ctc_zero_infinity

        
        self.conv_kernel = list(conv_kernel)
        self.conv_stride = list(conv_stride)

        if len(self.conv_kernel) != self.num_conv_layers:
            raise ValueError(
                "Configuration for convolutional module is incorrect. "
                "It is required that `len(config.conv_kernel)` == `config.num_conv_layers` "
                f"but is `len(config.conv_kernel) = {len(self.conv_kernel)}`, "
                f"`config.num_conv_layers = {self.num_conv_layers}`."
            )