yangwang825 commited on
Commit
5fa360b
·
verified ·
1 Parent(s): 9f52360

Create configuration_audio_spectrogram_transformer.py

Browse files
configuration_audio_spectrogram_transformer.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 Google AI and The HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Audio Spectogram Transformer (AST) model configuration"""
16
+
17
+ from ...configuration_utils import PretrainedConfig
18
+ from ...utils import logging
19
+
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+
24
+ class ASTConfig(PretrainedConfig):
25
+ r"""
26
+ This is the configuration class to store the configuration of a [`ASTModel`]. It is used to instantiate an AST
27
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
28
+ defaults will yield a similar configuration to that of the AST
29
+ [MIT/ast-finetuned-audioset-10-10-0.4593](https://huggingface.co/MIT/ast-finetuned-audioset-10-10-0.4593)
30
+ architecture.
31
+
32
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
33
+ documentation from [`PretrainedConfig`] for more information.
34
+
35
+ Args:
36
+ hidden_size (`int`, *optional*, defaults to 768):
37
+ Dimensionality of the encoder layers and the pooler layer.
38
+ num_hidden_layers (`int`, *optional*, defaults to 12):
39
+ Number of hidden layers in the Transformer encoder.
40
+ num_attention_heads (`int`, *optional*, defaults to 12):
41
+ Number of attention heads for each attention layer in the Transformer encoder.
42
+ intermediate_size (`int`, *optional*, defaults to 3072):
43
+ Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
44
+ hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
45
+ The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
46
+ `"relu"`, `"selu"` and `"gelu_new"` are supported.
47
+ hidden_dropout_prob (`float`, *optional*, defaults to 0.0):
48
+ The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
49
+ attention_probs_dropout_prob (`float`, *optional*, defaults to 0.0):
50
+ The dropout ratio for the attention probabilities.
51
+ initializer_range (`float`, *optional*, defaults to 0.02):
52
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
53
+ layer_norm_eps (`float`, *optional*, defaults to 1e-12):
54
+ The epsilon used by the layer normalization layers.
55
+ patch_size (`int`, *optional*, defaults to 16):
56
+ The size (resolution) of each patch.
57
+ qkv_bias (`bool`, *optional*, defaults to `True`):
58
+ Whether to add a bias to the queries, keys and values.
59
+ frequency_stride (`int`, *optional*, defaults to 10):
60
+ Frequency stride to use when patchifying the spectrograms.
61
+ time_stride (`int`, *optional*, defaults to 10):
62
+ Temporal stride to use when patchifying the spectrograms.
63
+ max_length (`int`, *optional*, defaults to 1024):
64
+ Temporal dimension of the spectrograms.
65
+ num_mel_bins (`int`, *optional*, defaults to 128):
66
+ Frequency dimension of the spectrograms (number of Mel-frequency bins).
67
+
68
+ Example:
69
+
70
+ ```python
71
+ >>> from transformers import ASTConfig, ASTModel
72
+
73
+ >>> # Initializing a AST MIT/ast-finetuned-audioset-10-10-0.4593 style configuration
74
+ >>> configuration = ASTConfig()
75
+
76
+ >>> # Initializing a model (with random weights) from the MIT/ast-finetuned-audioset-10-10-0.4593 style configuration
77
+ >>> model = ASTModel(configuration)
78
+
79
+ >>> # Accessing the model configuration
80
+ >>> configuration = model.config
81
+ ```"""
82
+
83
+ model_type = "audio-spectrogram-transformer"
84
+
85
+ def __init__(
86
+ self,
87
+ hidden_size=768,
88
+ num_hidden_layers=12,
89
+ num_attention_heads=12,
90
+ intermediate_size=3072,
91
+ hidden_act="gelu",
92
+ hidden_dropout_prob=0.0,
93
+ attention_probs_dropout_prob=0.0,
94
+ initializer_range=0.02,
95
+ layer_norm_eps=1e-12,
96
+ patch_size=16,
97
+ frequency_patch_size=None,
98
+ time_patch_size=None,
99
+ qkv_bias=True,
100
+ frequency_stride=10,
101
+ time_stride=10,
102
+ max_length=1024,
103
+ num_mel_bins=128,
104
+ **kwargs,
105
+ ):
106
+ super().__init__(**kwargs)
107
+
108
+ self.hidden_size = hidden_size
109
+ self.num_hidden_layers = num_hidden_layers
110
+ self.num_attention_heads = num_attention_heads
111
+ self.intermediate_size = intermediate_size
112
+ self.hidden_act = hidden_act
113
+ self.hidden_dropout_prob = hidden_dropout_prob
114
+ self.attention_probs_dropout_prob = attention_probs_dropout_prob
115
+ self.initializer_range = initializer_range
116
+ self.layer_norm_eps = layer_norm_eps
117
+ self.patch_size = patch_size
118
+ self.frequency_patch_size = frequency_patch_size
119
+ self.time_patch_size = time_patch_size
120
+ self.qkv_bias = qkv_bias
121
+ self.frequency_stride = frequency_stride
122
+ self.time_stride = time_stride
123
+ self.max_length = max_length
124
+ self.num_mel_bins = num_mel_bins