audio_spectrogram_transformer
mindnlp.transformers.models.audio_spectrogram_transformer.configuration_audio_spectrogram_transformer.AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP = {'MIT/ast-finetuned-audioset-10-10-0.4593': 'https://hf-mirror.com/MIT/ast-finetuned-audioset-10-10-0.4593/resolve/main/config.json'}
module-attribute
¶
mindnlp.transformers.models.audio_spectrogram_transformer.configuration_audio_spectrogram_transformer.ASTConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [ASTModel
]. It is used to instantiate an AST
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 AST
MIT/ast-finetuned-audioset-10-10-0.4593
architecture.
Configuration objects inherit from [PretrainedConfig
] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig
] for more information.
PARAMETER | DESCRIPTION |
---|---|
hidden_size |
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
intermediate_size |
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
TYPE:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
hidden_dropout_prob |
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
attention_probs_dropout_prob |
The dropout ratio for the attention probabilities.
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
patch_size |
The size (resolution) of each patch.
TYPE:
|
qkv_bias |
Whether to add a bias to the queries, keys and values.
TYPE:
|
frequency_stride |
Frequency stride to use when patchifying the spectrograms.
TYPE:
|
time_stride |
Temporal stride to use when patchifying the spectrograms.
TYPE:
|
max_length |
Temporal dimension of the spectrograms.
TYPE:
|
num_mel_bins |
Frequency dimension of the spectrograms (number of Mel-frequency bins).
TYPE:
|
Example
>>> from transformers import ASTConfig, ASTModel
...
>>> # Initializing a AST MIT/ast-finetuned-audioset-10-10-0.4593 style configuration
>>> configuration = ASTConfig()
...
>>> # Initializing a model (with random weights) from the MIT/ast-finetuned-audioset-10-10-0.4593 style configuration
>>> model = ASTModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/configuration_audio_spectrogram_transformer.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.configuration_audio_spectrogram_transformer.ASTConfig.__init__(hidden_size=768, num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072, hidden_act='gelu', hidden_dropout_prob=0.0, attention_probs_dropout_prob=0.0, initializer_range=0.02, layer_norm_eps=1e-12, patch_size=16, qkv_bias=True, frequency_stride=10, time_stride=10, max_length=1024, num_mel_bins=128, **kwargs)
¶
Initializes an instance of ASTConfig.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
hidden_size |
The size of the hidden layers. Defaults to 768.
TYPE:
|
num_hidden_layers |
The number of hidden layers. Defaults to 12.
TYPE:
|
num_attention_heads |
The number of attention heads. Defaults to 12.
TYPE:
|
intermediate_size |
The size of the intermediate layer. Defaults to 3072.
TYPE:
|
hidden_act |
The activation function for the hidden layers. Defaults to 'gelu'.
TYPE:
|
hidden_dropout_prob |
The dropout probability for the hidden layers. Defaults to 0.0.
TYPE:
|
attention_probs_dropout_prob |
The dropout probability for the attention probabilities. Defaults to 0.0.
TYPE:
|
initializer_range |
The range for parameter initialization. Defaults to 0.02.
TYPE:
|
layer_norm_eps |
The epsilon value for layer normalization. Defaults to 1e-12.
TYPE:
|
patch_size |
The size of the patch. Defaults to 16.
TYPE:
|
qkv_bias |
Whether to include bias in the query, key, and value tensors. Defaults to True.
TYPE:
|
frequency_stride |
The stride for frequency. Defaults to 10.
TYPE:
|
time_stride |
The stride for time. Defaults to 10.
TYPE:
|
max_length |
The maximum length. Defaults to 1024.
TYPE:
|
num_mel_bins |
The number of Mel bins. Defaults to 128.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/configuration_audio_spectrogram_transformer.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.feature_extraction_audio_spectrogram_transformer.ASTFeatureExtractor
¶
Bases: SequenceFeatureExtractor
Constructs a Audio Spectrogram Transformer (AST) feature extractor.
This feature extractor inherits from [~feature_extraction_sequence_utils.SequenceFeatureExtractor
] which contains
most of the main methods. Users should refer to this superclass for more information regarding those methods.
This class extracts mel-filter bank features from raw speech using TorchAudio if installed or using numpy otherwise, pads/truncates them to a fixed length and normalizes them using a mean and standard deviation.
PARAMETER | DESCRIPTION |
---|---|
feature_size |
The feature dimension of the extracted features.
TYPE:
|
sampling_rate |
The sampling rate at which the audio files should be digitalized expressed in hertz (Hz).
TYPE:
|
num_mel_bins |
Number of Mel-frequency bins.
TYPE:
|
max_length |
Maximum length to which to pad/truncate the extracted features.
TYPE:
|
do_normalize |
Whether or not to normalize the log-Mel features using
TYPE:
|
mean |
The mean value used to normalize the log-Mel features. Uses the AudioSet mean by default.
TYPE:
|
std |
The standard deviation value used to normalize the log-Mel features. Uses the AudioSet standard deviation by default.
TYPE:
|
return_attention_mask |
Whether or not [
TYPE:
|
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.feature_extraction_audio_spectrogram_transformer.ASTFeatureExtractor.__call__(raw_speech, sampling_rate=None, return_tensors=None, **kwargs)
¶
Main method to featurize and prepare for the model one or several sequence(s).
PARAMETER | DESCRIPTION |
---|---|
raw_speech |
The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float values, a list of numpy arrays or a list of list of float values. Must be mono channel audio, not stereo, i.e. single float per timestep.
TYPE:
|
sampling_rate |
The sampling rate at which the
TYPE:
|
return_tensors |
If set, will return tensors instead of list of python integers. Acceptable values are:
TYPE:
|
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.feature_extraction_audio_spectrogram_transformer.ASTFeatureExtractor.__init__(feature_size=1, sampling_rate=16000, num_mel_bins=128, max_length=1024, padding_value=0.0, do_normalize=True, mean=-4.2677393, std=4.5689974, return_attention_mask=False, **kwargs)
¶
Initializes an instance of the ASTFeatureExtractor class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
feature_size |
The size of the input features. Defaults to 1.
TYPE:
|
sampling_rate |
The sampling rate of the audio. Defaults to 16000.
TYPE:
|
num_mel_bins |
The number of mel bins for mel filtering. Defaults to 128.
TYPE:
|
max_length |
The maximum length of the input. Defaults to 1024.
TYPE:
|
padding_value |
The value used for padding sequences. Defaults to 0.0.
TYPE:
|
do_normalize |
Whether to normalize the input features. Defaults to True.
TYPE:
|
mean |
The mean value for input feature normalization. Defaults to -4.2677393.
TYPE:
|
std |
The standard deviation value for input feature normalization. Defaults to 4.5689974.
TYPE:
|
return_attention_mask |
Whether to return attention mask. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.feature_extraction_audio_spectrogram_transformer.ASTFeatureExtractor.normalize(input_values)
¶
Normalize the input values using the mean and standard deviation stored in the ASTFeatureExtractor instance.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ASTFeatureExtractor class. It holds the mean and standard deviation values necessary for normalization.
TYPE:
|
input_values |
A NumPy array containing the input values to be normalized. The shape of the array must be compatible with the mean and standard deviation arrays stored in the ASTFeatureExtractor instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
np.ndarray: A NumPy array with the normalized values. The normalization is performed by subtracting the mean value and dividing by twice the standard deviation value. |
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST = ['MIT/ast-finetuned-audioset-10-10-0.4593']
module-attribute
¶
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.ASTForAudioClassification
¶
Bases: ASTPreTrainedModel
ASTForAudioClassification is a class that implements a model for audio classification using the AST (Audio Spectrogram Transformer) architecture. This class inherits from ASTPreTrainedModel and provides methods for initializing the model with a configuration, and forwarding the model for audio classification tasks.
ATTRIBUTE | DESCRIPTION |
---|---|
num_labels |
Number of labels for the audio classification task.
|
audio_spectrogram_transformer |
Instance of ASTModel for processing audio input.
|
classifier |
Instance of ASTMLPHead for classification using the model's pooled output.
|
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.ASTForAudioClassification.__init__(config)
¶
Initializes an instance of the ASTForAudioClassification class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing the necessary parameters for ASTForAudioClassification initialization.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.ASTForAudioClassification.forward(input_values=None, head_mask=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the audio classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.ASTModel
¶
Bases: ASTPreTrainedModel
ASTModel is a class representing a model for Abstract Syntax Trees (AST) processing. This class inherits from ASTPreTrainedModel and includes methods for initializing the model, getting input embeddings, pruning heads, and forwarding the model's output.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
An instance of ASTConfig containing configuration parameters for the model.
|
embeddings |
An instance of ASTEmbeddings for handling AST embeddings.
|
encoder |
An instance of ASTEncoder for encoding AST inputs.
|
layernorm |
A layer normalization module with specified hidden size and epsilon.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the ASTModel with the given configuration. |
get_input_embeddings |
Returns the patch embeddings used by the model. |
_prune_heads |
Prunes specified attention heads in the model. |
forward |
Constructs the model output based on input values and optional arguments. |
The forward method handles input processing, encoding, and output generation based on the specified parameters. Pruning heads allows for fine-tuning the attention mechanism of the model. Overall, ASTModel provides a comprehensive solution for AST-based tasks.
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.ASTModel.__init__(config)
¶
Initializes an instance of the ASTModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object for the ASTModel. t provides necessary settings and hyperparameters for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.ASTModel.forward(input_values=None, head_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
This method forwards the ASTModel by processing the input values through the model's layers.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ASTModel.
TYPE:
|
input_values |
The input values to be processed by the model. Default is None.
TYPE:
|
head_mask |
The head mask for controlling the attention in the encoder layers. Default is None.
TYPE:
|
output_attentions |
Whether to output attentions. Default is None.
TYPE:
|
output_hidden_states |
Whether to output hidden states. Default is None.
TYPE:
|
return_dict |
Whether to return a dict. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPooling]
|
Union[Tuple, BaseModelOutputWithPooling]: The forwarded output, which can be a tuple or BaseModelOutputWithPooling object. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If input_values is None, a ValueError is raised with the message 'You have to specify input_values'. |
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.ASTModel.get_input_embeddings()
¶
Retrieve the input embeddings from the AST model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ASTModel class. It represents the current object of the ASTModel. This parameter is required as the method is an instance method.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ASTPatchEmbeddings
|
An instance of ASTPatchEmbeddings representing the input embeddings. The returned ASTPatchEmbeddings object contains the patch embeddings related to the input.
TYPE:
|
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 |
|
mindnlp.transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer.ASTPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
|