Instructions to use labhamlet/gramt-mono with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use labhamlet/gramt-mono with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="labhamlet/gramt-mono", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("labhamlet/gramt-mono", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199---library_name: transformerstags: []---# Model Card for Model ID<!-- Provide a quick summary of what the model is/does. -->## Model Details### Model Description<!-- Provide a longer summary of what this model is. -->This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.- **Developed by:** [More Information Needed]- **Funded by [optional]:** [More Information Needed]- **Shared by [optional]:** [More Information Needed]- **Model type:** [More Information Needed]- **Language(s) (NLP):** [More Information Needed]- **License:** [More Information Needed]- **Finetuned from model [optional]:** [More Information Needed]### Model Sources [optional]<!-- Provide the basic links for the model. -->- **Repository:** [More Information Needed]- **Paper [optional]:** [More Information Needed]- **Demo [optional]:** [More Information Needed]## Uses<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->### Direct Use<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->[More Information Needed]### Downstream Use [optional]<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->[More Information Needed]### Out-of-Scope Use<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->[More Information Needed]## Bias, Risks, and Limitations<!-- This section is meant to convey both technical and sociotechnical limitations. -->[More Information Needed]### Recommendations<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.## How to Get Started with the ModelUse the code below to get started with the model.[More Information Needed]## Training Details### Training Data<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->[More Information Needed]### Training Procedure<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->#### Preprocessing [optional][More Information Needed]#### Training Hyperparameters- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->#### Speeds, Sizes, Times [optional]<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->[More Information Needed]## Evaluation<!-- This section describes the evaluation protocols and provides the results. -->### Testing Data, Factors & Metrics#### Testing Data<!-- This should link to a Dataset Card if possible. -->[More Information Needed]#### Factors<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->[More Information Needed]#### Metrics<!-- These are the evaluation metrics being used, ideally with a description of why. -->[More Information Needed]### Results[More Information Needed]#### Summary## Model Examination [optional]<!-- Relevant interpretability work for the model goes here -->[More Information Needed]## Environmental Impact<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).- **Hardware Type:** [More Information Needed]- **Hours used:** [More Information Needed]- **Cloud Provider:** [More Information Needed]- **Compute Region:** [More Information Needed]- **Carbon Emitted:** [More Information Needed]## Technical Specifications [optional]### Model Architecture and Objective[More Information Needed]### Compute Infrastructure[More Information Needed]#### Hardware[More Information Needed]#### Software[More Information Needed]## Citation [optional]<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->**BibTeX:**[More Information Needed]**APA:**[More Information Needed]## Glossary [optional]<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->[More Information Needed]## More Information [optional][More Information Needed]## Model Card Authors [optional][More Information Needed]## Model Card Contact[More Information Needed]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183---library_name: transformerstags:- audio- spatial- speechlicense: mitdatasets:- agkphysics/AudioSetmetrics:- accuracypipeline_tag: feature-extraction---# Model Card for Model IDGRAM (General Purpose Audio Representation Model) is trained on AudioSet with newly proposed naturalistic training methadology.GRAMs utilize MWMAE (Multi-window multi-head attention), and RIR augmentations to achieve state-of-the-art results on downstream tasks such as FSD50K, ESC50, VL even when conditions are very adverse. What is different about GRAMs is the spatial reasoning capabilities, and the robustness to noise and reverberation.GRAMs natively support binaural localization, and ambisonics localization tasks unlike other models in the literature. Therefore, GRAMs can be used for understanding spatial scenes as well as classifying sounds, or recognizing speech in very noisy and reverberant environments.## Model DetailsThe GRAM learns spatial audio representation by reconstructing multi-channel masked spectrogrampatches. First, a patch extractor consisting of a single convolutional layer with 2D convolutionalfilters divides each multi-channel spectrogram into n non-overlapping patches. Nonmasked patch embeddings are input to the encoder, for which we selected the 12-layer ViT-Base(ViT-B) Transformer (Dosovitskiy et al., 2021) similar to Huang et al. (2022); Yadav et al. (2024).The encoder outputs patch representations that can be further used for fine-tuning.### Model DescriptionGRAM is a self-supervised, multi-channel masked auto-encoder model that efficiently learns spatial general-purpose audio representationsfrom simulated real-world sound scenes. To train GRAM, we developed a custom pipeline whichmakes use of the Soundspace 2.0 platform (Chen et al., 2022a) to simulate high-quality real-worldsound scenes from AudioSet (Gemmeke et al., 2017), and of WHAMR! (Maciejewski et al., 2020)for adding background noise. We present two versions of GRAM to ensure flexible application across audio formats:GRAM-Binaural for two-channel audio clips, and GRAM-Ambisonics for four-channel audio clips inthe first-order Ambisonics format.- **Developed by:** Goksenin Yuksel, goksenin.yuksel@ru.nl- **Model type:** Transformers, Audio Foundation Models- **Language(s) (NLP):** GRAMs support all languages, but mainly English.- **License:** MIT### Model Sources- **Repository:** https://github.com/labhamlet/GRAM-T- **Paper:** https://arxiv.org/abs/2506.00934## UsesGRAMs can be used as a powerful feature extractor for downstream tasks such as enviromental sound classification, speech recognition, speaker counting, sound localization.Later, training a linear head on top of these extracted features would yield a fine-tuned audio scene analysis model.## How to Get Started with the ModelGRAMs have three strategies to choose from; "raw", "mean" or "cls". We advise to use "raw" strategy as this prooduces embeddings over the time frames, and is more robust to silent parts.Raw : Break audio clips into non-overlapping 2 second chunks, concatenating the features in time and finally taking a mean over the time axis to generate a fixed vector representation independent of the input audio durationMean : Break audio clips into non-overlapping 2 second chunks, and taking a mean over all the patches to generate a fixed vector representation independent of the input audio durationCls : Break audio clips into non-overlapping 2 second chunks, and return the "[CLS]" token representation.~~~pythonfrom transformers import AutoModel, AutoFeatureExtractormodel = AutoModel.from_pretrained("labhamlet/gramt-mono", trust_remote_code=True)extractor = AutoFeatureExtractor.from_pretrained("labhamlet/gramt-mono", trust_remote_code=True)audio = torch.zeros([1,320000])extracted = extractor(audio, return_tensors="pt")log_mel = extracted['input_values']print(model(log_mel, strategy = "raw").shape)~~~## Training Details### Training DataThe 85,000 naturalistic scenes were split into a train set of 70,000 scenes (corresponding to 70 Matterport3D houses), and a test set of 15,000 scenes (15Matterport3D houses) for down-stream evaluation (see Section 3.4). We used the 70,000 naturalisticscenes in the train set to generate naturalistic scenes for all audio clips in the unbalanced trainingset of AudioSet (10-second sound tracks of 1.74 million YouTube videos (Gemmeke et al., 2017)).Specifically, during training we randomly paired an AudioSet clip with a noise sound clip from theWHAMR! background noise database (Maciejewski et al., 2020). WHAMR! noise clips longer than10 s were trimmed to 10 s duration and a linear fade-in/fade-out of 200 ms was applied to every noiseclip prior to mixing of the sound scene.To create a naturalistic sound scene, we then convolved the AudioSet clip either with BRIR(s, r, θ)for GRAM-Binaural, or with a ARIR(s, r, θ) for GRAM-Ambisonics, to obtain T. Similarly, weconvolved the WHAMR! noise clip with the to obtain naturalistic scenes.### Training ProcedureWe transformed the channels of each sound scene (i.e., the waveforms) into logscale mel spectrograms using 128 mel filters in the frequency range of 50-16000 Hz with a 25 msHanning window and 10 ms hop length, resulting in spectrograms of dimension 1024 × 128. ForGRAM-Ambisonic, we extracted normalized active Intensity Vectors (IVs) from the spectrogramsas additional input features encoding spatial information. We concatenated melspectrograms and intensity vectors, resulting in input x = [xmel, IV s] for each naturalistic scenegenerated from an AudioSet clip. In-batch sampling: As the online mixing of naturalistic acoustic scenes is computationally expensivedue to multiple long convolutions, we used a random in-batch sampling procedure to increase theeffective batch size in a computationally efficient manner. We randomly sampled 16 partiallyoverlapping segments of 2 seconds to create 16 samples of dimension 200 × 128. This increases theoriginal batch size of 96 to an effective batch size of 1536.For pre-training, we divided the binaural spectrogram into 2×8×16,ambisonics spectrograms into 7×8×16 patches. We used an adapted versionof the mask-based framework of MW-MAE (Yadav et al., 2024), randomly selecting a subset ofn patches M1, . . . , Mn for i = 1, . . . , n for masking (masking ratio = 0.8) and replacing theirembedding with a learnable mask token. Finally, we added fixed sinusoidal positional embeddings toall embedded patches.We trained all GRAMs for 500 K steps on an H100 92 GB GPU machinewith 16 CPU cores. We used the AdamW optimizer (Loshchilov & Hutter, 2017) with weight decayrate of 0.01, gradient clipping, and a cosine learning rate scheduler with 10 K steps warm-up. Theinitial learning rate was set to 0.0002, and decayed to 0. We optimize the mean squared error (MSE)loss function between the predicted masked patches and their corresponding input spectrogrampatches.#### PreprocessingFirstly, RMS Normalization was applied to audio clips to get all of them in the same loudness levels. Later, instance normalization was applied to the convolved scenes#### Training Hyperparameters- **Training regime:**: GRAMs were trained with mixed precision, torch.compile and flash attention.## EvaluationWe evaluate GRAM and other state-of-the-art models on the HEAR benchmarktask suite, which presents a wide range of tasks to evaluate the downstream performance of audiorepresentation models (Turian et al., 2022). We additionally evaluated performance on simulated real-worldsound scenes using Nat-HEAR.### Testing Data, Factors & Metrics#### Testing Data**HEAR**: The aim of the HEAR benchmark is to develop a general-purpose audio representation that provides a strong basis for learning in a wide variety of tasks and scenarios.HEAR evaluates audio representations using a benchmark suite across a variety of domains, including speech, environmental sound, and music.HEAR was launched as a NeurIPS 2021 shared challenge. It still remains an open question whether one single general-purpose audio representation can perform as holistically as the human ear.**NatHEAR**: Orovides a naturalistic version of all selected datasets in the HEAR benchmark suite intwo audio formats: a two-channel, binaural format and a four-channel, first-order Ambisonicsformat. Weincluded sound localization tasks for two different domains which we generated usingHEAR benchmark datasets: A speech localization task based on SC-5, and an environmental soundlocalization task based on ESC-50. The localization tasks are modeled as a multi-output regressiontask in which model outputs represent the estimated 3D Cartesian coordinates [x, y, z] on the unitsphere (Adavanne et al., 2018). Finally, to assess the transferability of GRAM to real-world soundscenes, we evaluate also on the sound event detection and localization tasks in TUT Sound Events2018 REAL (Adavanne et al., 2019)### Results| Model | DCASE | FSD50K | LC | ESC-50 | CD | VL | SC-5 | NS | BO | Mri-S | Mri-T | s(m) ||-------|-------|--------|-------|--------|-------|-------|------|-----|-------|-------|-------|------|| HEAR-Naive | 8.8 | 13.2 | 43.5 ± 1.6 | 28.6 ± 3.1 | 38.0 ± 2.3 | 14.8 ± 3.0 | 13.3 | 87.6 | 98.7 ± 1.9 | 94.1 ± 0.5 | 87.6 ± 6.4 | 0.0 || Wav2Vec 2.0 | 23.5 | 29.4 | 69.9 ± 2.1 | 46.4 ± 1.8 | 57.3 ± 1.1 | 34.9 ± 2.4 | 85.3 | 17.4 | 81.4 ± 4.8 | 90.7 ± 0.8 | 77.0 ± 0.9 | 31.5 || HuBERT | 78.3 | 32.8 | 63.3 ± 1.2 | 58.6 ± 2.8 | 71.2 ± 1.2 | 65.2 ± 2.9 | 94.0 | 19.8 | 93.2 ± 5.9 | 94.6 ± 0.4 | 85.0 ± 2.5 | 44.7 || WavLM | 27.0 | 25.7 | 61.3 ± 2.3 | 49.5 ± 3.8 | 64.3 ± 1.3 | 60.1 ± 3.2 | 93.8 | 18.2 | 84.3 ± 6.3 | 88.8 ± 1.0 | 76.8 ± 0.5 | 36.8 || MAE | – | 33.4 | 62.3 ± 1.1 | 72.9 ± 2.1 | 60.8 ± 1.8 | 21.3 ± 5.8 | 66.6 | 63.6 | 94.5 ± 5.6 | 94.8 ± 0.6 | 85.1 ± 10.4 | 32.7 || SSAST* | – | 21.4 | 57.8 ± 3.3 | 58.3 ± 2.6 | 48.0 ± 2.1 | 15.4 ± 2.6 | 22.0 | 64.2 | 95.8 ± 4.3 | 90.2 ± 5.9 | 89.1 ± 8.0 | 15.8 || BEATs | – | 54.1 | 77.8 ± 1.2 | 85.8 ± 2.9 | 66.9 ± 2.5 | 39.7 ± 4.3 | 86.9 | 68.6 | 94.1 ± 3.5 | 95.5 ± 0.4 | 96.6 ± 0.5 | 61.4 || MW-MAE | 94.2 | 51.8 | 80.3 ± 1.9 | 82.2 ± 3.2 | 74.4 ± 1.5 | 45.5 ± 1.7 | 91.6 | 69.4 | 95.8 ± 4.3 | 97.5 ± 0.4 | 97.6 ± 0.6 | 71.0 || SSAM | 87.3 | 53.5 | 75.5 ± 1.4 | 82.9 ± 3.6 | 70.2 ± 0.4 | 56.4 ± 5.2 | 89.3 | 72.6 | 93.2 ± 3.5 | 97.8 ± 0.5 | 96.9 ± 0.5 | 71.2 || **GRAM-Binaural** | 95.6 | 56.1 | 81.0 ± 1.1 | 86.7 ± 2.4 | 75.0 ± 1.4 | 53.2 ± 3.0 | 92.5 | 77.0 | 94.9 ± 3.2 | 97.3 ± 0.3 | 98.1 ± 0.2 | 74.6 || **GRAM-Ambisonics** | 94.3 | 53.0 | 79.4 ± 1.5 | 85.9 ± 1.5 | 71.9 ± 1.9 | 53.7 ± 1.2 | 89.6 | 73.8 | 94.9 ± 4.9 | 97.6 ± 0.5 | 98.5 ± 0.4 | 73.4 || **GRAM-Mono** | 95.3 | 56.8 | 81.3 ± 1.8 | 87.5 ± 2.3 | 75.1 ± 0.6 | 57.3 ± 3.4 | 93.5 | 75.8 | 95.8 ± 3.7 | 97.4 ± 0.3 | 98.0 ± 0.2 | 76.1 |#### SummaryWe present a General-purpose, Real-world Audio representation Model (GRAM), which learns spatialaudio representations using a multi-channel masked auto-encoder approach. GRAM demonstratesremarkable performance in naturalistic sound scenes as well as clean sound scenes, surpassing allstate-of-the-art self-supervised spectrogram-based audio foundation models while requiring only afraction of the training data. Moreover, GRAM is the first audio foundation model that is availablein both a two-channel, binaural format and a four-channel, first-order ambisonics format## Model Card ContactGoksenin Yuksel; goksenin.yuksel@ru.nl
README.md+122-138