yangwang825
commited on
Create configuration_audio_spectrogram_transformer.py
Browse files
configuration_audio_spectrogram_transformer.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 transformers.configuration_utils import PretrainedConfig
|
18 |
+
from transformers.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 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
32 |
+
documentation from [`PretrainedConfig`] for more information.
|
33 |
+
Args:
|
34 |
+
hidden_size (`int`, *optional*, defaults to 768):
|
35 |
+
Dimensionality of the encoder layers and the pooler layer.
|
36 |
+
num_hidden_layers (`int`, *optional*, defaults to 12):
|
37 |
+
Number of hidden layers in the Transformer encoder.
|
38 |
+
num_attention_heads (`int`, *optional*, defaults to 12):
|
39 |
+
Number of attention heads for each attention layer in the Transformer encoder.
|
40 |
+
intermediate_size (`int`, *optional*, defaults to 3072):
|
41 |
+
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
|
42 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
|
43 |
+
The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
|
44 |
+
`"relu"`, `"selu"` and `"gelu_new"` are supported.
|
45 |
+
hidden_dropout_prob (`float`, *optional*, defaults to 0.0):
|
46 |
+
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
|
47 |
+
attention_probs_dropout_prob (`float`, *optional*, defaults to 0.0):
|
48 |
+
The dropout ratio for the attention probabilities.
|
49 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
50 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
51 |
+
layer_norm_eps (`float`, *optional*, defaults to 1e-12):
|
52 |
+
The epsilon used by the layer normalization layers.
|
53 |
+
patch_size (`int`, *optional*, defaults to 16):
|
54 |
+
The size (resolution) of each patch.
|
55 |
+
qkv_bias (`bool`, *optional*, defaults to `True`):
|
56 |
+
Whether to add a bias to the queries, keys and values.
|
57 |
+
frequency_stride (`int`, *optional*, defaults to 10):
|
58 |
+
Frequency stride to use when patchifying the spectrograms.
|
59 |
+
time_stride (`int`, *optional*, defaults to 10):
|
60 |
+
Temporal stride to use when patchifying the spectrograms.
|
61 |
+
max_length (`int`, *optional*, defaults to 1024):
|
62 |
+
Temporal dimension of the spectrograms.
|
63 |
+
num_mel_bins (`int`, *optional*, defaults to 128):
|
64 |
+
Frequency dimension of the spectrograms (number of Mel-frequency bins).
|
65 |
+
Example:
|
66 |
+
```python
|
67 |
+
>>> from transformers import ASTConfig, ASTModel
|
68 |
+
>>> # Initializing a AST MIT/ast-finetuned-audioset-10-10-0.4593 style configuration
|
69 |
+
>>> configuration = ASTConfig()
|
70 |
+
>>> # Initializing a model (with random weights) from the MIT/ast-finetuned-audioset-10-10-0.4593 style configuration
|
71 |
+
>>> model = ASTModel(configuration)
|
72 |
+
>>> # Accessing the model configuration
|
73 |
+
>>> configuration = model.config
|
74 |
+
```"""
|
75 |
+
|
76 |
+
model_type = "audio-spectrogram-transformer"
|
77 |
+
|
78 |
+
def __init__(
|
79 |
+
self,
|
80 |
+
hidden_size=768,
|
81 |
+
num_hidden_layers=12,
|
82 |
+
num_attention_heads=12,
|
83 |
+
intermediate_size=3072,
|
84 |
+
hidden_act="gelu",
|
85 |
+
hidden_dropout_prob=0.0,
|
86 |
+
attention_probs_dropout_prob=0.0,
|
87 |
+
initializer_range=0.02,
|
88 |
+
layer_norm_eps=1e-12,
|
89 |
+
patch_size=16,
|
90 |
+
qkv_bias=True,
|
91 |
+
frequency_stride=10,
|
92 |
+
time_stride=10,
|
93 |
+
max_length=1024,
|
94 |
+
num_mel_bins=128,
|
95 |
+
**kwargs,
|
96 |
+
):
|
97 |
+
super().__init__(**kwargs)
|
98 |
+
|
99 |
+
self.hidden_size = hidden_size
|
100 |
+
self.num_hidden_layers = num_hidden_layers
|
101 |
+
self.num_attention_heads = num_attention_heads
|
102 |
+
self.intermediate_size = intermediate_size
|
103 |
+
self.hidden_act = hidden_act
|
104 |
+
self.hidden_dropout_prob = hidden_dropout_prob
|
105 |
+
self.attention_probs_dropout_prob = attention_probs_dropout_prob
|
106 |
+
self.initializer_range = initializer_range
|
107 |
+
self.layer_norm_eps = layer_norm_eps
|
108 |
+
self.patch_size = patch_size
|
109 |
+
self.qkv_bias = qkv_bias
|
110 |
+
self.frequency_stride = frequency_stride
|
111 |
+
self.time_stride = time_stride
|
112 |
+
self.max_length = max_length
|
113 |
+
self.num_mel_bins = num_mel_bins
|