Create README.md
#2
by
ybelkada
- opened
README.md
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
# Model card for CLAP
|
5 |
+
|
6 |
+
Model card for CLAP: Contrastive Language-Audio Pretraining
|
7 |
+
|
8 |
+
![clap_image](https://s3.amazonaws.com/moonup/production/uploads/1678811100805-62441d1d9fdefb55a0b7d12c.png)
|
9 |
+
|
10 |
+
|
11 |
+
# Table of Contents
|
12 |
+
|
13 |
+
0. [TL;DR](#TL;DR)
|
14 |
+
1. [Model Details](#model-details)
|
15 |
+
2. [Usage](#usage)
|
16 |
+
3. [Uses](#uses)
|
17 |
+
4. [Citation](#citation)
|
18 |
+
|
19 |
+
# TL;DR
|
20 |
+
|
21 |
+
The abstract of the paper states that:
|
22 |
+
|
23 |
+
> Contrastive learning has shown remarkable success in the field of multimodal representation learning. In this paper, we propose a pipeline of contrastive language-audio pretraining to develop an audio representation by combining audio data with natural language descriptions. To accomplish this target, we first release LAION-Audio-630K, a large collection of 633,526 audio-text pairs from different data sources. Second, we construct a contrastive language-audio pretraining model by considering different audio encoders and text encoders. We incorporate the feature fusion mechanism and keyword-to-caption augmentation into the model design to further enable the model to process audio inputs of variable lengths and enhance the performance. Third, we perform comprehensive experiments to evaluate our model across three tasks: text-to-audio retrieval, zero-shot audio classification, and supervised audio classification. The results demonstrate that our model achieves superior performance in text-to-audio retrieval task. In audio classification tasks, the model achieves state-of-the-art performance in the zero-shot setting and is able to obtain performance comparable to models' results in the non-zero-shot setting. LAION-Audio-630K and the proposed model are both available to the public.
|
24 |
+
|
25 |
+
|
26 |
+
# Usage
|
27 |
+
|
28 |
+
You can use this model for zero shot audio classification or extracting audio and/or textual features.
|
29 |
+
|
30 |
+
# Uses
|
31 |
+
|
32 |
+
## Perform zero-shot audio classification
|
33 |
+
|
34 |
+
### Using `pipeline`
|
35 |
+
|
36 |
+
```python
|
37 |
+
from datasets import load_dataset
|
38 |
+
from transformers import pipeline
|
39 |
+
|
40 |
+
dataset = load_dataset("ashraq/esc50")
|
41 |
+
audio = dataset["train"]["audio"][-1]["array"]
|
42 |
+
|
43 |
+
audio_classifier = pipeline(task="zero-shot-audio-classification", model="laion/clap-htsat-fused")
|
44 |
+
output = audio_classifier(audio, candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"])
|
45 |
+
print(output)
|
46 |
+
>>> [{"score": 0.999, "label": "Sound of a dog"}, {"score": 0.001, "label": "Sound of vaccum cleaner"}]
|
47 |
+
```
|
48 |
+
|
49 |
+
## Run the model:
|
50 |
+
|
51 |
+
You can also get the audio and text embeddings using `ClapModel`
|
52 |
+
|
53 |
+
### Run the model on CPU:
|
54 |
+
|
55 |
+
```python
|
56 |
+
from datasets import load_dataset
|
57 |
+
from transformers import ClapModel, ClapProcessor
|
58 |
+
|
59 |
+
librispeech_dummy = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
60 |
+
audio_sample = librispeech_dummy[0]
|
61 |
+
|
62 |
+
model = ClapModel.from_pretrained("laion/clap-htsat-fused")
|
63 |
+
processor = ClapProcessor.from_pretrained("laion/clap-htsat-fused")
|
64 |
+
|
65 |
+
inputs = processor(audios=audio_sample["audio"]["array"], return_tensors="pt")
|
66 |
+
audio_embed = model.get_audio_features(**inputs)
|
67 |
+
```
|
68 |
+
|
69 |
+
### Run the model on GPU:
|
70 |
+
|
71 |
+
```python
|
72 |
+
from datasets import load_dataset
|
73 |
+
from transformers import ClapModel, ClapProcessor
|
74 |
+
|
75 |
+
librispeech_dummy = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
76 |
+
audio_sample = librispeech_dummy[0]
|
77 |
+
|
78 |
+
model = ClapModel.from_pretrained("laion/clap-htsat-fused").to(0)
|
79 |
+
processor = ClapProcessor.from_pretrained("laion/clap-htsat-fused")
|
80 |
+
|
81 |
+
inputs = processor(audios=audio_sample["audio"]["array"], return_tensors="pt").to(0)
|
82 |
+
audio_embed = model.get_audio_features(**inputs)
|
83 |
+
```
|
84 |
+
|
85 |
+
|
86 |
+
# Citation
|
87 |
+
|
88 |
+
If you are using this model for your work, please consider citing the original paper:
|
89 |
+
```
|
90 |
+
@misc{https://doi.org/10.48550/arxiv.2211.06687,
|
91 |
+
doi = {10.48550/ARXIV.2211.06687},
|
92 |
+
|
93 |
+
url = {https://arxiv.org/abs/2211.06687},
|
94 |
+
|
95 |
+
author = {Wu, Yusong and Chen, Ke and Zhang, Tianyu and Hui, Yuchen and Berg-Kirkpatrick, Taylor and Dubnov, Shlomo},
|
96 |
+
|
97 |
+
keywords = {Sound (cs.SD), Audio and Speech Processing (eess.AS), FOS: Computer and information sciences, FOS: Computer and information sciences, FOS: Electrical engineering, electronic engineering, information engineering, FOS: Electrical engineering, electronic engineering, information engineering},
|
98 |
+
|
99 |
+
title = {Large-scale Contrastive Language-Audio Pretraining with Feature Fusion and Keyword-to-Caption Augmentation},
|
100 |
+
|
101 |
+
publisher = {arXiv},
|
102 |
+
|
103 |
+
year = {2022},
|
104 |
+
|
105 |
+
copyright = {Creative Commons Attribution 4.0 International}
|
106 |
+
}
|
107 |
+
```
|