import{S as Fr,i as Mr,s as Pr,e as a,k as p,w as b,t as n,M as zr,c as r,d as o,m as u,a as s,x as A,h as i,b as d,N as Nr,G as t,g as h,y as w,q as $,o as S,B as y,v as Ir,L as ro}from"../../chunks/vendor-hf-doc-builder.js";import{T as qr}from"../../chunks/Tip-hf-doc-builder.js";import{D as Oe}from"../../chunks/Docstring-hf-doc-builder.js";import{C as so}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as st}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ao}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Or(E){let c,v,f,g,T;return g=new so({props:{code:`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`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> ASTConfig, ASTModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a AST MIT/ast-finetuned-audioset-10-10-0.4593 style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = ASTConfig()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a model (with random weights) from the MIT/ast-finetuned-audioset-10-10-0.4593 style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ASTModel(configuration)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = model.config`}}),{c(){c=a("p"),v=n("Example:"),f=p(),b(g.$$.fragment)},l(l){c=r(l,"P",{});var _=s(c);v=i(_,"Example:"),_.forEach(o),f=u(l),A(g.$$.fragment,l)},m(l,_){h(l,c,_),t(c,v),h(l,f,_),w(g,l,_),T=!0},p:ro,i(l){T||($(g.$$.fragment,l),T=!0)},o(l){S(g.$$.fragment,l),T=!1},d(l){l&&o(c),l&&o(f),y(g,l)}}}function Dr(E){let c,v,f,g,T;return{c(){c=a("p"),v=n("Although the recipe for forward pass needs to be defined within this function, one should call the "),f=a("code"),g=n("Module"),T=n(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(l){c=r(l,"P",{});var _=s(c);v=i(_,"Although the recipe for forward pass needs to be defined within this function, one should call the "),f=r(_,"CODE",{});var F=s(f);g=i(F,"Module"),F.forEach(o),T=i(_,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),_.forEach(o)},m(l,_){h(l,c,_),t(c,v),t(c,f),t(f,g),t(c,T)},d(l){l&&o(c)}}}function Lr(E){let c,v,f,g,T;return g=new so({props:{code:`from transformers import ASTFeatureExtractor, ASTModel
import torch
from datasets import load_dataset

dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
dataset = dataset.sort("id")
sampling_rate = dataset.features["audio"].sampling_rate

processor = ASTFeatureExtractor.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593")
model = ASTModel.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593")

# audio file is decoded on the fly
inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")
with torch.no_grad():
    outputs = model(**inputs)

last_hidden_states = outputs.last_hidden_state
list(last_hidden_states.shape)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> ASTFeatureExtractor, ASTModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;hf-internal-testing/librispeech_asr_demo&quot;</span>, <span class="hljs-string">&quot;clean&quot;</span>, split=<span class="hljs-string">&quot;validation&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.sort(<span class="hljs-string">&quot;id&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>sampling_rate = dataset.features[<span class="hljs-string">&quot;audio&quot;</span>].sampling_rate

<span class="hljs-meta">&gt;&gt;&gt; </span>processor = ASTFeatureExtractor.from_pretrained(<span class="hljs-string">&quot;MIT/ast-finetuned-audioset-10-10-0.4593&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ASTModel.from_pretrained(<span class="hljs-string">&quot;MIT/ast-finetuned-audioset-10-10-0.4593&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># audio file is decoded on the fly</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = processor(dataset[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;array&quot;</span>], sampling_rate=sampling_rate, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    outputs = model(**inputs)

<span class="hljs-meta">&gt;&gt;&gt; </span>last_hidden_states = outputs.last_hidden_state
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">list</span>(last_hidden_states.shape)
[<span class="hljs-number">1</span>, <span class="hljs-number">1214</span>, <span class="hljs-number">768</span>]`}}),{c(){c=a("p"),v=n("Example:"),f=p(),b(g.$$.fragment)},l(l){c=r(l,"P",{});var _=s(c);v=i(_,"Example:"),_.forEach(o),f=u(l),A(g.$$.fragment,l)},m(l,_){h(l,c,_),t(c,v),h(l,f,_),w(g,l,_),T=!0},p:ro,i(l){T||($(g.$$.fragment,l),T=!0)},o(l){S(g.$$.fragment,l),T=!1},d(l){l&&o(c),l&&o(f),y(g,l)}}}function Wr(E){let c,v,f,g,T;return{c(){c=a("p"),v=n("Although the recipe for forward pass needs to be defined within this function, one should call the "),f=a("code"),g=n("Module"),T=n(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(l){c=r(l,"P",{});var _=s(c);v=i(_,"Although the recipe for forward pass needs to be defined within this function, one should call the "),f=r(_,"CODE",{});var F=s(f);g=i(F,"Module"),F.forEach(o),T=i(_,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),_.forEach(o)},m(l,_){h(l,c,_),t(c,v),t(c,f),t(f,g),t(c,T)},d(l){l&&o(c)}}}function Hr(E){let c,v,f,g,T;return g=new so({props:{code:`from transformers import ASTFeatureExtractor, ASTForAudioClassification
from datasets import load_dataset
import torch

dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
dataset = dataset.sort("id")
sampling_rate = dataset.features["audio"].sampling_rate

feature_extractor = ASTFeatureExtractor.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593")
model = ASTForAudioClassification.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593")

# audio file is decoded on the fly
inputs = feature_extractor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="pt")

with torch.no_grad():
    logits = model(**inputs).logits

predicted_class_ids = torch.argmax(logits, dim=-1).item()
predicted_label = model.config.id2label[predicted_class_ids]
predicted_label`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> ASTFeatureExtractor, ASTForAudioClassification
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;hf-internal-testing/librispeech_asr_demo&quot;</span>, <span class="hljs-string">&quot;clean&quot;</span>, split=<span class="hljs-string">&quot;validation&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = dataset.sort(<span class="hljs-string">&quot;id&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>sampling_rate = dataset.features[<span class="hljs-string">&quot;audio&quot;</span>].sampling_rate

<span class="hljs-meta">&gt;&gt;&gt; </span>feature_extractor = ASTFeatureExtractor.from_pretrained(<span class="hljs-string">&quot;MIT/ast-finetuned-audioset-10-10-0.4593&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ASTForAudioClassification.from_pretrained(<span class="hljs-string">&quot;MIT/ast-finetuned-audioset-10-10-0.4593&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># audio file is decoded on the fly</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = feature_extractor(dataset[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;audio&quot;</span>][<span class="hljs-string">&quot;array&quot;</span>], sampling_rate=sampling_rate, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    logits = model(**inputs).logits

<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_class_ids = torch.argmax(logits, dim=-<span class="hljs-number">1</span>).item()
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_label = model.config.id2label[predicted_class_ids]
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_label
<span class="hljs-string">&#x27;Speech&#x27;</span>`}}),{c(){c=a("p"),v=n("Example:"),f=p(),b(g.$$.fragment)},l(l){c=r(l,"P",{});var _=s(c);v=i(_,"Example:"),_.forEach(o),f=u(l),A(g.$$.fragment,l)},m(l,_){h(l,c,_),t(c,v),h(l,f,_),w(g,l,_),T=!0},p:ro,i(l){T||($(g.$$.fragment,l),T=!0)},o(l){S(g.$$.fragment,l),T=!1},d(l){l&&o(c),l&&o(f),y(g,l)}}}function Ur(E){let c,v;return c=new so({props:{code:`# compute loss - target_label is e.g. "down"
target_label = model.config.id2label[0]
inputs["labels"] = torch.tensor([model.config.label2id[target_label]])
loss = model(**inputs).loss
round(loss.item(), 2)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># compute loss - target_label is e.g. &quot;down&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>target_label = model.config.id2label[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs[<span class="hljs-string">&quot;labels&quot;</span>] = torch.tensor([model.config.label2id[target_label]])
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = model(**inputs).loss
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">round</span>(loss.item(), <span class="hljs-number">2</span>)
<span class="hljs-number">0.17</span>`}}),{c(){b(c.$$.fragment)},l(f){A(c.$$.fragment,f)},m(f,g){w(c,f,g),v=!0},p:ro,i(f){v||($(c.$$.fragment,f),v=!0)},o(f){S(c.$$.fragment,f),v=!1},d(f){y(c,f)}}}function Vr(E){let c,v,f,g,T,l,_,F,no,kt,O,R,nt,pe,io,it,lo,Ct,P,co,ue,mo,po,De,uo,fo,jt,Le,ho,qt,We,lt,go,Ft,He,_o,Mt,J,D,vo,Ue,To,bo,fe,dt,Ao,wo,$o,he,So,ge,yo,xo,Pt,K,Ha,zt,Q,Eo,Ve,ko,Co,Nt,z,jo,_e,qo,Fo,ve,Mo,Po,It,L,X,ct,Te,zo,mt,No,Ot,C,be,Io,W,Oo,Be,Do,Lo,Ae,Wo,Ho,Uo,H,Vo,Ge,Bo,Go,Ye,Yo,Ro,Jo,Z,Dt,U,ee,pt,we,Ko,ut,Qo,Lt,x,$e,Xo,ft,Zo,ea,Se,ta,Re,oa,aa,ra,ht,sa,na,te,ye,ia,gt,la,Wt,V,oe,_t,xe,da,vt,ca,Ht,M,Ee,ma,ke,pa,Ce,ua,fa,ha,q,je,ga,B,_a,Je,va,Ta,Tt,ba,Aa,wa,ae,$a,re,Ut,G,se,bt,qe,Sa,At,ya,Vt,j,Fe,xa,wt,Ea,ka,Me,Ca,Pe,ja,qa,Fa,k,ze,Ma,Y,Pa,Ke,za,Na,$t,Ia,Oa,Da,ne,La,ie,Wa,le,Bt;return l=new st({}),pe=new st({}),Te=new st({}),be=new Oe({props:{name:"class transformers.ASTConfig",anchor:"transformers.ASTConfig",parameters:[{name:"hidden_size",val:" = 768"},{name:"num_hidden_layers",val:" = 12"},{name:"num_attention_heads",val:" = 12"},{name:"intermediate_size",val:" = 3072"},{name:"hidden_act",val:" = 'gelu'"},{name:"hidden_dropout_prob",val:" = 0.0"},{name:"attention_probs_dropout_prob",val:" = 0.0"},{name:"initializer_range",val:" = 0.02"},{name:"layer_norm_eps",val:" = 1e-12"},{name:"patch_size",val:" = 16"},{name:"qkv_bias",val:" = True"},{name:"frequency_stride",val:" = 10"},{name:"time_stride",val:" = 10"},{name:"max_length",val:" = 1024"},{name:"num_mel_bins",val:" = 128"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.ASTConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 768) &#x2014;
Dimensionality of the encoder layers and the pooler layer.`,name:"hidden_size"},{anchor:"transformers.ASTConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of hidden layers in the Transformer encoder.`,name:"num_hidden_layers"},{anchor:"transformers.ASTConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 12) &#x2014;
Number of attention heads for each attention layer in the Transformer encoder.`,name:"num_attention_heads"},{anchor:"transformers.ASTConfig.intermediate_size",description:`<strong>intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to 3072) &#x2014;
Dimensionality of the &#x201C;intermediate&#x201D; (i.e., feed-forward) layer in the Transformer encoder.`,name:"intermediate_size"},{anchor:"transformers.ASTConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code> or <code>function</code>, <em>optional</em>, defaults to <code>&quot;gelu&quot;</code>) &#x2014;
The non-linear activation function (function or string) in the encoder and pooler. If string, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;selu&quot;</code> and <code>&quot;gelu_new&quot;</code> are supported.`,name:"hidden_act"},{anchor:"transformers.ASTConfig.hidden_dropout_prob",description:`<strong>hidden_dropout_prob</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.`,name:"hidden_dropout_prob"},{anchor:"transformers.ASTConfig.attention_probs_dropout_prob",description:`<strong>attention_probs_dropout_prob</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout ratio for the attention probabilities.`,name:"attention_probs_dropout_prob"},{anchor:"transformers.ASTConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to 0.02) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.ASTConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-12) &#x2014;
The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.ASTConfig.patch_size",description:`<strong>patch_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>16</code>) &#x2014;
The size (resolution) of each patch.`,name:"patch_size"},{anchor:"transformers.ASTConfig.qkv_bias",description:`<strong>qkv_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to add a bias to the queries, keys and values.`,name:"qkv_bias"},{anchor:"transformers.ASTConfig.frequency_stride",description:`<strong>frequency_stride</strong> (<code>int</code>, <em>optional</em>, defaults to 10) &#x2014;
Frequency stride to use when patchifying the spectrograms.`,name:"frequency_stride"},{anchor:"transformers.ASTConfig.time_stride",description:`<strong>time_stride</strong> (<code>int</code>, <em>optional</em>, defaults to 10) &#x2014;
Temporal stride to use when patchifying the spectrograms.`,name:"time_stride"},{anchor:"transformers.ASTConfig.max_length",description:`<strong>max_length</strong> (<code>int</code>, <em>optional</em>, defaults to 1024) &#x2014;
Temporal dimension of the spectrograms.`,name:"max_length"},{anchor:"transformers.ASTConfig.num_mel_bins",description:`<strong>num_mel_bins</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014;
Frequency dimension of the spectrograms (number of Mel-frequency bins).`,name:"num_mel_bins"}],source:"https://github.com/huggingface/transformers/blob/v4.25.1/src/transformers/models/audio_spectrogram_transformer/configuration_audio_spectrogram_transformer.py#L31"}}),Z=new ao({props:{anchor:"transformers.ASTConfig.example",$$slots:{default:[Or]},$$scope:{ctx:E}}}),we=new st({}),$e=new Oe({props:{name:"class transformers.ASTFeatureExtractor",anchor:"transformers.ASTFeatureExtractor",parameters:[{name:"feature_size",val:" = 1"},{name:"sampling_rate",val:" = 16000"},{name:"num_mel_bins",val:" = 128"},{name:"max_length",val:" = 1024"},{name:"padding_value",val:" = 0.0"},{name:"do_normalize",val:" = True"},{name:"mean",val:" = -4.2677393"},{name:"std",val:" = 4.5689974"},{name:"return_attention_mask",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.ASTFeatureExtractor.feature_size",description:`<strong>feature_size</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The feature dimension of the extracted features.`,name:"feature_size"},{anchor:"transformers.ASTFeatureExtractor.sampling_rate",description:`<strong>sampling_rate</strong> (<code>int</code>, <em>optional</em>, defaults to 16000) &#x2014;
The sampling rate at which the audio files should be digitalized expressed in Hertz per second (Hz).`,name:"sampling_rate"},{anchor:"transformers.ASTFeatureExtractor.num_mel_bins",description:`<strong>num_mel_bins</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014;
Number of Mel-frequency bins.`,name:"num_mel_bins"},{anchor:"transformers.ASTFeatureExtractor.max_length",description:`<strong>max_length</strong> (<code>int</code>, <em>optional</em>, defaults to 1024) &#x2014;
Maximum length to which to pad/truncate the extracted features.`,name:"max_length"},{anchor:"transformers.ASTFeatureExtractor.do_normalize",description:`<strong>do_normalize</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to normalize the log-Mel features using <code>mean</code> and <code>std</code>.`,name:"do_normalize"},{anchor:"transformers.ASTFeatureExtractor.mean",description:`<strong>mean</strong> (<code>float</code>, <em>optional</em>, defaults to -4.2677393) &#x2014;
The mean value used to normalize the log-Mel features. Uses the AudioSet mean by default.`,name:"mean"},{anchor:"transformers.ASTFeatureExtractor.std",description:`<strong>std</strong> (<code>float</code>, <em>optional</em>, defaults to 4.5689974) &#x2014;
The standard deviation value used to normalize the log-Mel features. Uses the AudioSet standard deviation
by default.`,name:"std"},{anchor:"transformers.ASTFeatureExtractor.return_attention_mask",description:`<strong>return_attention_mask</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not <a href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTFeatureExtractor.__call__"><strong>call</strong>()</a> should return <code>attention_mask</code>.`,name:"return_attention_mask"}],source:"https://github.com/huggingface/transformers/blob/v4.25.1/src/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py#L33"}}),ye=new Oe({props:{name:"__call__",anchor:"transformers.ASTFeatureExtractor.__call__",parameters:[{name:"raw_speech",val:": typing.Union[numpy.ndarray, typing.List[float], typing.List[numpy.ndarray], typing.List[typing.List[float]]]"},{name:"sampling_rate",val:": typing.Optional[int] = None"},{name:"return_tensors",val:": typing.Union[str, transformers.utils.generic.TensorType, NoneType] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.ASTFeatureExtractor.__call__.raw_speech",description:`<strong>raw_speech</strong> (<code>np.ndarray</code>, <code>List[float]</code>, <code>List[np.ndarray]</code>, <code>List[List[float]]</code>) &#x2014;
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.`,name:"raw_speech"},{anchor:"transformers.ASTFeatureExtractor.__call__.sampling_rate",description:`<strong>sampling_rate</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The sampling rate at which the <code>raw_speech</code> input was sampled. It is strongly recommended to pass
<code>sampling_rate</code> at the forward call to prevent silent errors.`,name:"sampling_rate"},{anchor:"transformers.ASTFeatureExtractor.__call__.return_tensors",description:`<strong>return_tensors</strong> (<code>str</code> or <a href="/docs/transformers/v4.25.1/en/internal/file_utils#transformers.TensorType">TensorType</a>, <em>optional</em>) &#x2014;
If set, will return tensors instead of list of python integers. Acceptable values are:</p>
<ul>
<li><code>&apos;tf&apos;</code>: Return TensorFlow <code>tf.constant</code> objects.</li>
<li><code>&apos;pt&apos;</code>: Return PyTorch <code>torch.Tensor</code> objects.</li>
<li><code>&apos;np&apos;</code>: Return Numpy <code>np.ndarray</code> objects.</li>
</ul>`,name:"return_tensors"}],source:"https://github.com/huggingface/transformers/blob/v4.25.1/src/transformers/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.py#L125"}}),xe=new st({}),Ee=new Oe({props:{name:"class transformers.ASTModel",anchor:"transformers.ASTModel",parameters:[{name:"config",val:": ASTConfig"}],parametersDescription:[{anchor:"transformers.ASTModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTConfig">ASTConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.25.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.25.1/src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py#L445"}}),je=new Oe({props:{name:"forward",anchor:"transformers.ASTModel.forward",parameters:[{name:"input_values",val:": typing.Optional[torch.Tensor] = None"},{name:"head_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.ASTModel.forward.input_values",description:`<strong>input_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, height, width)</code>) &#x2014;
Pixel values. Pixel values can be obtained using <a href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTFeatureExtractor">ASTFeatureExtractor</a>. See
<a href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTFeatureExtractor.__call__">ASTFeatureExtractor.<strong>call</strong>()</a> for details.`,name:"input_values"},{anchor:"transformers.ASTModel.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"head_mask"},{anchor:"transformers.ASTModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.ASTModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.ASTModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.25.1/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/v4.25.1/src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py#L469",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.25.1/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPooling"
>transformers.modeling_outputs.BaseModelOutputWithPooling</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTConfig"
>ASTConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) \u2014 Sequence of hidden-states at the output of the last layer of the model.</p>
</li>
<li>
<p><strong>pooler_output</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, hidden_size)</code>) \u2014 Last layer hidden-state of the first token of the sequence (classification token) after further processing
through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns
the classification token after processing through a linear layer and a tanh activation function. The linear
layer weights are trained from the next sentence prediction (classification) objective during pretraining.</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.25.1/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPooling"
>transformers.modeling_outputs.BaseModelOutputWithPooling</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),ae=new qr({props:{$$slots:{default:[Dr]},$$scope:{ctx:E}}}),re=new ao({props:{anchor:"transformers.ASTModel.forward.example",$$slots:{default:[Lr]},$$scope:{ctx:E}}}),qe=new st({}),Fe=new Oe({props:{name:"class transformers.ASTForAudioClassification",anchor:"transformers.ASTForAudioClassification",parameters:[{name:"config",val:": ASTConfig"}],parametersDescription:[{anchor:"transformers.ASTForAudioClassification.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTConfig">ASTConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/v4.25.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.25.1/src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py#L546"}}),ze=new Oe({props:{name:"forward",anchor:"transformers.ASTForAudioClassification.forward",parameters:[{name:"input_values",val:": typing.Optional[torch.Tensor] = None"},{name:"head_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"labels",val:": typing.Optional[torch.Tensor] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.ASTForAudioClassification.forward.input_values",description:`<strong>input_values</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, num_channels, height, width)</code>) &#x2014;
Pixel values. Pixel values can be obtained using <a href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTFeatureExtractor">ASTFeatureExtractor</a>. See
<a href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTFeatureExtractor.__call__">ASTFeatureExtractor.<strong>call</strong>()</a> for details.`,name:"input_values"},{anchor:"transformers.ASTForAudioClassification.forward.head_mask",description:`<strong>head_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(num_heads,)</code> or <code>(num_layers, num_heads)</code>, <em>optional</em>) &#x2014;
Mask to nullify selected heads of the self-attention modules. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"head_mask"},{anchor:"transformers.ASTForAudioClassification.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.ASTForAudioClassification.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.ASTForAudioClassification.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.25.1/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.ASTForAudioClassification.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
Labels for computing the audio classification/regression loss. Indices should be in <code>[0, ..., config.num_labels - 1]</code>. If <code>config.num_labels == 1</code> a regression loss is computed (Mean-Square loss), If
<code>config.num_labels &gt; 1</code> a classification loss is computed (Cross-Entropy).`,name:"labels"}],source:"https://github.com/huggingface/transformers/blob/v4.25.1/src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py#L559",returnDescription:`
<p>A <a
  href="/docs/transformers/v4.25.1/en/main_classes/output#transformers.modeling_outputs.SequenceClassifierOutput"
>transformers.modeling_outputs.SequenceClassifierOutput</a> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTConfig"
>ASTConfig</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Classification (or regression if config.num_labels==1) loss.</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, config.num_labels)</code>) \u2014 Classification (or regression if config.num_labels==1) scores (before SoftMax).</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`
<p><a
  href="/docs/transformers/v4.25.1/en/main_classes/output#transformers.modeling_outputs.SequenceClassifierOutput"
>transformers.modeling_outputs.SequenceClassifierOutput</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),ne=new qr({props:{$$slots:{default:[Wr]},$$scope:{ctx:E}}}),ie=new ao({props:{anchor:"transformers.ASTForAudioClassification.forward.example",$$slots:{default:[Hr]},$$scope:{ctx:E}}}),le=new ao({props:{anchor:"transformers.ASTForAudioClassification.forward.example-2",$$slots:{default:[Ur]},$$scope:{ctx:E}}}),{c(){c=a("meta"),v=p(),f=a("h1"),g=a("a"),T=a("span"),b(l.$$.fragment),_=p(),F=a("span"),no=n("Audio Spectrogram Transformer"),kt=p(),O=a("h2"),R=a("a"),nt=a("span"),b(pe.$$.fragment),io=p(),it=a("span"),lo=n("Overview"),Ct=p(),P=a("p"),co=n("The Audio Spectrogram Transformer model was proposed in "),ue=a("a"),mo=n("AST: Audio Spectrogram Transformer"),po=n(` by Yuan Gong, Yu-An Chung, James Glass.
The Audio Spectrogram Transformer applies a `),De=a("a"),uo=n("Vision Transformer"),fo=n(` to audio, by turning audio into an image (spectrogram). The model obtains state-of-the-art results
for audio classification.`),jt=p(),Le=a("p"),ho=n("The abstract from the paper is the following:"),qt=p(),We=a("p"),lt=a("em"),go=n("In the past decade, convolutional neural networks (CNNs) have been widely adopted as the main building block for end-to-end audio classification models, which aim to learn a direct mapping from audio spectrograms to corresponding labels. To better capture long-range global context, a recent trend is to add a self-attention mechanism on top of the CNN, forming a CNN-attention hybrid model. However, it is unclear whether the reliance on a CNN is necessary, and if neural networks purely based on attention are sufficient to obtain good performance in audio classification. In this paper, we answer the question by introducing the Audio Spectrogram Transformer (AST), the first convolution-free, purely attention-based model for audio classification. We evaluate AST on various audio classification benchmarks, where it achieves new state-of-the-art results of 0.485 mAP on AudioSet, 95.6% accuracy on ESC-50, and 98.1% accuracy on Speech Commands V2."),Ft=p(),He=a("p"),_o=n("Tips:"),Mt=p(),J=a("ul"),D=a("li"),vo=n(`When fine-tuning the Audio Spectrogram Transformer (AST) on your own dataset, it\u2019s recommended to take care of the input normalization (to make
sure the input has mean of 0 and std of 0.5). `),Ue=a("a"),To=n("ASTFeatureExtractor"),bo=n(` takes care of this. Note that it uses the AudioSet
mean and std by default. You can check `),fe=a("a"),dt=a("code"),Ao=n("ast/src/get_norm_stats.py"),wo=n(` to see how
the authors compute the stats for a downstream dataset.`),$o=p(),he=a("li"),So=n(`Note that the AST needs a low learning rate (the authors use a 10 times smaller learning rate compared to their CNN model proposed in the
`),ge=a("a"),yo=n("PSLA paper"),xo=n(") and converges quickly, so please search for a suitable learning rate and learning rate scheduler for your task."),Pt=p(),K=a("img"),zt=p(),Q=a("small"),Eo=n("Audio pectrogram Transformer architecture. Taken from the "),Ve=a("a"),ko=n("original paper"),Co=n("."),Nt=p(),z=a("p"),jo=n("This model was contributed by "),_e=a("a"),qo=n("nielsr"),Fo=n(`.
The original code can be found `),ve=a("a"),Mo=n("here"),Po=n("."),It=p(),L=a("h2"),X=a("a"),ct=a("span"),b(Te.$$.fragment),zo=p(),mt=a("span"),No=n("ASTConfig"),Ot=p(),C=a("div"),b(be.$$.fragment),Io=p(),W=a("p"),Oo=n("This is the configuration class to store the configuration of a "),Be=a("a"),Do=n("ASTModel"),Lo=n(`. 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
`),Ae=a("a"),Wo=n("MIT/ast-finetuned-audioset-10-10-0.4593"),Ho=n(`
architecture.`),Uo=p(),H=a("p"),Vo=n("Configuration objects inherit from "),Ge=a("a"),Bo=n("PretrainedConfig"),Go=n(` and can be used to control the model outputs. Read the
documentation from `),Ye=a("a"),Yo=n("PretrainedConfig"),Ro=n(" for more information."),Jo=p(),b(Z.$$.fragment),Dt=p(),U=a("h2"),ee=a("a"),pt=a("span"),b(we.$$.fragment),Ko=p(),ut=a("span"),Qo=n("ASTFeatureExtractor"),Lt=p(),x=a("div"),b($e.$$.fragment),Xo=p(),ft=a("p"),Zo=n("Constructs a Audio Spectrogram Transformer (AST) feature extractor."),ea=p(),Se=a("p"),ta=n("This feature extractor inherits from "),Re=a("a"),oa=n("SequenceFeatureExtractor"),aa=n(` which contains
most of the main methods. Users should refer to this superclass for more information regarding those methods.`),ra=p(),ht=a("p"),sa=n(`This class extracts mel-filter bank features from raw speech using TorchAudio, pads/truncates them to a fixed
length and normalizes them using a mean and standard deviation.`),na=p(),te=a("div"),b(ye.$$.fragment),ia=p(),gt=a("p"),la=n("Main method to featurize and prepare for the model one or several sequence(s)."),Wt=p(),V=a("h2"),oe=a("a"),_t=a("span"),b(xe.$$.fragment),da=p(),vt=a("span"),ca=n("ASTModel"),Ht=p(),M=a("div"),b(Ee.$$.fragment),ma=p(),ke=a("p"),pa=n(`The bare AST Model transformer outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),Ce=a("a"),ua=n("torch.nn.Module"),fa=n(` subclass. Use it
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),ha=p(),q=a("div"),b(je.$$.fragment),ga=p(),B=a("p"),_a=n("The "),Je=a("a"),va=n("ASTModel"),Ta=n(" forward method, overrides the "),Tt=a("code"),ba=n("__call__"),Aa=n(" special method."),wa=p(),b(ae.$$.fragment),$a=p(),b(re.$$.fragment),Ut=p(),G=a("h2"),se=a("a"),bt=a("span"),b(qe.$$.fragment),Sa=p(),At=a("span"),ya=n("ASTForAudioClassification"),Vt=p(),j=a("div"),b(Fe.$$.fragment),xa=p(),wt=a("p"),Ea=n(`Audio Spectrogram Transformer model with an audio classification head on top (a linear layer on top of the pooled
output) e.g. for datasets like AudioSet, Speech Commands v2.`),ka=p(),Me=a("p"),Ca=n("This model is a PyTorch "),Pe=a("a"),ja=n("torch.nn.Module"),qa=n(` subclass. Use it
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),Fa=p(),k=a("div"),b(ze.$$.fragment),Ma=p(),Y=a("p"),Pa=n("The "),Ke=a("a"),za=n("ASTForAudioClassification"),Na=n(" forward method, overrides the "),$t=a("code"),Ia=n("__call__"),Oa=n(" special method."),Da=p(),b(ne.$$.fragment),La=p(),b(ie.$$.fragment),Wa=p(),b(le.$$.fragment),this.h()},l(e){const m=zr('[data-svelte="svelte-1phssyn"]',document.head);c=r(m,"META",{name:!0,content:!0}),m.forEach(o),v=u(e),f=r(e,"H1",{class:!0});var Ne=s(f);g=r(Ne,"A",{id:!0,class:!0,href:!0});var St=s(g);T=r(St,"SPAN",{});var yt=s(T);A(l.$$.fragment,yt),yt.forEach(o),St.forEach(o),_=u(Ne),F=r(Ne,"SPAN",{});var xt=s(F);no=i(xt,"Audio Spectrogram Transformer"),xt.forEach(o),Ne.forEach(o),kt=u(e),O=r(e,"H2",{class:!0});var Ie=s(O);R=r(Ie,"A",{id:!0,class:!0,href:!0});var Et=s(R);nt=r(Et,"SPAN",{});var Ua=s(nt);A(pe.$$.fragment,Ua),Ua.forEach(o),Et.forEach(o),io=u(Ie),it=r(Ie,"SPAN",{});var Va=s(it);lo=i(Va,"Overview"),Va.forEach(o),Ie.forEach(o),Ct=u(e),P=r(e,"P",{});var Qe=s(P);co=i(Qe,"The Audio Spectrogram Transformer model was proposed in "),ue=r(Qe,"A",{href:!0,rel:!0});var Ba=s(ue);mo=i(Ba,"AST: Audio Spectrogram Transformer"),Ba.forEach(o),po=i(Qe,` by Yuan Gong, Yu-An Chung, James Glass.
The Audio Spectrogram Transformer applies a `),De=r(Qe,"A",{href:!0});var Ga=s(De);uo=i(Ga,"Vision Transformer"),Ga.forEach(o),fo=i(Qe,` to audio, by turning audio into an image (spectrogram). The model obtains state-of-the-art results
for audio classification.`),Qe.forEach(o),jt=u(e),Le=r(e,"P",{});var Ya=s(Le);ho=i(Ya,"The abstract from the paper is the following:"),Ya.forEach(o),qt=u(e),We=r(e,"P",{});var Ra=s(We);lt=r(Ra,"EM",{});var Ja=s(lt);go=i(Ja,"In the past decade, convolutional neural networks (CNNs) have been widely adopted as the main building block for end-to-end audio classification models, which aim to learn a direct mapping from audio spectrograms to corresponding labels. To better capture long-range global context, a recent trend is to add a self-attention mechanism on top of the CNN, forming a CNN-attention hybrid model. However, it is unclear whether the reliance on a CNN is necessary, and if neural networks purely based on attention are sufficient to obtain good performance in audio classification. In this paper, we answer the question by introducing the Audio Spectrogram Transformer (AST), the first convolution-free, purely attention-based model for audio classification. We evaluate AST on various audio classification benchmarks, where it achieves new state-of-the-art results of 0.485 mAP on AudioSet, 95.6% accuracy on ESC-50, and 98.1% accuracy on Speech Commands V2."),Ja.forEach(o),Ra.forEach(o),Ft=u(e),He=r(e,"P",{});var Ka=s(He);_o=i(Ka,"Tips:"),Ka.forEach(o),Mt=u(e),J=r(e,"UL",{});var Gt=s(J);D=r(Gt,"LI",{});var Xe=s(D);vo=i(Xe,`When fine-tuning the Audio Spectrogram Transformer (AST) on your own dataset, it\u2019s recommended to take care of the input normalization (to make
sure the input has mean of 0 and std of 0.5). `),Ue=r(Xe,"A",{href:!0});var Qa=s(Ue);To=i(Qa,"ASTFeatureExtractor"),Qa.forEach(o),bo=i(Xe,` takes care of this. Note that it uses the AudioSet
mean and std by default. You can check `),fe=r(Xe,"A",{href:!0,rel:!0});var Xa=s(fe);dt=r(Xa,"CODE",{});var Za=s(dt);Ao=i(Za,"ast/src/get_norm_stats.py"),Za.forEach(o),Xa.forEach(o),wo=i(Xe,` to see how
the authors compute the stats for a downstream dataset.`),Xe.forEach(o),$o=u(Gt),he=r(Gt,"LI",{});var Yt=s(he);So=i(Yt,`Note that the AST needs a low learning rate (the authors use a 10 times smaller learning rate compared to their CNN model proposed in the
`),ge=r(Yt,"A",{href:!0,rel:!0});var er=s(ge);yo=i(er,"PSLA paper"),er.forEach(o),xo=i(Yt,") and converges quickly, so please search for a suitable learning rate and learning rate scheduler for your task."),Yt.forEach(o),Gt.forEach(o),Pt=u(e),K=r(e,"IMG",{src:!0,alt:!0,width:!0}),zt=u(e),Q=r(e,"SMALL",{});var Rt=s(Q);Eo=i(Rt,"Audio pectrogram Transformer architecture. Taken from the "),Ve=r(Rt,"A",{href:!0});var tr=s(Ve);ko=i(tr,"original paper"),tr.forEach(o),Co=i(Rt,"."),Rt.forEach(o),Nt=u(e),z=r(e,"P",{});var Ze=s(z);jo=i(Ze,"This model was contributed by "),_e=r(Ze,"A",{href:!0,rel:!0});var or=s(_e);qo=i(or,"nielsr"),or.forEach(o),Fo=i(Ze,`.
The original code can be found `),ve=r(Ze,"A",{href:!0,rel:!0});var ar=s(ve);Mo=i(ar,"here"),ar.forEach(o),Po=i(Ze,"."),Ze.forEach(o),It=u(e),L=r(e,"H2",{class:!0});var Jt=s(L);X=r(Jt,"A",{id:!0,class:!0,href:!0});var rr=s(X);ct=r(rr,"SPAN",{});var sr=s(ct);A(Te.$$.fragment,sr),sr.forEach(o),rr.forEach(o),zo=u(Jt),mt=r(Jt,"SPAN",{});var nr=s(mt);No=i(nr,"ASTConfig"),nr.forEach(o),Jt.forEach(o),Ot=u(e),C=r(e,"DIV",{class:!0});var de=s(C);A(be.$$.fragment,de),Io=u(de),W=r(de,"P",{});var et=s(W);Oo=i(et,"This is the configuration class to store the configuration of a "),Be=r(et,"A",{href:!0});var ir=s(Be);Do=i(ir,"ASTModel"),ir.forEach(o),Lo=i(et,`. 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
`),Ae=r(et,"A",{href:!0,rel:!0});var lr=s(Ae);Wo=i(lr,"MIT/ast-finetuned-audioset-10-10-0.4593"),lr.forEach(o),Ho=i(et,`
architecture.`),et.forEach(o),Uo=u(de),H=r(de,"P",{});var tt=s(H);Vo=i(tt,"Configuration objects inherit from "),Ge=r(tt,"A",{href:!0});var dr=s(Ge);Bo=i(dr,"PretrainedConfig"),dr.forEach(o),Go=i(tt,` and can be used to control the model outputs. Read the
documentation from `),Ye=r(tt,"A",{href:!0});var cr=s(Ye);Yo=i(cr,"PretrainedConfig"),cr.forEach(o),Ro=i(tt," for more information."),tt.forEach(o),Jo=u(de),A(Z.$$.fragment,de),de.forEach(o),Dt=u(e),U=r(e,"H2",{class:!0});var Kt=s(U);ee=r(Kt,"A",{id:!0,class:!0,href:!0});var mr=s(ee);pt=r(mr,"SPAN",{});var pr=s(pt);A(we.$$.fragment,pr),pr.forEach(o),mr.forEach(o),Ko=u(Kt),ut=r(Kt,"SPAN",{});var ur=s(ut);Qo=i(ur,"ASTFeatureExtractor"),ur.forEach(o),Kt.forEach(o),Lt=u(e),x=r(e,"DIV",{class:!0});var N=s(x);A($e.$$.fragment,N),Xo=u(N),ft=r(N,"P",{});var fr=s(ft);Zo=i(fr,"Constructs a Audio Spectrogram Transformer (AST) feature extractor."),fr.forEach(o),ea=u(N),Se=r(N,"P",{});var Qt=s(Se);ta=i(Qt,"This feature extractor inherits from "),Re=r(Qt,"A",{href:!0});var hr=s(Re);oa=i(hr,"SequenceFeatureExtractor"),hr.forEach(o),aa=i(Qt,` which contains
most of the main methods. Users should refer to this superclass for more information regarding those methods.`),Qt.forEach(o),ra=u(N),ht=r(N,"P",{});var gr=s(ht);sa=i(gr,`This class extracts mel-filter bank features from raw speech using TorchAudio, pads/truncates them to a fixed
length and normalizes them using a mean and standard deviation.`),gr.forEach(o),na=u(N),te=r(N,"DIV",{class:!0});var Xt=s(te);A(ye.$$.fragment,Xt),ia=u(Xt),gt=r(Xt,"P",{});var _r=s(gt);la=i(_r,"Main method to featurize and prepare for the model one or several sequence(s)."),_r.forEach(o),Xt.forEach(o),N.forEach(o),Wt=u(e),V=r(e,"H2",{class:!0});var Zt=s(V);oe=r(Zt,"A",{id:!0,class:!0,href:!0});var vr=s(oe);_t=r(vr,"SPAN",{});var Tr=s(_t);A(xe.$$.fragment,Tr),Tr.forEach(o),vr.forEach(o),da=u(Zt),vt=r(Zt,"SPAN",{});var br=s(vt);ca=i(br,"ASTModel"),br.forEach(o),Zt.forEach(o),Ht=u(e),M=r(e,"DIV",{class:!0});var ot=s(M);A(Ee.$$.fragment,ot),ma=u(ot),ke=r(ot,"P",{});var eo=s(ke);pa=i(eo,`The bare AST Model transformer outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),Ce=r(eo,"A",{href:!0,rel:!0});var Ar=s(Ce);ua=i(Ar,"torch.nn.Module"),Ar.forEach(o),fa=i(eo,` subclass. Use it
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),eo.forEach(o),ha=u(ot),q=r(ot,"DIV",{class:!0});var ce=s(q);A(je.$$.fragment,ce),ga=u(ce),B=r(ce,"P",{});var at=s(B);_a=i(at,"The "),Je=r(at,"A",{href:!0});var wr=s(Je);va=i(wr,"ASTModel"),wr.forEach(o),Ta=i(at," forward method, overrides the "),Tt=r(at,"CODE",{});var $r=s(Tt);ba=i($r,"__call__"),$r.forEach(o),Aa=i(at," special method."),at.forEach(o),wa=u(ce),A(ae.$$.fragment,ce),$a=u(ce),A(re.$$.fragment,ce),ce.forEach(o),ot.forEach(o),Ut=u(e),G=r(e,"H2",{class:!0});var to=s(G);se=r(to,"A",{id:!0,class:!0,href:!0});var Sr=s(se);bt=r(Sr,"SPAN",{});var yr=s(bt);A(qe.$$.fragment,yr),yr.forEach(o),Sr.forEach(o),Sa=u(to),At=r(to,"SPAN",{});var xr=s(At);ya=i(xr,"ASTForAudioClassification"),xr.forEach(o),to.forEach(o),Vt=u(e),j=r(e,"DIV",{class:!0});var me=s(j);A(Fe.$$.fragment,me),xa=u(me),wt=r(me,"P",{});var Er=s(wt);Ea=i(Er,`Audio Spectrogram Transformer model with an audio classification head on top (a linear layer on top of the pooled
output) e.g. for datasets like AudioSet, Speech Commands v2.`),Er.forEach(o),ka=u(me),Me=r(me,"P",{});var oo=s(Me);Ca=i(oo,"This model is a PyTorch "),Pe=r(oo,"A",{href:!0,rel:!0});var kr=s(Pe);ja=i(kr,"torch.nn.Module"),kr.forEach(o),qa=i(oo,` subclass. Use it
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),oo.forEach(o),Fa=u(me),k=r(me,"DIV",{class:!0});var I=s(k);A(ze.$$.fragment,I),Ma=u(I),Y=r(I,"P",{});var rt=s(Y);Pa=i(rt,"The "),Ke=r(rt,"A",{href:!0});var Cr=s(Ke);za=i(Cr,"ASTForAudioClassification"),Cr.forEach(o),Na=i(rt," forward method, overrides the "),$t=r(rt,"CODE",{});var jr=s($t);Ia=i(jr,"__call__"),jr.forEach(o),Oa=i(rt," special method."),rt.forEach(o),Da=u(I),A(ne.$$.fragment,I),La=u(I),A(ie.$$.fragment,I),Wa=u(I),A(le.$$.fragment,I),I.forEach(o),me.forEach(o),this.h()},h(){d(c,"name","hf:doc:metadata"),d(c,"content",JSON.stringify(Br)),d(g,"id","audio-spectrogram-transformer"),d(g,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(g,"href","#audio-spectrogram-transformer"),d(f,"class","relative group"),d(R,"id","overview"),d(R,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(R,"href","#overview"),d(O,"class","relative group"),d(ue,"href","https://arxiv.org/abs/2104.01778"),d(ue,"rel","nofollow"),d(De,"href","vit"),d(Ue,"href","/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTFeatureExtractor"),d(fe,"href","https://github.com/YuanGongND/ast/blob/master/src/get_norm_stats.py"),d(fe,"rel","nofollow"),d(ge,"href","https://arxiv.org/abs/2102.01243"),d(ge,"rel","nofollow"),Nr(K.src,Ha="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/audio_spectogram_transformer_architecture.png")||d(K,"src",Ha),d(K,"alt","drawing"),d(K,"width","600"),d(Ve,"href","https://arxiv.org/abs/2104.01778"),d(_e,"href","https://huggingface.co/nielsr"),d(_e,"rel","nofollow"),d(ve,"href","https://github.com/YuanGongND/ast"),d(ve,"rel","nofollow"),d(X,"id","transformers.ASTConfig"),d(X,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(X,"href","#transformers.ASTConfig"),d(L,"class","relative group"),d(Be,"href","/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTModel"),d(Ae,"href","https://huggingface.co/MIT/ast-finetuned-audioset-10-10-0.4593"),d(Ae,"rel","nofollow"),d(Ge,"href","/docs/transformers/v4.25.1/en/main_classes/configuration#transformers.PretrainedConfig"),d(Ye,"href","/docs/transformers/v4.25.1/en/main_classes/configuration#transformers.PretrainedConfig"),d(C,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(ee,"id","transformers.ASTFeatureExtractor"),d(ee,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(ee,"href","#transformers.ASTFeatureExtractor"),d(U,"class","relative group"),d(Re,"href","/docs/transformers/v4.25.1/en/main_classes/feature_extractor#transformers.SequenceFeatureExtractor"),d(te,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(oe,"id","transformers.ASTModel"),d(oe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(oe,"href","#transformers.ASTModel"),d(V,"class","relative group"),d(Ce,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(Ce,"rel","nofollow"),d(Je,"href","/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTModel"),d(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(se,"id","transformers.ASTForAudioClassification"),d(se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(se,"href","#transformers.ASTForAudioClassification"),d(G,"class","relative group"),d(Pe,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),d(Pe,"rel","nofollow"),d(Ke,"href","/docs/transformers/v4.25.1/en/model_doc/audio-spectrogram-transformer#transformers.ASTForAudioClassification"),d(k,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),d(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,m){t(document.head,c),h(e,v,m),h(e,f,m),t(f,g),t(g,T),w(l,T,null),t(f,_),t(f,F),t(F,no),h(e,kt,m),h(e,O,m),t(O,R),t(R,nt),w(pe,nt,null),t(O,io),t(O,it),t(it,lo),h(e,Ct,m),h(e,P,m),t(P,co),t(P,ue),t(ue,mo),t(P,po),t(P,De),t(De,uo),t(P,fo),h(e,jt,m),h(e,Le,m),t(Le,ho),h(e,qt,m),h(e,We,m),t(We,lt),t(lt,go),h(e,Ft,m),h(e,He,m),t(He,_o),h(e,Mt,m),h(e,J,m),t(J,D),t(D,vo),t(D,Ue),t(Ue,To),t(D,bo),t(D,fe),t(fe,dt),t(dt,Ao),t(D,wo),t(J,$o),t(J,he),t(he,So),t(he,ge),t(ge,yo),t(he,xo),h(e,Pt,m),h(e,K,m),h(e,zt,m),h(e,Q,m),t(Q,Eo),t(Q,Ve),t(Ve,ko),t(Q,Co),h(e,Nt,m),h(e,z,m),t(z,jo),t(z,_e),t(_e,qo),t(z,Fo),t(z,ve),t(ve,Mo),t(z,Po),h(e,It,m),h(e,L,m),t(L,X),t(X,ct),w(Te,ct,null),t(L,zo),t(L,mt),t(mt,No),h(e,Ot,m),h(e,C,m),w(be,C,null),t(C,Io),t(C,W),t(W,Oo),t(W,Be),t(Be,Do),t(W,Lo),t(W,Ae),t(Ae,Wo),t(W,Ho),t(C,Uo),t(C,H),t(H,Vo),t(H,Ge),t(Ge,Bo),t(H,Go),t(H,Ye),t(Ye,Yo),t(H,Ro),t(C,Jo),w(Z,C,null),h(e,Dt,m),h(e,U,m),t(U,ee),t(ee,pt),w(we,pt,null),t(U,Ko),t(U,ut),t(ut,Qo),h(e,Lt,m),h(e,x,m),w($e,x,null),t(x,Xo),t(x,ft),t(ft,Zo),t(x,ea),t(x,Se),t(Se,ta),t(Se,Re),t(Re,oa),t(Se,aa),t(x,ra),t(x,ht),t(ht,sa),t(x,na),t(x,te),w(ye,te,null),t(te,ia),t(te,gt),t(gt,la),h(e,Wt,m),h(e,V,m),t(V,oe),t(oe,_t),w(xe,_t,null),t(V,da),t(V,vt),t(vt,ca),h(e,Ht,m),h(e,M,m),w(Ee,M,null),t(M,ma),t(M,ke),t(ke,pa),t(ke,Ce),t(Ce,ua),t(ke,fa),t(M,ha),t(M,q),w(je,q,null),t(q,ga),t(q,B),t(B,_a),t(B,Je),t(Je,va),t(B,Ta),t(B,Tt),t(Tt,ba),t(B,Aa),t(q,wa),w(ae,q,null),t(q,$a),w(re,q,null),h(e,Ut,m),h(e,G,m),t(G,se),t(se,bt),w(qe,bt,null),t(G,Sa),t(G,At),t(At,ya),h(e,Vt,m),h(e,j,m),w(Fe,j,null),t(j,xa),t(j,wt),t(wt,Ea),t(j,ka),t(j,Me),t(Me,Ca),t(Me,Pe),t(Pe,ja),t(Me,qa),t(j,Fa),t(j,k),w(ze,k,null),t(k,Ma),t(k,Y),t(Y,Pa),t(Y,Ke),t(Ke,za),t(Y,Na),t(Y,$t),t($t,Ia),t(Y,Oa),t(k,Da),w(ne,k,null),t(k,La),w(ie,k,null),t(k,Wa),w(le,k,null),Bt=!0},p(e,[m]){const Ne={};m&2&&(Ne.$$scope={dirty:m,ctx:e}),Z.$set(Ne);const St={};m&2&&(St.$$scope={dirty:m,ctx:e}),ae.$set(St);const yt={};m&2&&(yt.$$scope={dirty:m,ctx:e}),re.$set(yt);const xt={};m&2&&(xt.$$scope={dirty:m,ctx:e}),ne.$set(xt);const Ie={};m&2&&(Ie.$$scope={dirty:m,ctx:e}),ie.$set(Ie);const Et={};m&2&&(Et.$$scope={dirty:m,ctx:e}),le.$set(Et)},i(e){Bt||($(l.$$.fragment,e),$(pe.$$.fragment,e),$(Te.$$.fragment,e),$(be.$$.fragment,e),$(Z.$$.fragment,e),$(we.$$.fragment,e),$($e.$$.fragment,e),$(ye.$$.fragment,e),$(xe.$$.fragment,e),$(Ee.$$.fragment,e),$(je.$$.fragment,e),$(ae.$$.fragment,e),$(re.$$.fragment,e),$(qe.$$.fragment,e),$(Fe.$$.fragment,e),$(ze.$$.fragment,e),$(ne.$$.fragment,e),$(ie.$$.fragment,e),$(le.$$.fragment,e),Bt=!0)},o(e){S(l.$$.fragment,e),S(pe.$$.fragment,e),S(Te.$$.fragment,e),S(be.$$.fragment,e),S(Z.$$.fragment,e),S(we.$$.fragment,e),S($e.$$.fragment,e),S(ye.$$.fragment,e),S(xe.$$.fragment,e),S(Ee.$$.fragment,e),S(je.$$.fragment,e),S(ae.$$.fragment,e),S(re.$$.fragment,e),S(qe.$$.fragment,e),S(Fe.$$.fragment,e),S(ze.$$.fragment,e),S(ne.$$.fragment,e),S(ie.$$.fragment,e),S(le.$$.fragment,e),Bt=!1},d(e){o(c),e&&o(v),e&&o(f),y(l),e&&o(kt),e&&o(O),y(pe),e&&o(Ct),e&&o(P),e&&o(jt),e&&o(Le),e&&o(qt),e&&o(We),e&&o(Ft),e&&o(He),e&&o(Mt),e&&o(J),e&&o(Pt),e&&o(K),e&&o(zt),e&&o(Q),e&&o(Nt),e&&o(z),e&&o(It),e&&o(L),y(Te),e&&o(Ot),e&&o(C),y(be),y(Z),e&&o(Dt),e&&o(U),y(we),e&&o(Lt),e&&o(x),y($e),y(ye),e&&o(Wt),e&&o(V),y(xe),e&&o(Ht),e&&o(M),y(Ee),y(je),y(ae),y(re),e&&o(Ut),e&&o(G),y(qe),e&&o(Vt),e&&o(j),y(Fe),y(ze),y(ne),y(ie),y(le)}}}const Br={local:"audio-spectrogram-transformer",sections:[{local:"overview",title:"Overview"},{local:"transformers.ASTConfig",title:"ASTConfig"},{local:"transformers.ASTFeatureExtractor",title:"ASTFeatureExtractor"},{local:"transformers.ASTModel",title:"ASTModel"},{local:"transformers.ASTForAudioClassification",title:"ASTForAudioClassification"}],title:"Audio Spectrogram Transformer"};function Gr(E){return Ir(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Zr extends Fr{constructor(c){super();Mr(this,c,Gr,Vr,Pr,{})}}export{Zr as default,Br as metadata};
