shivam-2211 commited on
Commit
e4d282f
·
verified ·
1 Parent(s): 0cad015

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +228 -0
README.md ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - wav2vec2
5
+ - audio-classification
6
+ - deepfake-detection
7
+ - safetensors
8
+ library_name: transformers
9
+ pipeline_tag: audio-classification
10
+ datasets:
11
+ - garystafford/deepfake-audio-detection
12
+ base_model: facebook/wav2vec2-large-xlsr-53
13
+ ---
14
+
15
+ # Voice Detection Model
16
+
17
+ Binary audio classifier — classifies speech as **FAKE** (AI-generated) or **REAL** (human).
18
+
19
+ Built by fine-tuning [`facebook/wav2vec2-large-xlsr-53`](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on the [`garystafford/deepfake-audio-detection`](https://huggingface.co/datasets/garystafford/deepfake-audio-detection) dataset.
20
+
21
+ ---
22
+
23
+ ## Model Details
24
+
25
+ | | |
26
+ |---|---|
27
+ | **Architecture** | `Wav2Vec2ForSequenceClassification` |
28
+ | **Base model** | `facebook/wav2vec2-large-xlsr-53` |
29
+ | **Parameters** | 315,701,634 (F32) |
30
+ | **File size** | 1.26 GB |
31
+ | **Format** | Safetensors |
32
+ | **Transformers** | `4.57.6` |
33
+
34
+ ### Labels
35
+
36
+ ```json
37
+ {
38
+ "id2label": { "0": "FAKE", "1": "REAL" },
39
+ "label2id": { "FAKE": 0, "REAL": 1 }
40
+ }
41
+ ```
42
+
43
+ | ID | Label | Meaning |
44
+ |---|---|---|
45
+ | `0` | **FAKE** | AI-generated / synthetic / deepfake |
46
+ | `1` | **REAL** | Authentic human speech |
47
+
48
+ ---
49
+
50
+ ## Architecture
51
+
52
+ ### Transformer Encoder
53
+
54
+ | | |
55
+ |---|---|
56
+ | Hidden size | 1024 |
57
+ | Intermediate size | 4096 |
58
+ | Layers | 24 |
59
+ | Attention heads | 16 |
60
+ | Activation | gelu |
61
+ | Stable layer norm | ✅ |
62
+ | Layer norm eps | 1e-05 |
63
+ | Layerdrop | 0.1 |
64
+
65
+ ### CNN Feature Extractor (7 layers)
66
+
67
+ | Layer | Channels | Kernel | Stride |
68
+ |:---:|:---:|:---:|:---:|
69
+ | 1 | 512 | 10 | 5 |
70
+ | 2 | 512 | 3 | 2 |
71
+ | 3 | 512 | 3 | 2 |
72
+ | 4 | 512 | 3 | 2 |
73
+ | 5 | 512 | 3 | 2 |
74
+ | 6 | 512 | 2 | 2 |
75
+ | 7 | 512 | 2 | 2 |
76
+
77
+ - Activation: `gelu` · Norm: `layer` · Bias: `true`
78
+ - Conv positional embeddings: 128, 16 groups
79
+ - Feature encoder was **frozen** during fine-tuning
80
+
81
+ ### TDNN Classifier Head
82
+
83
+ | Layer | Dim | Kernel | Dilation |
84
+ |:---:|:---:|:---:|:---:|
85
+ | 1 | 512 | 5 | 1 |
86
+ | 2 | 512 | 3 | 2 |
87
+ | 3 | 512 | 3 | 3 |
88
+ | 4 | 512 | 1 | 1 |
89
+ | 5 | 1500 | 1 | 1 |
90
+
91
+ - Classifier projection: 256
92
+ - X-vector output dim: 512
93
+
94
+ ### Regularization
95
+
96
+ | | |
97
+ |---|---|
98
+ | Attention dropout | 0.1 |
99
+ | Hidden dropout | 0.1 |
100
+ | Feature proj dropout | 0.1 |
101
+ | Activation dropout | 0.0 |
102
+ | Final dropout | 0.0 |
103
+ | SpecAugment | ✅ enabled |
104
+ | Time mask prob | 0.075 |
105
+ | Time mask length | 10 |
106
+
107
+ ---
108
+
109
+ ## Preprocessor
110
+
111
+ From `preprocessor_config.json`:
112
+
113
+ | | |
114
+ |---|---|
115
+ | Type | `Wav2Vec2FeatureExtractor` |
116
+ | Sampling rate | 16000 Hz |
117
+ | Feature size | 1 (mono) |
118
+ | Normalize | ✅ |
119
+ | Return attention mask | ✅ |
120
+ | Padding side | right |
121
+ | Padding value | 0 |
122
+
123
+ ---
124
+
125
+ ## Training
126
+
127
+ ### Dataset
128
+
129
+ [`garystafford/deepfake-audio-detection`](https://huggingface.co/datasets/garystafford/deepfake-audio-detection) — 1,866 samples total.
130
+
131
+ Group-aware defensive splits (speaker isolation):
132
+
133
+ | Split | Samples |
134
+ |---|---|
135
+ | Train | 1,467 |
136
+ | Validation | 206 |
137
+ | Test | 193 |
138
+
139
+ ### Hyperparameters
140
+
141
+ | | |
142
+ |---|---|
143
+ | Learning rate | 3e-5 |
144
+ | Batch size | 8 per device |
145
+ | Gradient accumulation | 2 (effective batch 16) |
146
+ | Max epochs | 10 |
147
+ | Early stopping patience | 3 (metric: F1) |
148
+ | Warmup ratio | 0.1 |
149
+ | Weight decay | 0.01 |
150
+ | Max grad norm | 1.0 |
151
+ | Precision | FP16 |
152
+ | Loss | Weighted CrossEntropy (class-balanced) |
153
+ | Seed | 42 |
154
+
155
+ ### Preprocessing
156
+
157
+ - Silence trimming (`librosa.effects.trim`, 30 dB threshold)
158
+ - Truncate/pad to 5.0s (80,000 samples at 16 kHz)
159
+ - Random crop during training, center crop during eval
160
+
161
+ ### Augmentation (training only)
162
+
163
+ | Transform | Range | Probability |
164
+ |---|---|---|
165
+ | Gaussian noise | 0.001–0.01 amplitude | 0.4 |
166
+ | Time stretch | 0.9–1.1× | 0.3 |
167
+ | Pitch shift | ±2 semitones | 0.3 |
168
+ | Gain | ±6 dB | 0.5 |
169
+
170
+ ### Infrastructure
171
+
172
+ | | |
173
+ |---|---|
174
+ | Platform | Google Colab |
175
+ | GPU | NVIDIA T4 |
176
+ | Python | 3.12 |
177
+
178
+ ---
179
+
180
+ ## Usage
181
+
182
+ ```python
183
+ import torch
184
+ import librosa
185
+ from transformers import Wav2Vec2ForSequenceClassification, Wav2Vec2FeatureExtractor
186
+
187
+ model_id = "shivam-2211/voice-detection-model"
188
+ extractor = Wav2Vec2FeatureExtractor.from_pretrained(model_id)
189
+ model = Wav2Vec2ForSequenceClassification.from_pretrained(model_id)
190
+ model.eval()
191
+
192
+ # Load audio at 16 kHz mono
193
+ audio, sr = librosa.load("sample.wav", sr=16000, mono=True)
194
+
195
+ inputs = extractor(audio, sampling_rate=16000, return_tensors="pt", padding=True)
196
+
197
+ with torch.no_grad():
198
+ logits = model(**inputs).logits
199
+ probs = torch.softmax(logits, dim=-1)
200
+ pred_id = torch.argmax(probs, dim=-1).item()
201
+ confidence = probs[0][pred_id].item()
202
+
203
+ label = model.config.id2label[pred_id]
204
+ print(f"{label} ({confidence:.2%})")
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Repository Files
210
+
211
+ | File | Description |
212
+ |---|---|
213
+ | `model.safetensors` | Model weights (1.26 GB) |
214
+ | `config.json` | Architecture and label config |
215
+ | `preprocessor_config.json` | Feature extractor settings |
216
+ | `training_args.bin` | Serialized training hyperparameters |
217
+
218
+ ---
219
+
220
+ ## Limitations
221
+
222
+ - Performance may degrade on heavily compressed, noisy, or very short audio.
223
+ - Newer voice synthesis methods may produce artifacts not represented in training data.
224
+ - Should not be used as sole evidence without expert review.
225
+
226
+ ## License
227
+
228
+ MIT