Views
No views yet

transformers == 4.40
torch
torchaudioAttributeError: '...Model' object has no attribute 'all_tied_weights_keys' (or similar) on from_pretrained, you're on an older cached copy of this repo's code — transformers versions 5.x call self.post_init()-dependent bookkeeping during loading that earlier revisions of this wrapper didn't set up. This has been fixed; clearing your local transformers_modules cache for this repo and re-downloading it again.1import torch
2import torchaudio
3from transformers import AutoModel
4
5model = AutoModel.from_pretrained("FaisaI/tadabur-embedding", trust_remote_code=True).eval()
6
7# --- Load audio (16 kHz mono) ---
8waveform, sr = torchaudio.load("recitation.wav")
9waveform = waveform.mean(dim=0, keepdim=True) # mono
10if sr != 16000:
11 waveform = torchaudio.functional.resample(waveform, sr, 16000)
12
13# --- Log-mel spectrogram (EAT preprocessing) ---
14waveform = waveform - waveform.mean()
15mel = torchaudio.compliance.kaldi.fbank(
16 waveform,
17 htk_compat=True,
18 sample_frequency=16000,
19 use_energy=False,
20 window_type="hanning",
21 num_mel_bins=128,
22 dither=0.0,
23 frame_shift=10,
24) # (n_frames, 128)
25
26# Pad or truncate to 1024 frames (= 10.24 s)
27target_length = 1024
28n_frames = mel.shape[0]
29if n_frames < target_length:
30 mel = torch.nn.functional.pad(mel, (0, 0, 0, target_length - n_frames))
31else:
32 mel = mel[:target_length]
33
34# Normalize with tadabur dataset statistics
35norm_mean, norm_std = -4.381, 3.628
36mel = (mel - norm_mean) / (norm_std * 2)
37mel = mel[None, None] # (1, 1, 1024, 128)
38
39# --- Extract embeddings ---
40with torch.no_grad():
41 semantic = model.semantic_embedding(mel) # (1, 384) L2-normalized, ayah content
42 speaker = model.speaker_embedding(mel) # (1, 128) L2-normalized, reciter identity
43
44 features = model.extract_features(mel) # (1, 513, 768) = CLS + 512 frame patches
45 frame_embeddings = features[:, 1:] # (1, 512, 768) frame-level (~50 Hz)semantic_embedding vectors with a dot product (they are L2-normalized, so this is cosine similarity). For reciter similarity, use speaker_embedding the same way. The raw encoder features from extract_features are best for frame-level temporal tasks and as input to downstream models.features[:, 1:]) preserve temporal order and can be used directly for alignment and localization tasks.norm_mean = -4.381, norm_std = 3.628) were computed on this dataset — use them (not the AudioSet defaults) when preprocessing.1@misc{tadabur-embedding,
2 title = {tadabur-embedding: audio embeddings for Quranic recitation},
3 author = {Faisal},
4 year = {2026},
5 url = {https://huggingface.co/FaisaI/tadabur-embedding}
6}