Skip to content

Audio and Music SSL #2755

Merged
mravanelli merged 19 commits intospeechbrain:developfrom
poonehmousavi:audio_music_ssl
Dec 5, 2024
Merged

Audio and Music SSL #2755
mravanelli merged 19 commits intospeechbrain:developfrom
poonehmousavi:audio_music_ssl

Conversation

@poonehmousavi
Copy link
Copy Markdown
Collaborator

@poonehmousavi poonehmousavi commented Nov 17, 2024

What does this PR do?

Adding SSL model for Music and audio domains:

Fixes #<issue_number>

Before submitting
  • Did you read the contributor guideline?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Does your code adhere to project-specific code style and conventions?

PR review

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified
  • Confirm that the changes adhere to compatibility requirements (e.g., Python version, platform)
  • Review the self-review checklist to ensure the code is ready for review

@poonehmousavi poonehmousavi self-assigned this Nov 17, 2024
@poonehmousavi poonehmousavi added the enhancement New feature or request label Nov 17, 2024
@TParcollet TParcollet self-requested a review November 20, 2024 21:44
@poonehmousavi poonehmousavi marked this pull request as ready for review November 21, 2024 23:32
@poonehmousavi
Copy link
Copy Markdown
Collaborator Author

poonehmousavi commented Nov 21, 2024

The error is related to the returning warning, should I skip the doctest fro MERT?

Comment thread speechbrain/lobes/models/beats.py Outdated
Comment thread speechbrain/lobes/models/beats.py
Comment thread speechbrain/lobes/models/beats.py Outdated
Comment thread speechbrain/lobes/models/beats.py Outdated
Comment thread speechbrain/lobes/models/beats.py Outdated

Example
-------
>>> audio = torch.randn(4, 10000) # Batch of 4 audio signals
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

audio = torch.randn(4, 10000)  # Batch of 4 audio signals
length = torch.tensor([1.0, 0.5, 0.75, 1.0])
model = BEATs("BEATs_iter1_finetuned_on_AS2M_cpt2.pt")
outputs = model.extract_features(audio, length)
print(outputs.shape)
>>> AttributeError: 'tuple' object has no attribute 'shape'

When loading a pretrained model, I guess you do not need the predictor but just the embedding model (see line 2005).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It happens when the finetuned version is loaded, so it also returns the prob_log of the prediction. I changed the code, so it could work with both finetuned and self-supervised checkpoints

Comment thread speechbrain/lobes/models/huggingface_transformers/mert.py Outdated
Comment thread speechbrain/lobes/models/huggingface_transformers/mert.py Outdated
Comment thread speechbrain/lobes/models/huggingface_transformers/mert.py Outdated
Comment thread speechbrain/lobes/models/huggingface_transformers/mert.py Outdated
Comment thread speechbrain/lobes/models/huggingface_transformers/mert.py Outdated
@lucadellalib lucadellalib self-requested a review December 2, 2024 19:36
Comment thread speechbrain/lobes/models/beats.py Outdated
@@ -0,0 +1,2059 @@
"""This lobe enables the integration of pretrained BBEATs: Audio Pre-Training with Acoustic Tokenizers.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix typo: "BBEATs" -> "BEATs"

where a projection of the CNN output is added to the beginning.
If False, the forward function outputs the hidden states only from the last transformer layer.

Example
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with this, it should fix the tests:

    Example
    -------
    >>> import torch
    >>> inputs = torch.rand([10, 600])
    >>> model_hub = "m-a-p/MERT-v1-95M"
    >>> save_path = "savedir"
    >>> model = MERT(model_hub, save_path)
    WARNING: feature_extractor_cqt requires the libray 'nnAudio'
    >>> outputs = model(inputs)
    >>> outputs.shape
    torch.Size([10, 1, 768])

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning is resolved but then since the warning message contains "library" instead of "library" we got recommit issue

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace:

>>> model = MERT(model_hub, save_path)
WARNING: feature_extractor_cqt requires the libray 'nnAudio'

with

>>> model = MERT(model_hub, save_path)  # doctest: +ELLIPSIS
WARNING: ...

Comment thread speechbrain/lobes/models/beats.py Outdated
self, attn_weights, tgt_len: int, src_len: int, bsz: int
):
"""
"""5
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove 5

@mravanelli
Copy link
Copy Markdown
Collaborator

Thank you @poonehmousavi , for this contribution! I reviewed the PR, and everything seems to work properly. I only have the following comments:

  • Please add an inline comment for trust_remote_code in huggingface.py to clarify its purpose and usage.
  • Some docstrings in beats.py are not formatted according to the SpeechBrain standard. For example:
    Current Format:
Arguments:  
----------  
	 q (Tensor): Query tensor.  
         v (Tensor): Value tensor.  

Expected Format:

Arguments:  
----------  
q: torch.tensor  
    Query tensor.  
v: torch.tensor  
    Value tensor.  

There are a few instances like this that need to be corrected.

  • MERT and BEATs will be moved to the "integration" folder that @pplantinga is currently designing. I think we can first merge the PRs regarding the new tokenizers and right after proceed with the folder restructuring.

@poonehmousavi
Copy link
Copy Markdown
Collaborator Author

Thank you @poonehmousavi , for this contribution! I reviewed the PR, and everything seems to work properly. I only have the following comments:

  • Please add an inline comment for trust_remote_code in huggingface.py to clarify its purpose and usage.
  • Some docstrings in beats.py are not formatted according to the SpeechBrain standard. For example:
    Current Format:
Arguments:  
----------  
	 q (Tensor): Query tensor.  
         v (Tensor): Value tensor.  

Expected Format:

Arguments:  
----------  
q: torch.tensor  
    Query tensor.  
v: torch.tensor  
    Value tensor.  

There are a few instances like this that need to be corrected.

  • MERT and BEATs will be moved to the "integration" folder that @pplantinga is currently designing. I think we can first merge the PRs regarding the new tokenizers and right after proceed with the folder restructuring.

regarding moving BEATs to the integration folder, the current version of BEATs is completely implemented in SB without the need to external library.. so maybe there is no need to be moved to integration folder

@mravanelli
Copy link
Copy Markdown
Collaborator

After the latest changes, I'm fine with it.

@mravanelli mravanelli merged commit 4bfe32a into speechbrain:develop Dec 5, 2024
@poonehmousavi poonehmousavi deleted the audio_music_ssl branch February 5, 2025 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants