Feature Extraction
Transformers
Safetensors
mert2
audio
music
music-understanding
representation-learning
custom_code
Instructions to use m-a-p/MERT-v2-FullSong with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use m-a-p/MERT-v2-FullSong with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="m-a-p/MERT-v2-FullSong", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("m-a-p/MERT-v2-FullSong", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit ·
d8ba1c7
0
Parent(s):
Release MERT-v2-FullSong
Browse files- .gitattributes +36 -0
- LICENSE +424 -0
- README.md +185 -0
- THIRD_PARTY_NOTICES.md +11 -0
- assets/mert2-architecture.png +3 -0
- config.json +41 -0
- configuration_mert2.py +76 -0
- marble_results.json +327 -0
- model.safetensors +3 -0
- modeling_mert2.py +361 -0
- preprocessor_config.json +9 -0
- weights_manifest.json +9 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/m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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MERT2 model-weight license
|
| 2 |
+
|
| 3 |
+
The MERT2-30s and MERT2-FS checkpoint weights in model.safetensors are
|
| 4 |
+
licensed under Creative Commons Attribution-NonCommercial 4.0 International
|
| 5 |
+
(CC BY-NC 4.0): https://creativecommons.org/licenses/by-nc/4.0/
|
| 6 |
+
|
| 7 |
+
For attribution, identify MERT2, the model name, and its source repository:
|
| 8 |
+
https://huggingface.co/m-a-p/MERT-v2-30s
|
| 9 |
+
https://huggingface.co/m-a-p/MERT-v2-FullSong
|
| 10 |
+
|
| 11 |
+
This weight license does not replace separately applicable licenses for code
|
| 12 |
+
or dependencies. See THIRD_PARTY_NOTICES.md.
|
| 13 |
+
|
| 14 |
+
The official license text follows without modification.
|
| 15 |
+
Source: https://creativecommons.org/licenses/by-nc/4.0/legalcode.txt
|
| 16 |
+
|
| 17 |
+
Attribution-NonCommercial 4.0 International
|
| 18 |
+
|
| 19 |
+
=======================================================================
|
| 20 |
+
|
| 21 |
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
| 22 |
+
does not provide legal services or legal advice. Distribution of
|
| 23 |
+
Creative Commons public licenses does not create a lawyer-client or
|
| 24 |
+
other relationship. Creative Commons makes its licenses and related
|
| 25 |
+
information available on an "as-is" basis. Creative Commons gives no
|
| 26 |
+
warranties regarding its licenses, any material licensed under their
|
| 27 |
+
terms and conditions, or any related information. Creative Commons
|
| 28 |
+
disclaims all liability for damages resulting from their use to the
|
| 29 |
+
fullest extent possible.
|
| 30 |
+
|
| 31 |
+
Using Creative Commons Public Licenses
|
| 32 |
+
|
| 33 |
+
Creative Commons public licenses provide a standard set of terms and
|
| 34 |
+
conditions that creators and other rights holders may use to share
|
| 35 |
+
original works of authorship and other material subject to copyright
|
| 36 |
+
and certain other rights specified in the public license below. The
|
| 37 |
+
following considerations are for informational purposes only, are not
|
| 38 |
+
exhaustive, and do not form part of our licenses.
|
| 39 |
+
|
| 40 |
+
Considerations for licensors: Our public licenses are
|
| 41 |
+
intended for use by those authorized to give the public
|
| 42 |
+
permission to use material in ways otherwise restricted by
|
| 43 |
+
copyright and certain other rights. Our licenses are
|
| 44 |
+
irrevocable. Licensors should read and understand the terms
|
| 45 |
+
and conditions of the license they choose before applying it.
|
| 46 |
+
Licensors should also secure all rights necessary before
|
| 47 |
+
applying our licenses so that the public can reuse the
|
| 48 |
+
material as expected. Licensors should clearly mark any
|
| 49 |
+
material not subject to the license. This includes other CC-
|
| 50 |
+
licensed material, or material used under an exception or
|
| 51 |
+
limitation to copyright. More considerations for licensors:
|
| 52 |
+
wiki.creativecommons.org/Considerations_for_licensors
|
| 53 |
+
|
| 54 |
+
Considerations for the public: By using one of our public
|
| 55 |
+
licenses, a licensor grants the public permission to use the
|
| 56 |
+
licensed material under specified terms and conditions. If
|
| 57 |
+
the licensor's permission is not necessary for any reason--for
|
| 58 |
+
example, because of any applicable exception or limitation to
|
| 59 |
+
copyright--then that use is not regulated by the license. Our
|
| 60 |
+
licenses grant only permissions under copyright and certain
|
| 61 |
+
other rights that a licensor has authority to grant. Use of
|
| 62 |
+
the licensed material may still be restricted for other
|
| 63 |
+
reasons, including because others have copyright or other
|
| 64 |
+
rights in the material. A licensor may make special requests,
|
| 65 |
+
such as asking that all changes be marked or described.
|
| 66 |
+
Although not required by our licenses, you are encouraged to
|
| 67 |
+
respect those requests where reasonable. More considerations
|
| 68 |
+
for the public:
|
| 69 |
+
wiki.creativecommons.org/Considerations_for_licensees
|
| 70 |
+
|
| 71 |
+
=======================================================================
|
| 72 |
+
|
| 73 |
+
Creative Commons Attribution-NonCommercial 4.0 International Public
|
| 74 |
+
License
|
| 75 |
+
|
| 76 |
+
By exercising the Licensed Rights (defined below), You accept and agree
|
| 77 |
+
to be bound by the terms and conditions of this Creative Commons
|
| 78 |
+
Attribution-NonCommercial 4.0 International Public License ("Public
|
| 79 |
+
License"). To the extent this Public License may be interpreted as a
|
| 80 |
+
contract, You are granted the Licensed Rights in consideration of Your
|
| 81 |
+
acceptance of these terms and conditions, and the Licensor grants You
|
| 82 |
+
such rights in consideration of benefits the Licensor receives from
|
| 83 |
+
making the Licensed Material available under these terms and
|
| 84 |
+
conditions.
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
Section 1 -- Definitions.
|
| 88 |
+
|
| 89 |
+
a. Adapted Material means material subject to Copyright and Similar
|
| 90 |
+
Rights that is derived from or based upon the Licensed Material
|
| 91 |
+
and in which the Licensed Material is translated, altered,
|
| 92 |
+
arranged, transformed, or otherwise modified in a manner requiring
|
| 93 |
+
permission under the Copyright and Similar Rights held by the
|
| 94 |
+
Licensor. For purposes of this Public License, where the Licensed
|
| 95 |
+
Material is a musical work, performance, or sound recording,
|
| 96 |
+
Adapted Material is always produced where the Licensed Material is
|
| 97 |
+
synched in timed relation with a moving image.
|
| 98 |
+
|
| 99 |
+
b. Adapter's License means the license You apply to Your Copyright
|
| 100 |
+
and Similar Rights in Your contributions to Adapted Material in
|
| 101 |
+
accordance with the terms and conditions of this Public License.
|
| 102 |
+
|
| 103 |
+
c. Copyright and Similar Rights means copyright and/or similar rights
|
| 104 |
+
closely related to copyright including, without limitation,
|
| 105 |
+
performance, broadcast, sound recording, and Sui Generis Database
|
| 106 |
+
Rights, without regard to how the rights are labeled or
|
| 107 |
+
categorized. For purposes of this Public License, the rights
|
| 108 |
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
| 109 |
+
Rights.
|
| 110 |
+
d. Effective Technological Measures means those measures that, in the
|
| 111 |
+
absence of proper authority, may not be circumvented under laws
|
| 112 |
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
| 113 |
+
Treaty adopted on December 20, 1996, and/or similar international
|
| 114 |
+
agreements.
|
| 115 |
+
|
| 116 |
+
e. Exceptions and Limitations means fair use, fair dealing, and/or
|
| 117 |
+
any other exception or limitation to Copyright and Similar Rights
|
| 118 |
+
that applies to Your use of the Licensed Material.
|
| 119 |
+
|
| 120 |
+
f. Licensed Material means the artistic or literary work, database,
|
| 121 |
+
or other material to which the Licensor applied this Public
|
| 122 |
+
License.
|
| 123 |
+
|
| 124 |
+
g. Licensed Rights means the rights granted to You subject to the
|
| 125 |
+
terms and conditions of this Public License, which are limited to
|
| 126 |
+
all Copyright and Similar Rights that apply to Your use of the
|
| 127 |
+
Licensed Material and that the Licensor has authority to license.
|
| 128 |
+
|
| 129 |
+
h. Licensor means the individual(s) or entity(ies) granting rights
|
| 130 |
+
under this Public License.
|
| 131 |
+
|
| 132 |
+
i. NonCommercial means not primarily intended for or directed towards
|
| 133 |
+
commercial advantage or monetary compensation. For purposes of
|
| 134 |
+
this Public License, the exchange of the Licensed Material for
|
| 135 |
+
other material subject to Copyright and Similar Rights by digital
|
| 136 |
+
file-sharing or similar means is NonCommercial provided there is
|
| 137 |
+
no payment of monetary compensation in connection with the
|
| 138 |
+
exchange.
|
| 139 |
+
|
| 140 |
+
j. Share means to provide material to the public by any means or
|
| 141 |
+
process that requires permission under the Licensed Rights, such
|
| 142 |
+
as reproduction, public display, public performance, distribution,
|
| 143 |
+
dissemination, communication, or importation, and to make material
|
| 144 |
+
available to the public including in ways that members of the
|
| 145 |
+
public may access the material from a place and at a time
|
| 146 |
+
individually chosen by them.
|
| 147 |
+
|
| 148 |
+
k. Sui Generis Database Rights means rights other than copyright
|
| 149 |
+
resulting from Directive 96/9/EC of the European Parliament and of
|
| 150 |
+
the Council of 11 March 1996 on the legal protection of databases,
|
| 151 |
+
as amended and/or succeeded, as well as other essentially
|
| 152 |
+
equivalent rights anywhere in the world.
|
| 153 |
+
|
| 154 |
+
l. You means the individual or entity exercising the Licensed Rights
|
| 155 |
+
under this Public License. Your has a corresponding meaning.
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
Section 2 -- Scope.
|
| 159 |
+
|
| 160 |
+
a. License grant.
|
| 161 |
+
|
| 162 |
+
1. Subject to the terms and conditions of this Public License,
|
| 163 |
+
the Licensor hereby grants You a worldwide, royalty-free,
|
| 164 |
+
non-sublicensable, non-exclusive, irrevocable license to
|
| 165 |
+
exercise the Licensed Rights in the Licensed Material to:
|
| 166 |
+
|
| 167 |
+
a. reproduce and Share the Licensed Material, in whole or
|
| 168 |
+
in part, for NonCommercial purposes only; and
|
| 169 |
+
|
| 170 |
+
b. produce, reproduce, and Share Adapted Material for
|
| 171 |
+
NonCommercial purposes only.
|
| 172 |
+
|
| 173 |
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
| 174 |
+
Exceptions and Limitations apply to Your use, this Public
|
| 175 |
+
License does not apply, and You do not need to comply with
|
| 176 |
+
its terms and conditions.
|
| 177 |
+
|
| 178 |
+
3. Term. The term of this Public License is specified in Section
|
| 179 |
+
6(a).
|
| 180 |
+
|
| 181 |
+
4. Media and formats; technical modifications allowed. The
|
| 182 |
+
Licensor authorizes You to exercise the Licensed Rights in
|
| 183 |
+
all media and formats whether now known or hereafter created,
|
| 184 |
+
and to make technical modifications necessary to do so. The
|
| 185 |
+
Licensor waives and/or agrees not to assert any right or
|
| 186 |
+
authority to forbid You from making technical modifications
|
| 187 |
+
necessary to exercise the Licensed Rights, including
|
| 188 |
+
technical modifications necessary to circumvent Effective
|
| 189 |
+
Technological Measures. For purposes of this Public License,
|
| 190 |
+
simply making modifications authorized by this Section 2(a)
|
| 191 |
+
(4) never produces Adapted Material.
|
| 192 |
+
|
| 193 |
+
5. Downstream recipients.
|
| 194 |
+
|
| 195 |
+
a. Offer from the Licensor -- Licensed Material. Every
|
| 196 |
+
recipient of the Licensed Material automatically
|
| 197 |
+
receives an offer from the Licensor to exercise the
|
| 198 |
+
Licensed Rights under the terms and conditions of this
|
| 199 |
+
Public License.
|
| 200 |
+
|
| 201 |
+
b. No downstream restrictions. You may not offer or impose
|
| 202 |
+
any additional or different terms or conditions on, or
|
| 203 |
+
apply any Effective Technological Measures to, the
|
| 204 |
+
Licensed Material if doing so restricts exercise of the
|
| 205 |
+
Licensed Rights by any recipient of the Licensed
|
| 206 |
+
Material.
|
| 207 |
+
|
| 208 |
+
6. No endorsement. Nothing in this Public License constitutes or
|
| 209 |
+
may be construed as permission to assert or imply that You
|
| 210 |
+
are, or that Your use of the Licensed Material is, connected
|
| 211 |
+
with, or sponsored, endorsed, or granted official status by,
|
| 212 |
+
the Licensor or others designated to receive attribution as
|
| 213 |
+
provided in Section 3(a)(1)(A)(i).
|
| 214 |
+
|
| 215 |
+
b. Other rights.
|
| 216 |
+
|
| 217 |
+
1. Moral rights, such as the right of integrity, are not
|
| 218 |
+
licensed under this Public License, nor are publicity,
|
| 219 |
+
privacy, and/or other similar personality rights; however, to
|
| 220 |
+
the extent possible, the Licensor waives and/or agrees not to
|
| 221 |
+
assert any such rights held by the Licensor to the limited
|
| 222 |
+
extent necessary to allow You to exercise the Licensed
|
| 223 |
+
Rights, but not otherwise.
|
| 224 |
+
|
| 225 |
+
2. Patent and trademark rights are not licensed under this
|
| 226 |
+
Public License.
|
| 227 |
+
|
| 228 |
+
3. To the extent possible, the Licensor waives any right to
|
| 229 |
+
collect royalties from You for the exercise of the Licensed
|
| 230 |
+
Rights, whether directly or through a collecting society
|
| 231 |
+
under any voluntary or waivable statutory or compulsory
|
| 232 |
+
licensing scheme. In all other cases the Licensor expressly
|
| 233 |
+
reserves any right to collect such royalties, including when
|
| 234 |
+
the Licensed Material is used other than for NonCommercial
|
| 235 |
+
purposes.
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
Section 3 -- License Conditions.
|
| 239 |
+
|
| 240 |
+
Your exercise of the Licensed Rights is expressly made subject to the
|
| 241 |
+
following conditions.
|
| 242 |
+
|
| 243 |
+
a. Attribution.
|
| 244 |
+
|
| 245 |
+
1. If You Share the Licensed Material (including in modified
|
| 246 |
+
form), You must:
|
| 247 |
+
|
| 248 |
+
a. retain the following if it is supplied by the Licensor
|
| 249 |
+
with the Licensed Material:
|
| 250 |
+
|
| 251 |
+
i. identification of the creator(s) of the Licensed
|
| 252 |
+
Material and any others designated to receive
|
| 253 |
+
attribution, in any reasonable manner requested by
|
| 254 |
+
the Licensor (including by pseudonym if
|
| 255 |
+
designated);
|
| 256 |
+
|
| 257 |
+
ii. a copyright notice;
|
| 258 |
+
|
| 259 |
+
iii. a notice that refers to this Public License;
|
| 260 |
+
|
| 261 |
+
iv. a notice that refers to the disclaimer of
|
| 262 |
+
warranties;
|
| 263 |
+
|
| 264 |
+
v. a URI or hyperlink to the Licensed Material to the
|
| 265 |
+
extent reasonably practicable;
|
| 266 |
+
|
| 267 |
+
b. indicate if You modified the Licensed Material and
|
| 268 |
+
retain an indication of any previous modifications; and
|
| 269 |
+
|
| 270 |
+
c. indicate the Licensed Material is licensed under this
|
| 271 |
+
Public License, and include the text of, or the URI or
|
| 272 |
+
hyperlink to, this Public License.
|
| 273 |
+
|
| 274 |
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
| 275 |
+
reasonable manner based on the medium, means, and context in
|
| 276 |
+
which You Share the Licensed Material. For example, it may be
|
| 277 |
+
reasonable to satisfy the conditions by providing a URI or
|
| 278 |
+
hyperlink to a resource that includes the required
|
| 279 |
+
information.
|
| 280 |
+
|
| 281 |
+
3. If requested by the Licensor, You must remove any of the
|
| 282 |
+
information required by Section 3(a)(1)(A) to the extent
|
| 283 |
+
reasonably practicable.
|
| 284 |
+
|
| 285 |
+
4. If You Share Adapted Material You produce, the Adapter's
|
| 286 |
+
License You apply must not prevent recipients of the Adapted
|
| 287 |
+
Material from complying with this Public License.
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
Section 4 -- Sui Generis Database Rights.
|
| 291 |
+
|
| 292 |
+
Where the Licensed Rights include Sui Generis Database Rights that
|
| 293 |
+
apply to Your use of the Licensed Material:
|
| 294 |
+
|
| 295 |
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
| 296 |
+
to extract, reuse, reproduce, and Share all or a substantial
|
| 297 |
+
portion of the contents of the database for NonCommercial purposes
|
| 298 |
+
only;
|
| 299 |
+
|
| 300 |
+
b. if You include all or a substantial portion of the database
|
| 301 |
+
contents in a database in which You have Sui Generis Database
|
| 302 |
+
Rights, then the database in which You have Sui Generis Database
|
| 303 |
+
Rights (but not its individual contents) is Adapted Material; and
|
| 304 |
+
|
| 305 |
+
c. You must comply with the conditions in Section 3(a) if You Share
|
| 306 |
+
all or a substantial portion of the contents of the database.
|
| 307 |
+
|
| 308 |
+
For the avoidance of doubt, this Section 4 supplements and does not
|
| 309 |
+
replace Your obligations under this Public License where the Licensed
|
| 310 |
+
Rights include other Copyright and Similar Rights.
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
| 314 |
+
|
| 315 |
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
| 316 |
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
| 317 |
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
| 318 |
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
| 319 |
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
| 320 |
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
| 321 |
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
| 322 |
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
| 323 |
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
| 324 |
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
| 325 |
+
|
| 326 |
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
| 327 |
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
| 328 |
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
| 329 |
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
| 330 |
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
| 331 |
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
| 332 |
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
| 333 |
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
| 334 |
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
| 335 |
+
|
| 336 |
+
c. The disclaimer of warranties and limitation of liability provided
|
| 337 |
+
above shall be interpreted in a manner that, to the extent
|
| 338 |
+
possible, most closely approximates an absolute disclaimer and
|
| 339 |
+
waiver of all liability.
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
Section 6 -- Term and Termination.
|
| 343 |
+
|
| 344 |
+
a. This Public License applies for the term of the Copyright and
|
| 345 |
+
Similar Rights licensed here. However, if You fail to comply with
|
| 346 |
+
this Public License, then Your rights under this Public License
|
| 347 |
+
terminate automatically.
|
| 348 |
+
|
| 349 |
+
b. Where Your right to use the Licensed Material has terminated under
|
| 350 |
+
Section 6(a), it reinstates:
|
| 351 |
+
|
| 352 |
+
1. automatically as of the date the violation is cured, provided
|
| 353 |
+
it is cured within 30 days of Your discovery of the
|
| 354 |
+
violation; or
|
| 355 |
+
|
| 356 |
+
2. upon express reinstatement by the Licensor.
|
| 357 |
+
|
| 358 |
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
| 359 |
+
right the Licensor may have to seek remedies for Your violations
|
| 360 |
+
of this Public License.
|
| 361 |
+
|
| 362 |
+
c. For the avoidance of doubt, the Licensor may also offer the
|
| 363 |
+
Licensed Material under separate terms or conditions or stop
|
| 364 |
+
distributing the Licensed Material at any time; however, doing so
|
| 365 |
+
will not terminate this Public License.
|
| 366 |
+
|
| 367 |
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
| 368 |
+
License.
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
Section 7 -- Other Terms and Conditions.
|
| 372 |
+
|
| 373 |
+
a. The Licensor shall not be bound by any additional or different
|
| 374 |
+
terms or conditions communicated by You unless expressly agreed.
|
| 375 |
+
|
| 376 |
+
b. Any arrangements, understandings, or agreements regarding the
|
| 377 |
+
Licensed Material not stated herein are separate from and
|
| 378 |
+
independent of the terms and conditions of this Public License.
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
Section 8 -- Interpretation.
|
| 382 |
+
|
| 383 |
+
a. For the avoidance of doubt, this Public License does not, and
|
| 384 |
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
| 385 |
+
conditions on any use of the Licensed Material that could lawfully
|
| 386 |
+
be made without permission under this Public License.
|
| 387 |
+
|
| 388 |
+
b. To the extent possible, if any provision of this Public License is
|
| 389 |
+
deemed unenforceable, it shall be automatically reformed to the
|
| 390 |
+
minimum extent necessary to make it enforceable. If the provision
|
| 391 |
+
cannot be reformed, it shall be severed from this Public License
|
| 392 |
+
without affecting the enforceability of the remaining terms and
|
| 393 |
+
conditions.
|
| 394 |
+
|
| 395 |
+
c. No term or condition of this Public License will be waived and no
|
| 396 |
+
failure to comply consented to unless expressly agreed to by the
|
| 397 |
+
Licensor.
|
| 398 |
+
|
| 399 |
+
d. Nothing in this Public License constitutes or may be interpreted
|
| 400 |
+
as a limitation upon, or waiver of, any privileges and immunities
|
| 401 |
+
that apply to the Licensor or You, including from the legal
|
| 402 |
+
processes of any jurisdiction or authority.
|
| 403 |
+
|
| 404 |
+
=======================================================================
|
| 405 |
+
|
| 406 |
+
Creative Commons is not a party to its public
|
| 407 |
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
| 408 |
+
its public licenses to material it publishes and in those instances
|
| 409 |
+
will be considered the “Licensor.” The text of the Creative Commons
|
| 410 |
+
public licenses is dedicated to the public domain under the CC0 Public
|
| 411 |
+
Domain Dedication. Except for the limited purpose of indicating that
|
| 412 |
+
material is shared under a Creative Commons public license or as
|
| 413 |
+
otherwise permitted by the Creative Commons policies published at
|
| 414 |
+
creativecommons.org/policies, Creative Commons does not authorize the
|
| 415 |
+
use of the trademark "Creative Commons" or any other trademark or logo
|
| 416 |
+
of Creative Commons without its prior written consent including,
|
| 417 |
+
without limitation, in connection with any unauthorized modifications
|
| 418 |
+
to any of its public licenses or any other arrangements,
|
| 419 |
+
understandings, or agreements concerning use of licensed material. For
|
| 420 |
+
the avoidance of doubt, this paragraph does not form part of the
|
| 421 |
+
public licenses.
|
| 422 |
+
|
| 423 |
+
Creative Commons may be contacted at creativecommons.org.
|
| 424 |
+
|
README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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: cc-by-nc-4.0
|
| 3 |
+
library_name: transformers
|
| 4 |
+
pipeline_tag: feature-extraction
|
| 5 |
+
tags:
|
| 6 |
+
- audio
|
| 7 |
+
- music
|
| 8 |
+
- music-understanding
|
| 9 |
+
- representation-learning
|
| 10 |
+
- mert2
|
| 11 |
+
- custom_code
|
| 12 |
+
---
|
| 13 |
+
<h1 align="center">🤗 MERT-v2-FullSong</h1>
|
| 14 |
+
<p align="center"><strong>Music representations with full-song context</strong></p>
|
| 15 |
+
<p align="center">24 kHz mono · 632M parameters · 24 layers · 1,024 dimensions · 25 Hz</p>
|
| 16 |
+
|
| 17 |
+
<p align="center">
|
| 18 |
+
<a href="https://map-yue2.github.io/">🎵 YuE2 project</a>
|
| 19 |
+
·
|
| 20 |
+
<a href="#quick-start">🚀 Quick start</a>
|
| 21 |
+
·
|
| 22 |
+
<a href="#marble">📊 MARBLE</a>
|
| 23 |
+
·
|
| 24 |
+
<a href="#layer-guide">🎛️ Layer guide</a>
|
| 25 |
+
·
|
| 26 |
+
<a href="#citation">📚 Citation</a>
|
| 27 |
+
</p>
|
| 28 |
+
<p align="center">
|
| 29 |
+
<a href="https://huggingface.co/m-a-p/MERT-v2-30s"><img alt="MERT-v2-30s" src="https://img.shields.io/badge/MERT--v2--30s-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 30 |
+
|
| 31 |
+
<a href="https://huggingface.co/m-a-p/MERT-v2-FullSong"><img alt="MERT-v2-FullSong" src="https://img.shields.io/badge/MERT--v2--FullSong-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 32 |
+
|
| 33 |
+
<a href="https://huggingface.co/m-a-p/YuE2-3B"><img alt="YuE2-3B" src="https://img.shields.io/badge/YuE2--3B-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 34 |
+
|
| 35 |
+
<a href="https://huggingface.co/m-a-p/YuE2-Vae"><img alt="🤗 YuE2-Vae" src="https://img.shields.io/badge/YuE2--Vae-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 36 |
+
|
| 37 |
+
<a href="https://huggingface.co/m-a-p/YuE2-Vae-legacy"><img alt="🤗 YuE2-Vae-legacy" src="https://img.shields.io/badge/YuE2--Vae--legacy-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 38 |
+
|
| 39 |
+
<a href="https://huggingface.co/datasets/m-a-p/WildSongBench"><img alt="🤗 WildSongBench" src="https://img.shields.io/badge/WildSongBench-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 40 |
+
|
| 41 |
+
<a href="https://huggingface.co/m-a-p/SheetSage2"><img alt="SheetSage2" src="https://img.shields.io/badge/SheetSage2-374151?logo=huggingface&logoColor=FFD21E" height="20" /></a>
|
| 42 |
+
</p>
|
| 43 |
+
|
| 44 |
+
**MERT-v2-FullSong is a bidirectional music encoder adapted to complete songs lasting 30–360 seconds.** Extract general-purpose music representations at the frame or recording level. Load with standard Hugging Face Transformers, using the familiar [MERT](https://huggingface.co/m-a-p/MERT-v1-330M) workflow.
|
| 45 |
+
|
| 46 |
+
It continues pretraining from [MERT-v2-30s](https://huggingface.co/m-a-p/MERT-v2-30s) and preserves the same feature interface.
|
| 47 |
+
|
| 48 |
+

|
| 49 |
+
|
| 50 |
+
*MERT-v2-30s uses the bidirectional backbone in (B); MERT-v2-FullSong continues through the full-song branch in (C). The causal branch is used for YuE2 tokenization.*
|
| 51 |
+
|
| 52 |
+
<a id="quick-start"></a>
|
| 53 |
+
|
| 54 |
+
## 🚀 Quick start
|
| 55 |
+
|
| 56 |
+
Install the matching PyTorch packages:
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
python -m pip install torch==2.6.0 torchaudio==2.6.0 transformers==4.53.2 huggingface-hub safetensors soundfile
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
import soundfile as sf
|
| 64 |
+
import torch
|
| 65 |
+
import torchaudio.functional as AF
|
| 66 |
+
from transformers import AutoFeatureExtractor, AutoModel
|
| 67 |
+
|
| 68 |
+
repo = "m-a-p/MERT-v2-FullSong"
|
| 69 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 70 |
+
processor = AutoFeatureExtractor.from_pretrained(repo, trust_remote_code=True)
|
| 71 |
+
model = AutoModel.from_pretrained(repo, trust_remote_code=True).eval().to(device)
|
| 72 |
+
|
| 73 |
+
audio, sr = sf.read("music.wav", dtype="float32", always_2d=True)
|
| 74 |
+
audio = audio[:30 * sr].mean(axis=1) # First 30 seconds, mixed to mono.
|
| 75 |
+
waveform = AF.resample(torch.from_numpy(audio), sr, processor.sampling_rate)
|
| 76 |
+
inputs = processor(
|
| 77 |
+
waveform.numpy(), sampling_rate=processor.sampling_rate, return_tensors="pt",
|
| 78 |
+
).to(device)
|
| 79 |
+
|
| 80 |
+
with torch.inference_mode():
|
| 81 |
+
output = model(**inputs, output_hidden_states=True)
|
| 82 |
+
|
| 83 |
+
frames = output.last_hidden_state # [batch, frames, 1024], 25 Hz
|
| 84 |
+
layers = output.hidden_states # 24 tensors, one per block
|
| 85 |
+
mask = output.feature_attention_mask[..., None]
|
| 86 |
+
embedding = (frames * mask).sum(1) / mask.sum(1).clamp_min(1) # [batch, 1024]
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
`hidden_states[0]` is block 1; `hidden_states[23]` is block 24. Remove the audio slice to process a complete song.
|
| 90 |
+
|
| 91 |
+
<a id="marble"></a>
|
| 92 |
+
|
| 93 |
+
## 📊 MARBLE
|
| 94 |
+
|
| 95 |
+
Reported frozen-encoder results on [MARBLE](https://github.com/a43992899/MARBLE). All scores are multiplied by 100; higher is better. **Bold** marks the best displayed value in each column, including ties.
|
| 96 |
+
|
| 97 |
+
Baseline scores and parameter counts are reproduced from Tables III and V of [PupuJEPA](https://arxiv.org/html/2606.25713v2); the baselines were not rerun for this release. Evaluation protocols may differ across sources.
|
| 98 |
+
|
| 99 |
+
**General music understanding.** MTT = MagnaTagATune; key = GiantSteps refined key accuracy; genre and beat = GTZAN; valence and arousal = EmoMusic. ROC = ROC-AUC; AP = average precision.
|
| 100 |
+
|
| 101 |
+
| Model | Params | MTT ROC | MTT AP | Key acc. | Genre acc. | Beat F1 | Valence R² | Arousal R² |
|
| 102 |
+
|---|---:|---:|---:|---:|---:|---:|---:|---:|
|
| 103 |
+
| MERT-Large | 330M | 90.6 | 37.9 | 64.1 | 77.6 | 86.8 | 56.7 | 76.1 |
|
| 104 |
+
| Dasheng-1.2B | 1.2B | 91.5 | 40.4 | 58.0 | 81.4 | 87.7 | 57.4 | 75.0 |
|
| 105 |
+
| MuQ | 310M | 90.5 | 38.5 | 63.2 | 83.8 | 90.1 | 58.3 | 76.4 |
|
| 106 |
+
| MusicFM | 330M | 90.9 | 38.3 | 63.0 | 84.1 | 90.2 | 57.2 | 74.4 |
|
| 107 |
+
| AudioMAE++ | 307M | 91.2 | 39.5 | 61.7 | 80.3 | 90.0 | 59.0 | 75.7 |
|
| 108 |
+
| MATPAC++ | 307M | 90.6 | 38.2 | 63.7 | 81.4 | 90.1 | 57.8 | 74.7 |
|
| 109 |
+
| A-JEPA | 307M | 91.0 | 39.2 | 65.0 | 83.8 | 90.0 | 57.4 | 74.8 |
|
| 110 |
+
| PupuJEPA-Large | 307M | 91.7 | 40.8 | 66.1 | 86.9 | **91.0** | 62.5 | 76.8 |
|
| 111 |
+
| PupuJEPA-Huge | 632M | 91.3 | 39.7 | 64.8 | 85.9 | 90.5 | 62.0 | 78.5 |
|
| 112 |
+
| **MERT-v2-30s** | 632M | **91.91** | **41.29** | 66.97 | **91.72** | 90.59 | 63.23 | **80.01** |
|
| 113 |
+
| **MERT-v2-FullSong** | 632M | 91.74 | 41.20 | **67.05** | 90.69 | 90.57 | **63.52** | 78.14 |
|
| 114 |
+
|
| 115 |
+
**MTG-Jamendo tagging.** Mood denotes mood/theme tags.
|
| 116 |
+
|
| 117 |
+
| Model | Params | Instrument ROC | Instrument AP | Mood ROC | Mood AP | Genre ROC | Genre AP | Top-50 ROC | Top-50 AP |
|
| 118 |
+
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
|
| 119 |
+
| MERT-Large | 330M | 75.5 | 18.8 | 75.3 | 13.5 | 86.1 | 18.0 | 82.6 | 29.1 |
|
| 120 |
+
| Dasheng-1.2B | 1.2B | 75.0 | 19.0 | 76.1 | 15.5 | 85.5 | 18.8 | 82.4 | 29.6 |
|
| 121 |
+
| MuQ | 310M | 74.8 | 19.1 | 73.7 | 13.2 | 85.4 | 19.1 | 83.0 | 30.2 |
|
| 122 |
+
| MusicFM | 330M | 74.6 | 18.5 | 74.9 | 14.1 | 85.3 | 19.4 | 81.9 | 29.7 |
|
| 123 |
+
| AudioMAE++ | 307M | 77.1 | 19.9 | 75.6 | 14.0 | 86.3 | 18.9 | 83.1 | 31.1 |
|
| 124 |
+
| MATPAC++ | 307M | 77.2 | 19.7 | 75.1 | 14.1 | 85.7 | 19.6 | 82.5 | 30.2 |
|
| 125 |
+
| A-JEPA | 307M | 76.6 | 19.3 | 74.6 | 14.3 | 85.5 | 19.2 | 82.5 | 29.6 |
|
| 126 |
+
| PupuJEPA-Large | 307M | 78.4 | 21.2 | 76.2 | 15.3 | 86.1 | 20.1 | 82.8 | 30.5 |
|
| 127 |
+
| PupuJEPA-Huge | 632M | 77.6 | 20.5 | 75.9 | 14.7 | 85.9 | 20.1 | 83.1 | 30.7 |
|
| 128 |
+
| **MERT-v2-30s** | 632M | **80.27** | 22.89 | **79.44** | **16.68** | **88.01** | **21.22** | **84.18** | **32.17** |
|
| 129 |
+
| **MERT-v2-FullSong** | 632M | **80.27** | **23.51** | 78.74 | 15.74 | 87.98 | 20.66 | 84.13 | 31.62 |
|
| 130 |
+
|
| 131 |
+
**Supplemental:** Chords1217 frame accuracy is **78.48** for MERT-v2-30s and **77.79** for MERT-v2-FullSong.
|
| 132 |
+
|
| 133 |
+
<!-- mert2-hf-validation:start -->
|
| 134 |
+
**HF reproduction verified:** Both models reproduce all ten MARBLE tasks with the fixed evaluation settings. [Scores and best settings](marble_results.json).
|
| 135 |
+
<!-- mert2-hf-validation:end -->
|
| 136 |
+
|
| 137 |
+
<a id="layer-guide"></a>
|
| 138 |
+
|
| 139 |
+
## 🎛️ Layer guide
|
| 140 |
+
|
| 141 |
+
Recommended probe settings with the encoder frozen. L1 = `hidden_states[0]`; All-layer MLP uses all 24 layers.
|
| 142 |
+
|
| 143 |
+
| Task / dataset | MERT-v2-30s layer | Probe LR | MERT-v2-FullSong layer | Probe LR |
|
| 144 |
+
|---|---|---:|---|---:|
|
| 145 |
+
| Genre · GTZAN | L23 | 5e-3 | L24 | 5e-4 |
|
| 146 |
+
| Beat · GTZAN | L21 | 1e-3 | L23 | 1e-3 |
|
| 147 |
+
| Key · GiantSteps | L4 | 1e-3 | L23 | 1e-3 |
|
| 148 |
+
| Emotion · EmoMusic | All-layer MLP | 5e-5 | L24 | 5e-4 |
|
| 149 |
+
| Chords · Chords1217 | All-layer MLP | 1e-4 | All-layer MLP | 5e-4 |
|
| 150 |
+
| Tagging · MagnaTagATune | L22 | 1e-3 | L23 | 1e-3 |
|
| 151 |
+
| Instrument · MTG-Jamendo | L14 | 1e-3 | L12 | 1e-3 |
|
| 152 |
+
| Mood/theme · MTG-Jamendo | L16 | 1e-3 | L13 | 1e-3 |
|
| 153 |
+
| Genre · MTG-Jamendo | L19 | 1e-3 | L16 | 1e-3 |
|
| 154 |
+
| Top-50 · MTG-Jamendo | L13 | 1e-3 | L22 | 1e-3 |
|
| 155 |
+
|
| 156 |
+
<a id="citation"></a>
|
| 157 |
+
|
| 158 |
+
## 📚 Citation
|
| 159 |
+
|
| 160 |
+
**Technical report coming soon.** For now, please cite [MERT (ICLR 2024)](https://proceedings.iclr.cc/paper_files/paper/2024/hash/33dffa2e3d2ab74a783d1a8c292f66d9-Abstract-Conference.html) and [MARBLE (NeurIPS 2023)](https://proceedings.neurips.cc/paper_files/paper/2023/hash/7cbeec46f979618beafb4f46d8f39f36-Abstract-Datasets_and_Benchmarks.html) when using MERT-v2 or its benchmark results in your research.
|
| 161 |
+
|
| 162 |
+
```bibtex
|
| 163 |
+
@inproceedings{li2024mert,
|
| 164 |
+
title = {MERT: Acoustic Music Understanding Model with Large-Scale Self-supervised Training},
|
| 165 |
+
author = {Li, Yizhi and Yuan, Ruibin and Zhang, Ge and Ma, Yinghao and Chen, Xingran and Yin, Hanzhi and Xiao, Chenghao and Lin, Chenghua and Ragni, Anton and Benetos, Emmanouil and Gyenge, Norbert and Dannenberg, Roger and Liu, Ruibo and Chen, Wenhu and Xia, Gus and Shi, Yemin and Huang, Wenhao and Wang, Zili and Guo, Yike and Fu, Jie},
|
| 166 |
+
booktitle = {International Conference on Learning Representations},
|
| 167 |
+
year = {2024},
|
| 168 |
+
url = {https://proceedings.iclr.cc/paper_files/paper/2024/hash/33dffa2e3d2ab74a783d1a8c292f66d9-Abstract-Conference.html}
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
@inproceedings{yuan2023marble,
|
| 172 |
+
title = {MARBLE: Music Audio Representation Benchmark for Universal Evaluation},
|
| 173 |
+
author = {Yuan, Ruibin and Ma, Yinghao and Li, Yizhi and Zhang, Ge and Chen, Xingran and Yin, Hanzhi and Zhuo, Le and Liu, Yiqi and Huang, Jiawen and Tian, Zeyue and Deng, Binyue and Wang, Ningzhi and Lin, Chenghua and Benetos, Emmanouil and Ragni, Anton and Gyenge, Norbert and Dannenberg, Roger and Chen, Wenhu and Xia, Gus and Xue, Wei and Liu, Si and Wang, Shi and Liu, Ruibo and Guo, Yike and Fu, Jie},
|
| 174 |
+
booktitle = {Advances in Neural Information Processing Systems},
|
| 175 |
+
volume = {36},
|
| 176 |
+
pages = {39626--39647},
|
| 177 |
+
year = {2023},
|
| 178 |
+
doi = {10.52202/075280-1722},
|
| 179 |
+
url = {https://proceedings.neurips.cc/paper_files/paper/2023/hash/7cbeec46f979618beafb4f46d8f39f36-Abstract-Datasets_and_Benchmarks.html}
|
| 180 |
+
}
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
Weights: [CC BY-NC 4.0](LICENSE). [Dependency notices](THIRD_PARTY_NOTICES.md).
|
| 184 |
+
|
| 185 |
+
**YuE2 family:** [Song generation](https://huggingface.co/m-a-p/YuE2-3B) · [Audio decoder](https://huggingface.co/m-a-p/YuE2-Vae) · [Benchmark decoder](https://huggingface.co/m-a-p/YuE2-Vae-legacy).
|
THIRD_PARTY_NOTICES.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Third-party notices
|
| 2 |
+
|
| 3 |
+
The MERT2 inference implementation uses separately installed PyTorch,
|
| 4 |
+
torchaudio, Hugging Face Transformers, huggingface_hub, and safetensors.
|
| 5 |
+
These dependencies retain their respective upstream licenses and notices;
|
| 6 |
+
this model repository does not redistribute their source distributions.
|
| 7 |
+
|
| 8 |
+
The example additionally uses SoundFile, which retains its upstream license.
|
| 9 |
+
|
| 10 |
+
The MERT2 checkpoint weights are licensed separately under CC BY-NC 4.0;
|
| 11 |
+
see [LICENSE](LICENSE). This weight license does not relicense dependencies.
|
assets/mert2-architecture.png
ADDED
|
Git LFS Details
|
config.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"MERT2Model"
|
| 4 |
+
],
|
| 5 |
+
"auto_map": {
|
| 6 |
+
"AutoConfig": "configuration_mert2.MERT2Config",
|
| 7 |
+
"AutoModel": "modeling_mert2.MERT2Model"
|
| 8 |
+
},
|
| 9 |
+
"context_seconds": 360.0,
|
| 10 |
+
"conv_depthwise_kernel_size": 31,
|
| 11 |
+
"frame_rate": 25.0,
|
| 12 |
+
"hidden_size": 1024,
|
| 13 |
+
"hop_length": 240,
|
| 14 |
+
"initializer_range": 0.02,
|
| 15 |
+
"inputs_to_logits_ratio": 960,
|
| 16 |
+
"intermediate_size": 4096,
|
| 17 |
+
"layer_norm_eps": 1e-05,
|
| 18 |
+
"minimum_input_samples": 1025,
|
| 19 |
+
"model_type": "mert2",
|
| 20 |
+
"n_fft": 2048,
|
| 21 |
+
"num_attention_heads": 16,
|
| 22 |
+
"num_hidden_layers": 24,
|
| 23 |
+
"num_mel_bins": 128,
|
| 24 |
+
"rotary_embedding_base": 10000,
|
| 25 |
+
"sampling_rate": 24000,
|
| 26 |
+
"subsampling_channels": [
|
| 27 |
+
128,
|
| 28 |
+
512,
|
| 29 |
+
1024
|
| 30 |
+
],
|
| 31 |
+
"subsampling_depths": [
|
| 32 |
+
3,
|
| 33 |
+
4,
|
| 34 |
+
5
|
| 35 |
+
],
|
| 36 |
+
"subsampling_layer_norm_eps": 1e-06,
|
| 37 |
+
"torch_dtype": "float32",
|
| 38 |
+
"transformers_version": "4.53.2",
|
| 39 |
+
"variant": "fs",
|
| 40 |
+
"win_length": 2048
|
| 41 |
+
}
|
configuration_mert2.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Configuration for MERT2 music representation models."""
|
| 2 |
+
|
| 3 |
+
from transformers import PretrainedConfig
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class MERT2Config(PretrainedConfig):
|
| 7 |
+
"""Architecture shared by the 30-second and full-song MERT2 encoders."""
|
| 8 |
+
|
| 9 |
+
model_type = "mert2"
|
| 10 |
+
|
| 11 |
+
def __init__(
|
| 12 |
+
self,
|
| 13 |
+
hidden_size=1024,
|
| 14 |
+
intermediate_size=4096,
|
| 15 |
+
num_hidden_layers=24,
|
| 16 |
+
num_attention_heads=16,
|
| 17 |
+
num_mel_bins=128,
|
| 18 |
+
sampling_rate=24000,
|
| 19 |
+
n_fft=2048,
|
| 20 |
+
win_length=2048,
|
| 21 |
+
hop_length=240,
|
| 22 |
+
subsampling_channels=None,
|
| 23 |
+
subsampling_depths=None,
|
| 24 |
+
conv_depthwise_kernel_size=31,
|
| 25 |
+
rotary_embedding_base=10000,
|
| 26 |
+
layer_norm_eps=1e-5,
|
| 27 |
+
subsampling_layer_norm_eps=1e-6,
|
| 28 |
+
initializer_range=0.02,
|
| 29 |
+
variant="30s",
|
| 30 |
+
context_seconds=None,
|
| 31 |
+
**kwargs,
|
| 32 |
+
):
|
| 33 |
+
super().__init__(**kwargs)
|
| 34 |
+
self.hidden_size = int(hidden_size)
|
| 35 |
+
self.intermediate_size = int(intermediate_size)
|
| 36 |
+
self.num_hidden_layers = int(num_hidden_layers)
|
| 37 |
+
self.num_attention_heads = int(num_attention_heads)
|
| 38 |
+
self.num_mel_bins = int(num_mel_bins)
|
| 39 |
+
self.sampling_rate = int(sampling_rate)
|
| 40 |
+
self.n_fft = int(n_fft)
|
| 41 |
+
self.win_length = int(win_length)
|
| 42 |
+
self.hop_length = int(hop_length)
|
| 43 |
+
self.subsampling_channels = list(subsampling_channels or [num_mel_bins, 512, hidden_size])
|
| 44 |
+
self.subsampling_depths = list(subsampling_depths or [3, 4, 5])
|
| 45 |
+
self.conv_depthwise_kernel_size = int(conv_depthwise_kernel_size)
|
| 46 |
+
self.rotary_embedding_base = int(rotary_embedding_base)
|
| 47 |
+
self.layer_norm_eps = float(layer_norm_eps)
|
| 48 |
+
self.subsampling_layer_norm_eps = float(subsampling_layer_norm_eps)
|
| 49 |
+
self.initializer_range = float(initializer_range)
|
| 50 |
+
self.variant = str(variant)
|
| 51 |
+
self.context_seconds = float(context_seconds if context_seconds is not None else (360 if variant == "fs" else 30))
|
| 52 |
+
self.inputs_to_logits_ratio = self.hop_length * 4
|
| 53 |
+
self.frame_rate = self.sampling_rate / self.inputs_to_logits_ratio
|
| 54 |
+
self.minimum_input_samples = self.n_fft // 2 + 1
|
| 55 |
+
|
| 56 |
+
if min(self.hidden_size, self.intermediate_size, self.num_hidden_layers, self.num_attention_heads) <= 0:
|
| 57 |
+
raise ValueError("Encoder dimensions and layer counts must be positive.")
|
| 58 |
+
if self.hidden_size % self.num_attention_heads or (self.hidden_size // self.num_attention_heads) % 2:
|
| 59 |
+
raise ValueError("hidden_size must divide into an even head dimension.")
|
| 60 |
+
if len(self.subsampling_channels) != 3 or len(self.subsampling_depths) != 3:
|
| 61 |
+
raise ValueError("The subsampler must contain three channel widths and three depths.")
|
| 62 |
+
if self.subsampling_channels[0] != self.num_mel_bins or self.subsampling_channels[-1] != self.hidden_size:
|
| 63 |
+
raise ValueError("Subsampling widths must start at num_mel_bins and end at hidden_size.")
|
| 64 |
+
if min(*self.subsampling_channels, *self.subsampling_depths, self.num_mel_bins, self.sampling_rate, self.hop_length) <= 0:
|
| 65 |
+
raise ValueError("Frontend dimensions and sampling parameters must be positive.")
|
| 66 |
+
if self.n_fft < self.win_length or self.win_length <= 0 or self.n_fft % 2:
|
| 67 |
+
raise ValueError("n_fft must be even and at least win_length > 0.")
|
| 68 |
+
if self.conv_depthwise_kernel_size <= 0 or self.conv_depthwise_kernel_size % 2 != 1:
|
| 69 |
+
raise ValueError("conv_depthwise_kernel_size must be positive and odd.")
|
| 70 |
+
if self.rotary_embedding_base <= 0 or min(self.layer_norm_eps, self.subsampling_layer_norm_eps) <= 0:
|
| 71 |
+
raise ValueError("Rotary base and normalization epsilons must be positive.")
|
| 72 |
+
if self.variant not in {"30s", "fs"}:
|
| 73 |
+
raise ValueError("variant must be '30s' or 'fs'.")
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
MERT2Config.register_for_auto_class()
|
marble_results.json
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 2,
|
| 3 |
+
"benchmark": "MARBLE",
|
| 4 |
+
"metric_scale": 1,
|
| 5 |
+
"display_scale": 100,
|
| 6 |
+
"models": {
|
| 7 |
+
"MERT-v2-30s": {
|
| 8 |
+
"repo_id": "a43992899/MERT-v2-30s",
|
| 9 |
+
"tasks": [
|
| 10 |
+
{
|
| 11 |
+
"dataset": "GTZAN",
|
| 12 |
+
"task": "Genre classification",
|
| 13 |
+
"supplemental": false,
|
| 14 |
+
"representation": {
|
| 15 |
+
"mode": "fixed_layer",
|
| 16 |
+
"layer": 23,
|
| 17 |
+
"hidden_state_index": 22
|
| 18 |
+
},
|
| 19 |
+
"learning_rate": 0.005,
|
| 20 |
+
"probe_seed": 1234,
|
| 21 |
+
"metrics": {
|
| 22 |
+
"file_acc": 0.9172413945198059
|
| 23 |
+
}
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"dataset": "GTZAN",
|
| 27 |
+
"task": "Beat tracking",
|
| 28 |
+
"supplemental": false,
|
| 29 |
+
"representation": {
|
| 30 |
+
"mode": "fixed_layer",
|
| 31 |
+
"layer": 21,
|
| 32 |
+
"hidden_state_index": 20
|
| 33 |
+
},
|
| 34 |
+
"learning_rate": 0.001,
|
| 35 |
+
"probe_seed": 1234,
|
| 36 |
+
"metrics": {
|
| 37 |
+
"beat_f1": 0.9058816432952881
|
| 38 |
+
}
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"dataset": "GiantSteps",
|
| 42 |
+
"task": "Key detection",
|
| 43 |
+
"supplemental": false,
|
| 44 |
+
"representation": {
|
| 45 |
+
"mode": "fixed_layer",
|
| 46 |
+
"layer": 4,
|
| 47 |
+
"hidden_state_index": 3
|
| 48 |
+
},
|
| 49 |
+
"learning_rate": 0.001,
|
| 50 |
+
"probe_seed": 1234,
|
| 51 |
+
"metrics": {
|
| 52 |
+
"weighted_score": 0.6697019867549668
|
| 53 |
+
}
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"dataset": "EmoMusic",
|
| 57 |
+
"task": "Emotion recognition",
|
| 58 |
+
"supplemental": false,
|
| 59 |
+
"representation": {
|
| 60 |
+
"mode": "learned_all_layer_mlp",
|
| 61 |
+
"num_layers": 24
|
| 62 |
+
},
|
| 63 |
+
"learning_rate": 5e-05,
|
| 64 |
+
"probe_seed": 1234,
|
| 65 |
+
"metrics": {
|
| 66 |
+
"valence_r2": 0.6322920322418213,
|
| 67 |
+
"arousal_r2": 0.8000704646110535
|
| 68 |
+
}
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"dataset": "Chords1217",
|
| 72 |
+
"task": "Chord recognition",
|
| 73 |
+
"supplemental": true,
|
| 74 |
+
"representation": {
|
| 75 |
+
"mode": "learned_all_layer_mlp",
|
| 76 |
+
"num_layers": 24
|
| 77 |
+
},
|
| 78 |
+
"learning_rate": 0.0001,
|
| 79 |
+
"probe_seed": 1234,
|
| 80 |
+
"metrics": {
|
| 81 |
+
"acc": 0.7847631573677063
|
| 82 |
+
}
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"dataset": "MagnaTagATune",
|
| 86 |
+
"task": "Tagging",
|
| 87 |
+
"supplemental": false,
|
| 88 |
+
"representation": {
|
| 89 |
+
"mode": "fixed_layer",
|
| 90 |
+
"layer": 22,
|
| 91 |
+
"hidden_state_index": 21
|
| 92 |
+
},
|
| 93 |
+
"learning_rate": 0.001,
|
| 94 |
+
"probe_seed": 1234,
|
| 95 |
+
"metrics": {
|
| 96 |
+
"auroc": 0.9190762042999268,
|
| 97 |
+
"average_precision": 0.4129374325275421
|
| 98 |
+
}
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"dataset": "MTG-Jamendo",
|
| 102 |
+
"task": "Genre tagging",
|
| 103 |
+
"supplemental": false,
|
| 104 |
+
"representation": {
|
| 105 |
+
"mode": "fixed_layer",
|
| 106 |
+
"layer": 19,
|
| 107 |
+
"hidden_state_index": 18
|
| 108 |
+
},
|
| 109 |
+
"learning_rate": 0.001,
|
| 110 |
+
"probe_seed": 1234,
|
| 111 |
+
"metrics": {
|
| 112 |
+
"auroc": 0.8801141381263733,
|
| 113 |
+
"average_precision": 0.21221663057804108
|
| 114 |
+
}
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"dataset": "MTG-Jamendo",
|
| 118 |
+
"task": "Instrument tagging",
|
| 119 |
+
"supplemental": false,
|
| 120 |
+
"representation": {
|
| 121 |
+
"mode": "fixed_layer",
|
| 122 |
+
"layer": 14,
|
| 123 |
+
"hidden_state_index": 13
|
| 124 |
+
},
|
| 125 |
+
"learning_rate": 0.001,
|
| 126 |
+
"probe_seed": 1234,
|
| 127 |
+
"metrics": {
|
| 128 |
+
"auroc": 0.8027445673942566,
|
| 129 |
+
"average_precision": 0.2288619726896286
|
| 130 |
+
}
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"dataset": "MTG-Jamendo",
|
| 134 |
+
"task": "Mood/theme tagging",
|
| 135 |
+
"supplemental": false,
|
| 136 |
+
"representation": {
|
| 137 |
+
"mode": "fixed_layer",
|
| 138 |
+
"layer": 16,
|
| 139 |
+
"hidden_state_index": 15
|
| 140 |
+
},
|
| 141 |
+
"learning_rate": 0.001,
|
| 142 |
+
"probe_seed": 1234,
|
| 143 |
+
"metrics": {
|
| 144 |
+
"auroc": 0.7944093942642212,
|
| 145 |
+
"average_precision": 0.16676680743694305
|
| 146 |
+
}
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"dataset": "MTG-Jamendo",
|
| 150 |
+
"task": "Top-50 tagging",
|
| 151 |
+
"supplemental": false,
|
| 152 |
+
"representation": {
|
| 153 |
+
"mode": "fixed_layer",
|
| 154 |
+
"layer": 13,
|
| 155 |
+
"hidden_state_index": 12
|
| 156 |
+
},
|
| 157 |
+
"learning_rate": 0.001,
|
| 158 |
+
"probe_seed": 1234,
|
| 159 |
+
"metrics": {
|
| 160 |
+
"auroc": 0.8417603969573975,
|
| 161 |
+
"average_precision": 0.3217017948627472
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
]
|
| 165 |
+
},
|
| 166 |
+
"MERT-v2-FullSong": {
|
| 167 |
+
"repo_id": "a43992899/MERT-v2-FullSong",
|
| 168 |
+
"tasks": [
|
| 169 |
+
{
|
| 170 |
+
"dataset": "GTZAN",
|
| 171 |
+
"task": "Genre classification",
|
| 172 |
+
"supplemental": false,
|
| 173 |
+
"representation": {
|
| 174 |
+
"mode": "fixed_layer",
|
| 175 |
+
"layer": 24,
|
| 176 |
+
"hidden_state_index": 23
|
| 177 |
+
},
|
| 178 |
+
"learning_rate": 0.0005,
|
| 179 |
+
"probe_seed": 1234,
|
| 180 |
+
"metrics": {
|
| 181 |
+
"file_acc": 0.9068965315818787
|
| 182 |
+
}
|
| 183 |
+
},
|
| 184 |
+
{
|
| 185 |
+
"dataset": "GTZAN",
|
| 186 |
+
"task": "Beat tracking",
|
| 187 |
+
"supplemental": false,
|
| 188 |
+
"representation": {
|
| 189 |
+
"mode": "fixed_layer",
|
| 190 |
+
"layer": 23,
|
| 191 |
+
"hidden_state_index": 22
|
| 192 |
+
},
|
| 193 |
+
"learning_rate": 0.001,
|
| 194 |
+
"probe_seed": 1234,
|
| 195 |
+
"metrics": {
|
| 196 |
+
"beat_f1": 0.9057297706604004
|
| 197 |
+
}
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"dataset": "GiantSteps",
|
| 201 |
+
"task": "Key detection",
|
| 202 |
+
"supplemental": false,
|
| 203 |
+
"representation": {
|
| 204 |
+
"mode": "fixed_layer",
|
| 205 |
+
"layer": 23,
|
| 206 |
+
"hidden_state_index": 22
|
| 207 |
+
},
|
| 208 |
+
"learning_rate": 0.001,
|
| 209 |
+
"probe_seed": 1234,
|
| 210 |
+
"metrics": {
|
| 211 |
+
"weighted_score": 0.6705298013245033
|
| 212 |
+
}
|
| 213 |
+
},
|
| 214 |
+
{
|
| 215 |
+
"dataset": "EmoMusic",
|
| 216 |
+
"task": "Emotion recognition",
|
| 217 |
+
"supplemental": false,
|
| 218 |
+
"representation": {
|
| 219 |
+
"mode": "fixed_layer",
|
| 220 |
+
"layer": 24,
|
| 221 |
+
"hidden_state_index": 23
|
| 222 |
+
},
|
| 223 |
+
"learning_rate": 0.0005,
|
| 224 |
+
"probe_seed": 1234,
|
| 225 |
+
"metrics": {
|
| 226 |
+
"valence_r2": 0.6351668834686279,
|
| 227 |
+
"arousal_r2": 0.7814431190490723
|
| 228 |
+
}
|
| 229 |
+
},
|
| 230 |
+
{
|
| 231 |
+
"dataset": "Chords1217",
|
| 232 |
+
"task": "Chord recognition",
|
| 233 |
+
"supplemental": true,
|
| 234 |
+
"representation": {
|
| 235 |
+
"mode": "learned_all_layer_mlp",
|
| 236 |
+
"num_layers": 24
|
| 237 |
+
},
|
| 238 |
+
"learning_rate": 0.0005,
|
| 239 |
+
"probe_seed": 1234,
|
| 240 |
+
"metrics": {
|
| 241 |
+
"acc": 0.7779459357261658
|
| 242 |
+
}
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"dataset": "MagnaTagATune",
|
| 246 |
+
"task": "Tagging",
|
| 247 |
+
"supplemental": false,
|
| 248 |
+
"representation": {
|
| 249 |
+
"mode": "fixed_layer",
|
| 250 |
+
"layer": 23,
|
| 251 |
+
"hidden_state_index": 22
|
| 252 |
+
},
|
| 253 |
+
"learning_rate": 0.001,
|
| 254 |
+
"probe_seed": 1234,
|
| 255 |
+
"metrics": {
|
| 256 |
+
"auroc": 0.9173608422279358,
|
| 257 |
+
"average_precision": 0.4120141565799713
|
| 258 |
+
}
|
| 259 |
+
},
|
| 260 |
+
{
|
| 261 |
+
"dataset": "MTG-Jamendo",
|
| 262 |
+
"task": "Genre tagging",
|
| 263 |
+
"supplemental": false,
|
| 264 |
+
"representation": {
|
| 265 |
+
"mode": "fixed_layer",
|
| 266 |
+
"layer": 16,
|
| 267 |
+
"hidden_state_index": 15
|
| 268 |
+
},
|
| 269 |
+
"learning_rate": 0.001,
|
| 270 |
+
"probe_seed": 1234,
|
| 271 |
+
"metrics": {
|
| 272 |
+
"auroc": 0.8797574043273926,
|
| 273 |
+
"average_precision": 0.20656391978263855
|
| 274 |
+
}
|
| 275 |
+
},
|
| 276 |
+
{
|
| 277 |
+
"dataset": "MTG-Jamendo",
|
| 278 |
+
"task": "Instrument tagging",
|
| 279 |
+
"supplemental": false,
|
| 280 |
+
"representation": {
|
| 281 |
+
"mode": "fixed_layer",
|
| 282 |
+
"layer": 12,
|
| 283 |
+
"hidden_state_index": 11
|
| 284 |
+
},
|
| 285 |
+
"learning_rate": 0.001,
|
| 286 |
+
"probe_seed": 1234,
|
| 287 |
+
"metrics": {
|
| 288 |
+
"auroc": 0.8026924133300781,
|
| 289 |
+
"average_precision": 0.2351299524307251
|
| 290 |
+
}
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"dataset": "MTG-Jamendo",
|
| 294 |
+
"task": "Mood/theme tagging",
|
| 295 |
+
"supplemental": false,
|
| 296 |
+
"representation": {
|
| 297 |
+
"mode": "fixed_layer",
|
| 298 |
+
"layer": 13,
|
| 299 |
+
"hidden_state_index": 12
|
| 300 |
+
},
|
| 301 |
+
"learning_rate": 0.001,
|
| 302 |
+
"probe_seed": 1234,
|
| 303 |
+
"metrics": {
|
| 304 |
+
"auroc": 0.7874246835708618,
|
| 305 |
+
"average_precision": 0.15743640065193176
|
| 306 |
+
}
|
| 307 |
+
},
|
| 308 |
+
{
|
| 309 |
+
"dataset": "MTG-Jamendo",
|
| 310 |
+
"task": "Top-50 tagging",
|
| 311 |
+
"supplemental": false,
|
| 312 |
+
"representation": {
|
| 313 |
+
"mode": "fixed_layer",
|
| 314 |
+
"layer": 22,
|
| 315 |
+
"hidden_state_index": 21
|
| 316 |
+
},
|
| 317 |
+
"learning_rate": 0.001,
|
| 318 |
+
"probe_seed": 1234,
|
| 319 |
+
"metrics": {
|
| 320 |
+
"auroc": 0.8413298726081848,
|
| 321 |
+
"average_precision": 0.3162302076816559
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
]
|
| 325 |
+
}
|
| 326 |
+
}
|
| 327 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e6dd2ab187d6dd62b6521cd7d8f932e237acf0c5757745a7232082e28391350d
|
| 3 |
+
size 2529812848
|
modeling_mert2.py
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Standalone MERT2 waveform-to-representation inference."""
|
| 2 |
+
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
from typing import Optional, Tuple
|
| 5 |
+
|
| 6 |
+
import torch
|
| 7 |
+
from torch import nn
|
| 8 |
+
from torch.nn import functional as F
|
| 9 |
+
from torchaudio.transforms import AmplitudeToDB, MelScale, Spectrogram
|
| 10 |
+
from transformers import PreTrainedModel
|
| 11 |
+
from transformers.utils import ModelOutput
|
| 12 |
+
|
| 13 |
+
from .configuration_mert2 import MERT2Config
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@dataclass
|
| 17 |
+
class MERT2ModelOutput(ModelOutput):
|
| 18 |
+
"""Frame representations and their validity mask.
|
| 19 |
+
|
| 20 |
+
``hidden_states`` contains one tensor per Conformer block, without an input
|
| 21 |
+
embedding. ``feature_attention_mask`` is True at valid output frames.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
last_hidden_state: Optional[torch.FloatTensor] = None
|
| 25 |
+
hidden_states: Optional[Tuple[torch.FloatTensor, ...]] = None
|
| 26 |
+
feature_attention_mask: Optional[torch.BoolTensor] = None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class MERT2MelFrontend(nn.Module):
|
| 30 |
+
"""Power log-mel features with fixed, checkpoint-specific normalization."""
|
| 31 |
+
|
| 32 |
+
def __init__(self, config):
|
| 33 |
+
super().__init__()
|
| 34 |
+
# Filter construction requires real tensors even during meta loading.
|
| 35 |
+
with torch.device("cpu"):
|
| 36 |
+
self.register_buffer("mel_mean", torch.zeros(config.num_mel_bins, dtype=torch.float32))
|
| 37 |
+
self.register_buffer("mel_std", torch.ones(config.num_mel_bins, dtype=torch.float32))
|
| 38 |
+
self.spectrogram = Spectrogram(
|
| 39 |
+
n_fft=config.n_fft,
|
| 40 |
+
win_length=config.win_length,
|
| 41 |
+
hop_length=config.hop_length,
|
| 42 |
+
power=2.0,
|
| 43 |
+
).float()
|
| 44 |
+
self.mel_scale = MelScale(
|
| 45 |
+
n_mels=config.num_mel_bins,
|
| 46 |
+
sample_rate=config.sampling_rate,
|
| 47 |
+
n_stft=config.n_fft // 2 + 1,
|
| 48 |
+
).float()
|
| 49 |
+
self.amplitude_to_db = AmplitudeToDB(stype="power", top_db=None)
|
| 50 |
+
|
| 51 |
+
def _apply(self, fn, recurse=True):
|
| 52 |
+
# Preserve the original float32 values, including on model.half().
|
| 53 |
+
saved = [(module, name, value) for module in self.modules() for name, value in module._buffers.items() if value is not None]
|
| 54 |
+
super()._apply(fn, recurse=recurse)
|
| 55 |
+
for module, name, original in saved:
|
| 56 |
+
current = module._buffers[name]
|
| 57 |
+
if original.is_floating_point():
|
| 58 |
+
module._buffers[name] = (
|
| 59 |
+
current.float() if original.is_meta else original.to(device=current.device, dtype=torch.float32)
|
| 60 |
+
)
|
| 61 |
+
return self
|
| 62 |
+
|
| 63 |
+
@torch.no_grad()
|
| 64 |
+
def forward(self, waveform):
|
| 65 |
+
with torch.autocast(device_type=waveform.device.type, enabled=False):
|
| 66 |
+
spectrum = self.spectrogram(waveform.float())
|
| 67 |
+
mel = self.amplitude_to_db(self.mel_scale(spectrum))
|
| 68 |
+
mel = mel[..., :-1].transpose(-1, -2)
|
| 69 |
+
return (mel - self.mel_mean) / self.mel_std.clamp_min(1e-5)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class Transpose(nn.Module):
|
| 73 |
+
def forward(self, hidden_states):
|
| 74 |
+
return hidden_states.transpose(1, 2)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class GlobalResponseNorm(nn.Module):
|
| 78 |
+
def __init__(self, dim):
|
| 79 |
+
super().__init__()
|
| 80 |
+
self.weight = nn.Parameter(torch.zeros(1, 1, dim))
|
| 81 |
+
self.bias = nn.Parameter(torch.zeros(1, 1, dim))
|
| 82 |
+
|
| 83 |
+
def forward(self, hidden_states):
|
| 84 |
+
magnitude = torch.norm(hidden_states, p=2, dim=1, keepdim=True)
|
| 85 |
+
normalized = magnitude / (magnitude.mean(dim=-1, keepdim=True) + 1e-6)
|
| 86 |
+
return self.weight * (hidden_states * normalized) + self.bias + hidden_states
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class ConvNextLayer(nn.Module):
|
| 90 |
+
def __init__(self, dim, eps):
|
| 91 |
+
super().__init__()
|
| 92 |
+
self.depthwise_block = nn.Sequential(
|
| 93 |
+
Transpose(), nn.Conv1d(dim, dim, 7, padding=3, groups=dim), Transpose()
|
| 94 |
+
)
|
| 95 |
+
self.pointwise_block = nn.Sequential(
|
| 96 |
+
nn.LayerNorm(dim, eps=eps),
|
| 97 |
+
nn.Linear(dim, 4 * dim),
|
| 98 |
+
nn.GELU(),
|
| 99 |
+
GlobalResponseNorm(4 * dim),
|
| 100 |
+
nn.Linear(4 * dim, dim),
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
def forward(self, hidden_states):
|
| 104 |
+
return hidden_states + self.pointwise_block(self.depthwise_block(hidden_states))
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class ConvNextBlock(nn.Module):
|
| 108 |
+
def __init__(self, in_channels, out_channels, stride, depth, eps):
|
| 109 |
+
super().__init__()
|
| 110 |
+
self.resampling_layer = (
|
| 111 |
+
nn.Sequential(
|
| 112 |
+
nn.LayerNorm(in_channels, eps=eps),
|
| 113 |
+
Transpose(),
|
| 114 |
+
nn.Conv1d(in_channels, out_channels, 2, stride=stride),
|
| 115 |
+
Transpose(),
|
| 116 |
+
)
|
| 117 |
+
if in_channels != out_channels or stride > 1 else nn.Identity()
|
| 118 |
+
)
|
| 119 |
+
self.convnext_layers = nn.Sequential(*[ConvNextLayer(out_channels, eps) for _ in range(depth)])
|
| 120 |
+
|
| 121 |
+
def forward(self, hidden_states):
|
| 122 |
+
return self.convnext_layers(self.resampling_layer(hidden_states))
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class RotaryEmbedding(nn.Module):
|
| 126 |
+
def __init__(self, config):
|
| 127 |
+
super().__init__()
|
| 128 |
+
self.head_dim = config.hidden_size // config.num_attention_heads
|
| 129 |
+
self.base = config.rotary_embedding_base
|
| 130 |
+
with torch.device("cpu"):
|
| 131 |
+
inverse_frequency = 1.0 / (
|
| 132 |
+
self.base ** (torch.arange(0, self.head_dim, 2, dtype=torch.float32) / self.head_dim)
|
| 133 |
+
)
|
| 134 |
+
self.register_buffer("inv_freq", inverse_frequency, persistent=False)
|
| 135 |
+
self._sequence_length = 0
|
| 136 |
+
self._cache_device = None
|
| 137 |
+
self._cos = None
|
| 138 |
+
self._sin = None
|
| 139 |
+
|
| 140 |
+
def _apply(self, fn, recurse=True):
|
| 141 |
+
original = self.inv_freq
|
| 142 |
+
super()._apply(fn, recurse=recurse)
|
| 143 |
+
self.inv_freq = original.to(device=self.inv_freq.device, dtype=torch.float32)
|
| 144 |
+
return self
|
| 145 |
+
|
| 146 |
+
def forward(self, hidden_states):
|
| 147 |
+
length = hidden_states.shape[1]
|
| 148 |
+
if self._cos is None or self._cache_device != hidden_states.device or length > self._sequence_length:
|
| 149 |
+
positions = torch.arange(length, device=hidden_states.device, dtype=self.inv_freq.dtype)
|
| 150 |
+
frequencies = torch.einsum("i,j->ij", positions, self.inv_freq)
|
| 151 |
+
angles = torch.cat((frequencies, frequencies), dim=-1)
|
| 152 |
+
self._cos = angles.cos()[:, None, None, :]
|
| 153 |
+
self._sin = angles.sin()[:, None, None, :]
|
| 154 |
+
self._sequence_length = length
|
| 155 |
+
self._cache_device = hidden_states.device
|
| 156 |
+
return (
|
| 157 |
+
self._cos[:length].to(hidden_states.dtype).permute(1, 0, 2, 3),
|
| 158 |
+
self._sin[:length].to(hidden_states.dtype).permute(1, 0, 2, 3),
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def rotate_half(value):
|
| 163 |
+
first, second = value.chunk(2, dim=-1)
|
| 164 |
+
return torch.cat((-second, first), dim=-1)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
class SelfAttention(nn.Module):
|
| 168 |
+
def __init__(self, config):
|
| 169 |
+
super().__init__()
|
| 170 |
+
self.config = config
|
| 171 |
+
self.num_heads = config.num_attention_heads
|
| 172 |
+
self.head_dim = config.hidden_size // self.num_heads
|
| 173 |
+
self.query_proj = nn.Linear(config.hidden_size, config.hidden_size)
|
| 174 |
+
self.key_proj = nn.Linear(config.hidden_size, config.hidden_size)
|
| 175 |
+
self.value_proj = nn.Linear(config.hidden_size, config.hidden_size)
|
| 176 |
+
self.out_proj = nn.Linear(config.hidden_size, config.hidden_size)
|
| 177 |
+
|
| 178 |
+
def forward(self, hidden_states, position_embeddings):
|
| 179 |
+
batch, time, width = hidden_states.shape
|
| 180 |
+
shape = (batch, time, self.num_heads, self.head_dim)
|
| 181 |
+
query = self.query_proj(hidden_states).reshape(shape)
|
| 182 |
+
key = self.key_proj(hidden_states).reshape(shape)
|
| 183 |
+
value = self.value_proj(hidden_states).reshape(shape)
|
| 184 |
+
cos, sin = position_embeddings
|
| 185 |
+
query = query * cos + rotate_half(query) * sin
|
| 186 |
+
key = key * cos + rotate_half(key) * sin
|
| 187 |
+
if self.config._attn_implementation == "flash_attention_2":
|
| 188 |
+
if query.device.type != "cuda" or query.dtype not in (torch.float16, torch.bfloat16):
|
| 189 |
+
raise ValueError("flash_attention_2 requires CUDA and float16/bfloat16 activations; use autocast or load a reduced-precision model.")
|
| 190 |
+
try:
|
| 191 |
+
from flash_attn import flash_attn_func
|
| 192 |
+
except ImportError as error:
|
| 193 |
+
raise ImportError("Install flash-attn to use flash_attention_2, or select attn_implementation='sdpa'.") from error
|
| 194 |
+
attended = flash_attn_func(query.contiguous(), key.contiguous(), value.contiguous(), dropout_p=0.0, causal=False)
|
| 195 |
+
else:
|
| 196 |
+
attended = F.scaled_dot_product_attention(
|
| 197 |
+
query.transpose(1, 2), key.transpose(1, 2), value.transpose(1, 2), dropout_p=0.0, is_causal=False
|
| 198 |
+
).transpose(1, 2)
|
| 199 |
+
return self.out_proj(attended.reshape(batch, time, width))
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
class FeedForward(nn.Module):
|
| 203 |
+
def __init__(self, config):
|
| 204 |
+
super().__init__()
|
| 205 |
+
self.w_1 = nn.Linear(config.hidden_size, config.intermediate_size)
|
| 206 |
+
self.w_2 = nn.Linear(config.intermediate_size, config.hidden_size)
|
| 207 |
+
|
| 208 |
+
def forward(self, hidden_states):
|
| 209 |
+
return self.w_2(F.gelu(self.w_1(hidden_states)))
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class ConvolutionModule(nn.Module):
|
| 213 |
+
def __init__(self, config):
|
| 214 |
+
super().__init__()
|
| 215 |
+
width = config.hidden_size
|
| 216 |
+
kernel = config.conv_depthwise_kernel_size
|
| 217 |
+
self.layer_norm = nn.LayerNorm(width, eps=config.layer_norm_eps)
|
| 218 |
+
self.conv_block = nn.Sequential(
|
| 219 |
+
Transpose(),
|
| 220 |
+
nn.Conv1d(width, 2 * width, 1, bias=False),
|
| 221 |
+
nn.GLU(dim=1),
|
| 222 |
+
nn.Conv1d(width, width, kernel, padding=(kernel - 1) // 2, groups=width, bias=False),
|
| 223 |
+
nn.Sequential(Transpose(), nn.LayerNorm(width, eps=config.layer_norm_eps), Transpose()),
|
| 224 |
+
nn.GELU(),
|
| 225 |
+
nn.Conv1d(width, width, 1, bias=False),
|
| 226 |
+
Transpose(),
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
def forward(self, hidden_states):
|
| 230 |
+
return self.conv_block(self.layer_norm(hidden_states))
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
class ConformerBlock(nn.Module):
|
| 234 |
+
def __init__(self, config):
|
| 235 |
+
super().__init__()
|
| 236 |
+
width, eps = config.hidden_size, config.layer_norm_eps
|
| 237 |
+
self.ffn1_layer_norm = nn.LayerNorm(width, eps=eps)
|
| 238 |
+
self.ffn1 = FeedForward(config)
|
| 239 |
+
self.attn_layer_norm = nn.LayerNorm(width, eps=eps)
|
| 240 |
+
self.attn = SelfAttention(config)
|
| 241 |
+
self.conv_module = ConvolutionModule(config)
|
| 242 |
+
self.ffn2_layer_norm = nn.LayerNorm(width, eps=eps)
|
| 243 |
+
self.ffn2 = FeedForward(config)
|
| 244 |
+
self.final_layer_norm = nn.LayerNorm(width, eps=eps)
|
| 245 |
+
|
| 246 |
+
def forward(self, hidden_states, position_embeddings):
|
| 247 |
+
hidden_states = hidden_states + 0.5 * self.ffn1(self.ffn1_layer_norm(hidden_states))
|
| 248 |
+
hidden_states = self.attn(self.attn_layer_norm(hidden_states), position_embeddings) + hidden_states
|
| 249 |
+
hidden_states = self.conv_module(hidden_states) + hidden_states
|
| 250 |
+
hidden_states = hidden_states + 0.5 * self.ffn2(self.ffn2_layer_norm(hidden_states))
|
| 251 |
+
return self.final_layer_norm(hidden_states)
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
class MERT2Model(PreTrainedModel):
|
| 255 |
+
"""Encode mono waveforms into 25 Hz MERT2 frame representations.
|
| 256 |
+
|
| 257 |
+
Inputs are floating-point mono waveforms sampled at ``config.sampling_rate``.
|
| 258 |
+
Do not standardize their amplitude. An optional waveform attention mask must
|
| 259 |
+
contain a prefix of ones followed by zeros. Without a mask, every input
|
| 260 |
+
sample, including any caller-provided silence or padding, is processed.
|
| 261 |
+
"""
|
| 262 |
+
|
| 263 |
+
config_class = MERT2Config
|
| 264 |
+
base_model_prefix = ""
|
| 265 |
+
main_input_name = "input_values"
|
| 266 |
+
_supports_sdpa = True
|
| 267 |
+
_supports_flash_attn_2 = True
|
| 268 |
+
_no_split_modules = ["ConvNextBlock", "ConformerBlock"]
|
| 269 |
+
|
| 270 |
+
def __init__(self, config):
|
| 271 |
+
super().__init__(config)
|
| 272 |
+
if config._attn_implementation not in {"sdpa", "flash_attention_2"}:
|
| 273 |
+
raise ValueError("MERT2 supports attn_implementation='sdpa' or 'flash_attention_2'.")
|
| 274 |
+
self.feature_extractor = MERT2MelFrontend(config)
|
| 275 |
+
channels = [config.num_mel_bins] + config.subsampling_channels
|
| 276 |
+
self.subsampling_module = nn.Sequential(*[
|
| 277 |
+
ConvNextBlock(channels[i], channels[i + 1], (1, 2, 2)[i], config.subsampling_depths[i], config.subsampling_layer_norm_eps)
|
| 278 |
+
for i in range(3)
|
| 279 |
+
])
|
| 280 |
+
self.layers = nn.ModuleList([ConformerBlock(config) for _ in range(config.num_hidden_layers)])
|
| 281 |
+
self.embed_positions = RotaryEmbedding(config)
|
| 282 |
+
self.post_init()
|
| 283 |
+
|
| 284 |
+
def _init_weights(self, module):
|
| 285 |
+
if isinstance(module, (nn.Linear, nn.Conv1d)):
|
| 286 |
+
nn.init.normal_(module.weight, mean=0.0, std=self.config.initializer_range)
|
| 287 |
+
if module.bias is not None:
|
| 288 |
+
nn.init.zeros_(module.bias)
|
| 289 |
+
elif isinstance(module, nn.LayerNorm):
|
| 290 |
+
nn.init.ones_(module.weight)
|
| 291 |
+
nn.init.zeros_(module.bias)
|
| 292 |
+
|
| 293 |
+
def _get_feat_extract_output_lengths(self, input_lengths):
|
| 294 |
+
return input_lengths // self.config.inputs_to_logits_ratio
|
| 295 |
+
|
| 296 |
+
def _encode(self, input_values, output_hidden_states):
|
| 297 |
+
mel = self.feature_extractor(input_values)
|
| 298 |
+
input_dtype = self.subsampling_module[0].convnext_layers[0].depthwise_block[1].weight.dtype
|
| 299 |
+
hidden = self.subsampling_module(mel.to(dtype=input_dtype))
|
| 300 |
+
positions = self.embed_positions(hidden)
|
| 301 |
+
states = [] if output_hidden_states else None
|
| 302 |
+
for layer in self.layers:
|
| 303 |
+
hidden = layer(hidden, positions)
|
| 304 |
+
if states is not None:
|
| 305 |
+
states.append(hidden)
|
| 306 |
+
return hidden, tuple(states) if states is not None else None
|
| 307 |
+
|
| 308 |
+
def forward(self, input_values, attention_mask=None, output_hidden_states=None, return_dict=None):
|
| 309 |
+
"""Return final frames, optionally all block states, and a frame mask.
|
| 310 |
+
|
| 311 |
+
Different valid waveform lengths are encoded separately so convolution
|
| 312 |
+
and global normalization never incorporate another sample's padding.
|
| 313 |
+
Outputs are zero-padded to the longest valid feature sequence.
|
| 314 |
+
"""
|
| 315 |
+
output_hidden_states = self.config.output_hidden_states if output_hidden_states is None else output_hidden_states
|
| 316 |
+
return_dict = self.config.use_return_dict if return_dict is None else return_dict
|
| 317 |
+
if input_values.ndim != 2 or not input_values.is_floating_point() or input_values.shape[0] == 0:
|
| 318 |
+
raise ValueError("input_values must be a nonempty floating-point tensor of shape [batch, samples].")
|
| 319 |
+
if input_values.shape[1] < self.config.minimum_input_samples:
|
| 320 |
+
raise ValueError(f"Each waveform must contain at least {self.config.minimum_input_samples} samples.")
|
| 321 |
+
if not torch.isfinite(input_values).all():
|
| 322 |
+
raise ValueError("input_values must contain only finite samples.")
|
| 323 |
+
batch, samples = input_values.shape
|
| 324 |
+
if attention_mask is None:
|
| 325 |
+
hidden, states = self._encode(input_values, output_hidden_states)
|
| 326 |
+
feature_mask = torch.ones(hidden.shape[:2], dtype=torch.bool, device=hidden.device)
|
| 327 |
+
else:
|
| 328 |
+
if attention_mask.shape != input_values.shape:
|
| 329 |
+
raise ValueError("attention_mask must have the same shape as input_values.")
|
| 330 |
+
attention_mask = attention_mask.to(device=input_values.device)
|
| 331 |
+
if not ((attention_mask == 0) | (attention_mask == 1)).all():
|
| 332 |
+
raise ValueError("attention_mask must contain only zeros and ones.")
|
| 333 |
+
mask = attention_mask.bool()
|
| 334 |
+
lengths = mask.sum(dim=1)
|
| 335 |
+
expected = torch.arange(samples, device=input_values.device)[None, :] < lengths[:, None]
|
| 336 |
+
if not torch.equal(mask, expected):
|
| 337 |
+
raise ValueError("attention_mask must be right padded: valid samples followed by padding.")
|
| 338 |
+
if (lengths < self.config.minimum_input_samples).any():
|
| 339 |
+
raise ValueError(f"Each waveform must contain at least {self.config.minimum_input_samples} valid samples.")
|
| 340 |
+
feature_lengths = self._get_feat_extract_output_lengths(lengths)
|
| 341 |
+
maximum = int(feature_lengths.max().item())
|
| 342 |
+
feature_mask = torch.arange(maximum, device=input_values.device)[None, :] < feature_lengths[:, None]
|
| 343 |
+
hidden, state_values = None, None
|
| 344 |
+
for length in torch.unique(lengths, sorted=True).tolist():
|
| 345 |
+
indices = torch.where(lengths == length)[0]
|
| 346 |
+
group_hidden, group_states = self._encode(input_values.index_select(0, indices)[:, :length], output_hidden_states)
|
| 347 |
+
padding = (0, 0, 0, maximum - group_hidden.shape[1])
|
| 348 |
+
if hidden is None:
|
| 349 |
+
hidden = group_hidden.new_zeros(batch, maximum, self.config.hidden_size)
|
| 350 |
+
if output_hidden_states:
|
| 351 |
+
state_values = [torch.zeros_like(hidden) for _ in self.layers]
|
| 352 |
+
hidden = hidden.index_copy(0, indices, F.pad(group_hidden, padding))
|
| 353 |
+
if state_values is not None:
|
| 354 |
+
for i, value in enumerate(group_states):
|
| 355 |
+
state_values[i] = state_values[i].index_copy(0, indices, F.pad(value, padding))
|
| 356 |
+
states = tuple(state_values) if state_values is not None else None
|
| 357 |
+
output = MERT2ModelOutput(last_hidden_state=hidden, hidden_states=states, feature_attention_mask=feature_mask)
|
| 358 |
+
return output if return_dict else output.to_tuple()
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
MERT2Model.register_for_auto_class("AutoModel")
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"feature_extractor_type": "Wav2Vec2FeatureExtractor",
|
| 3 |
+
"feature_size": 1,
|
| 4 |
+
"sampling_rate": 24000,
|
| 5 |
+
"padding_value": 0.0,
|
| 6 |
+
"padding_side": "right",
|
| 7 |
+
"return_attention_mask": true,
|
| 8 |
+
"do_normalize": false
|
| 9 |
+
}
|
weights_manifest.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"format": "safetensors",
|
| 3 |
+
"dtype": "float32",
|
| 4 |
+
"parameters": 632295808,
|
| 5 |
+
"state_tensors": 876,
|
| 6 |
+
"filename": "model.safetensors",
|
| 7 |
+
"sha256": "e6dd2ab187d6dd62b6521cd7d8f932e237acf0c5757745a7232082e28391350d",
|
| 8 |
+
"bytes": 2529812848
|
| 9 |
+
}
|