Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions maeb-results
Submodule maeb-results added at 8ecd55
19 changes: 12 additions & 7 deletions mteb/models/model_implementations/wav2clip_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ def __init__(
self.sampling_rate = 16_000
self.max_audio_length_s = max_audio_length_s

# text side (CLIP)
self.clip = CLIPModel.from_pretrained(model_name, revision=revision).to(device)
# text side (CLIP) - we use the standard OpenAI CLIP model as mentioned in paper
# Wav2Clip aligns audio embeddings to CLIP's embedding space using this specific model
clip_model_name = "openai/clip-vit-base-patch32"
clip_revision = "3d74acf9a28c67741b2f4f2ea7635f0aaf6f0268"
self.clip = CLIPModel.from_pretrained(
clip_model_name, revision=clip_revision, device_map=device
)
self.clip.eval()
self.clip_processor = CLIPProcessor.from_pretrained(
model_name, revision=revision
clip_model_name, revision=clip_revision
)

def get_audio_embeddings(
Expand Down Expand Up @@ -71,7 +76,7 @@ def get_audio_embeddings(
orig_freq=sr, new_freq=self.sampling_rate
)
array = resampler(array)
audio_arrays.append(array.numpy())
audio_arrays.append(array) # Keep as tensor

max_length = max(wav.shape[-1] for wav in audio_arrays)
padded_wavs = []
Expand All @@ -84,8 +89,8 @@ def get_audio_embeddings(
padded_wav = wav
padded_wavs.append(padded_wav)

# Stack into batch tensor
batch_tensor = torch.stack(padded_wavs).cpu().detach().numpy()
# Stack into batch array and convert to numpy for embed_audio
batch_tensor = torch.stack(padded_wavs).numpy()

# Process entire batch at once
batch_embeds = self.embed_audio(batch_tensor, self.audio_model)
Expand Down Expand Up @@ -159,7 +164,7 @@ def encode(
loader=Wav2ClipZeroShotWrapper,
name="lyrebird/wav2clip",
languages=["eng-Latn"],
revision="N/A",
revision="no_revision",
release_date="2022-03-15",
modalities=["audio", "text"],
n_parameters=163_000_000, # wav2clip: 11.7M + CLIP: 151.3M ≈ 163M
Expand Down
Loading