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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: cc-by-nc-sa-4.0
|
| 3 |
+
metrics:
|
| 4 |
+
- accuracy
|
| 5 |
+
- precision
|
| 6 |
+
- recall
|
| 7 |
+
- f1
|
| 8 |
+
- roc_auc
|
| 9 |
+
base_model:
|
| 10 |
+
- facebook/wav2vec2-xls-r-2b
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# π **SSL-AntiDeepfake**
|
| 14 |
+
|
| 15 |
+
The **SSL-AntiDeepfake** project provides a series of powerful self-supervised learning (SSL) models crafted to **detect deepfake speech** with state-of-the-art accuracy.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# π€ Available Models
|
| 19 |
+
|
| 20 |
+
All models are released on Hugging Face π€ with two variants:
|
| 21 |
+
- **Default**: Trained with data augmentation
|
| 22 |
+
- **NDA** (No Data Augmentation): Trained without data augmentation
|
| 23 |
+
|
| 24 |
+
| Model | Variants |
|
| 25 |
+
|-----------------------------------------------|--------------------|
|
| 26 |
+
| XLS-R-2B-AntiDeepfake | [Default](https://huggingface.co/nii-yamagishilab/xls-r-2b-anti-deepfake), [NDA](https://huggingface.co/nii-yamagishilab/xls-r-2b-anti-deepfake-nda)
|
| 27 |
+
| XLS-R-1B-AntiDeepfake | [Default](https://huggingface.co/nii-yamagishilab/xls-r-1b-anti-deepfake), [NDA](https://huggingface.co/nii-yamagishilab/xls-r-1b-anti-deepfake-nda)
|
| 28 |
+
| MMS-1B-AntiDeepfake | [Default](https://huggingface.co/nii-yamagishilab/mms-1b-anti-deepfake), [NDA](https://huggingface.co/nii-yamagishilab/mms-1b-anti-deepfake-nda)
|
| 29 |
+
| MMS-300M-AntiDeepfake | [Default](https://huggingface.co/nii-yamagishilab/mms-300m-anti-deepfake), [NDA](https://huggingface.co/nii-yamagishilab/mms-300m-anti-deepfake-nda)
|
| 30 |
+
| Wav2Vec2-Large-AntiDeepfake | [Default](https://huggingface.co/nii-yamagishilab/wav2vec-large-anti-deepfake), [NDA](https://huggingface.co/nii-yamagishilab/wav2vec-large-anti-deepfake-nda)
|
| 31 |
+
| Wav2Vec2-Small-AntiDeepfake | [Default](https://huggingface.co/nii-yamagishilab/wav2vec-small-anti-deepfake), [NDA](https://huggingface.co/nii-yamagishilab/wav2vec-small-anti-deepfake-nda)
|
| 32 |
+
| Hubert-Extra-Large-AntiDeepfake | [Default](https://huggingface.co/nii-yamagishilab/hubert-xlarge-anti-deepfake), [NDA](https://huggingface.co/nii-yamagishilab/hubert-xlarge-anti-deepfake-nda)
|
| 33 |
+
|
| 34 |
+
# π οΈ Training Code & Repository
|
| 35 |
+
Explore training scripts, config files, and evaluation utilities in our GitHub repository:π [SSL-AntiDeepfake GitHub Repository](https://github.com/nii-yamagishilab/Ultra-SSL-AntiDeepfake)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# π **Model Spotlight: XLS-R-2B-AntiDeepfake-NDA**
|
| 39 |
+
|
| 40 |
+
# π **Key Features**
|
| 41 |
+
- **Architecture**: Wav2Vec 2.0 - [`facebook/wav2vec2-xls-r-2b`](https://huggingface.co/facebook/wav2vec2-xls-r-2b) π.
|
| 42 |
+
- **Input**: 16kHz sampled speech with arbitrary length ποΈ.
|
| 43 |
+
- **Output**: Binary classification score (<Fake score π΄ , Real score π’>).
|
| 44 |
+
- **Training Dataset**: Totally 18k hours of fake speech and 56k hours of real speech.
|
| 45 |
+
|
| 46 |
+
# ποΈ **Architecture**
|
| 47 |
+
- **Front-end Feature Extractor**: XLS-R-2B.
|
| 48 |
+
- **Back-end Classifier**: A fully connected layer.
|
| 49 |
+
|
| 50 |
+
# βοΈ **Training Details**
|
| 51 |
+
- **Optimizer**: AdamW with a learning rate of `1e-7`.
|
| 52 |
+
- **Batch Size**: Dynamic Batching, maximum length per batch is set to 50 seconds.
|
| 53 |
+
- **Data Augmentation**: None
|
| 54 |
+
- **Loss Function**: Cross-Entropy Loss.
|
| 55 |
+
- **Evaluation Metrics**: Equal Error Rate (EER), ROC AUC, Accuracy, Precision, Recall, F1 Score.
|
| 56 |
+
|
| 57 |
+
# π **Inference with PyTorch**
|
| 58 |
+
|
| 59 |
+
β οΈ **Important:**
|
| 60 |
+
To run inference with this model, you need to install a specific version of `fairseq` and make manual code modifications. For detailed instructions, please refer to the installation guide in our [GitHub repository](https://github.com/nii-yamagishilab/Ultra-SSL-AntiDeepfake).
|
| 61 |
+
|
| 62 |
+
β
**Easier Alternatives:**
|
| 63 |
+
We recommend these models for plug-and-play inference:
|
| 64 |
+
- [MMS-300M-AntiDeepfake](https://huggingface.co/nii-yamagishilab/mms-300m-anti-deepfake)
|
| 65 |
+
- [MMS-1B-AntiDeepfake](https://huggingface.co/nii-yamagishilab/mms-1b-anti-deepfake)
|
| 66 |
+
|
| 67 |
+
π¦ Dependencies after installing fairseq:
|
| 68 |
+
```
|
| 69 |
+
pip install huggingface-hub safetensors soundfile
|
| 70 |
+
(pip install huggingface-hub==0.31.1 safetensors==0.5.3 soundfile==0.13.1)
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
π Inference:
|
| 74 |
+
```python
|
| 75 |
+
import os
|
| 76 |
+
import urllib.request
|
| 77 |
+
import torch
|
| 78 |
+
import torchaudio
|
| 79 |
+
import fairseq
|
| 80 |
+
from huggingface_hub import PyTorchModelHubMixin
|
| 81 |
+
|
| 82 |
+
# === Detect all audio files in a specified folder ===
|
| 83 |
+
folder_path = "/path/to/folder/contains/wavs/"
|
| 84 |
+
audio_formats = (".mp3", ".wav", ".flac", ".m4a")
|
| 85 |
+
|
| 86 |
+
# === Download Fairseq checkpoint if not present ===
|
| 87 |
+
# The downloaded checkpoint is used for building front-end architecture,
|
| 88 |
+
# its weights will be replaced by the model.safetensors file in this repo.
|
| 89 |
+
ssl_path = "xlsr2_2B_1000k.pt"
|
| 90 |
+
ssl_url = "https://dl.fbaipublicfiles.com/fairseq/wav2vec/xlsr2_2B_1000k.pt"
|
| 91 |
+
|
| 92 |
+
if not os.path.exists(ssl_path):
|
| 93 |
+
print(f"Downloading checkpoint to {ssl_path}...")
|
| 94 |
+
urllib.request.urlretrieve(ssl_url, ssl_path)
|
| 95 |
+
print("Download complete.")
|
| 96 |
+
else:
|
| 97 |
+
print(f"{ssl_path} already exists. Skipping download.")
|
| 98 |
+
|
| 99 |
+
# === Wrapper for the SSL model ===
|
| 100 |
+
class SSLModel(torch.nn.Module):
|
| 101 |
+
def __init__(self):
|
| 102 |
+
super().__init__()
|
| 103 |
+
# The downloaded .pt file is used here
|
| 104 |
+
model, _, _ = fairseq.checkpoint_utils.load_model_ensemble_and_task([ssl_path])
|
| 105 |
+
self.model = model[0]
|
| 106 |
+
|
| 107 |
+
def extract_feat(self, input_data):
|
| 108 |
+
# If input has shape (B, T, 1), squeeze the last dim
|
| 109 |
+
if input_data.ndim == 3:
|
| 110 |
+
input_data = input_data[:, :, 0]
|
| 111 |
+
|
| 112 |
+
# Extract features
|
| 113 |
+
with torch.no_grad():
|
| 114 |
+
features = self.model(input_data, mask=False, features_only=True)['x']
|
| 115 |
+
return features
|
| 116 |
+
|
| 117 |
+
# === Function for reading and pre-processing waveforms ===
|
| 118 |
+
def load_wav_and_preprocess(wav_path, target_sr=16000):
|
| 119 |
+
# Load audio file
|
| 120 |
+
wav, sr = torchaudio.load(wav_path)
|
| 121 |
+
# Convert to mono if stereo
|
| 122 |
+
wav = wav.mean(dim=0)
|
| 123 |
+
# Resample to target sampling rate
|
| 124 |
+
wav = torchaudio.functional.resample(wav, sr, new_freq=target_sr)
|
| 125 |
+
# Normalize waveform
|
| 126 |
+
with torch.no_grad():
|
| 127 |
+
wav = torch.nn.functional.layer_norm(wav, wav.shape)
|
| 128 |
+
# Add batch dimension and return
|
| 129 |
+
return wav.unsqueeze(0)
|
| 130 |
+
|
| 131 |
+
# === The actual deepfake detection model using SSL frontend + FC backend ===
|
| 132 |
+
class DeepfakeDetector(torch.nn.Module, PyTorchModelHubMixin):
|
| 133 |
+
def __init__(self):
|
| 134 |
+
super().__init__()
|
| 135 |
+
self.ssl_orig_output_dim = 1920
|
| 136 |
+
self.num_classes = 2
|
| 137 |
+
|
| 138 |
+
# Frontend: SSL model
|
| 139 |
+
self.m_ssl = SSLModel()
|
| 140 |
+
|
| 141 |
+
# Backend: Pooling + Classification
|
| 142 |
+
self.adap_pool1d = torch.nn.AdaptiveAvgPool1d(output_size=1)
|
| 143 |
+
self.proj_fc = torch.nn.Linear(
|
| 144 |
+
in_features=self.ssl_orig_output_dim,
|
| 145 |
+
out_features=self.num_classes,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
def forward(self, wav):
|
| 149 |
+
emb = self.m_ssl.extract_feat(wav) # [B, T, D]
|
| 150 |
+
emb = emb.transpose(1, 2) # [B, D, T]
|
| 151 |
+
pooled_emb = self.adap_pool1d(emb) # [B, D, 1]
|
| 152 |
+
pooled_emb = pooled_emb.squeeze(-1) # [B, D]
|
| 153 |
+
logits = self.proj_fc(pooled_emb) # [B, 2]
|
| 154 |
+
return logits
|
| 155 |
+
|
| 156 |
+
# === Load AntiDeepfake model from Hugging Face===
|
| 157 |
+
model = DeepfakeDetector.from_pretrained("nii-yamagishilab/xls-r-2b-anti-deepfake-nda")
|
| 158 |
+
model.eval()
|
| 159 |
+
|
| 160 |
+
# === Inference on a folder of audio files ===
|
| 161 |
+
results = []
|
| 162 |
+
for root, _, files in os.walk(folder_path):
|
| 163 |
+
for file in files:
|
| 164 |
+
if file.lower().endswith(audio_formats):
|
| 165 |
+
input_path = os.path.join(root, file)
|
| 166 |
+
with torch.no_grad():
|
| 167 |
+
wav = load_wav_and_preprocess(input_path)
|
| 168 |
+
logits = model(wav)
|
| 169 |
+
probs = torch.nn.functional.softmax(logits, dim=1)
|
| 170 |
+
results.append((file, probs.cpu().numpy()[0]))
|
| 171 |
+
|
| 172 |
+
# Sort results alphabetically by filename
|
| 173 |
+
results.sort(key=lambda x: x[0])
|
| 174 |
+
|
| 175 |
+
# Print formatted results
|
| 176 |
+
print("\n=== Deepfake Detection Results ===")
|
| 177 |
+
for file_name, prob in results:
|
| 178 |
+
print(f"{file_name}: real prob = {prob[1]:.3f}, fake prob = {prob[0]:.3f}")
|
| 179 |
+
```
|
| 180 |
+
# π **Performance Metrics**
|
| 181 |
+
Results shown below can be reproduced using scripts provided in our [GitHub repository](https://github.com/nii-yamagishilab/Ultra-SSL-AntiDeepfake).
|
| 182 |
+
|
| 183 |
+
| Test Database | ROC AUC | Accuracy | Precision | Recall | F1-score | FPR | FNR | EER (%) @ Threshold |
|
| 184 |
+
|---------------------|---------|----------|-----------|--------|----------|-------|-------|----------------------|
|
| 185 |
+
| ADD2023 | 0.983 | 0.947 | 0.957 | 0.972 | 0.964 | 0.124 | 0.028 | 6.84 @ 0.9105 |
|
| 186 |
+
| DeepVoice | 0.997 | 0.917 | 0.597 | 0.991 | 0.746 | 0.094 | 0.009 | 2.63 @ 0.9801 |
|
| 187 |
+
| FakeOrReal | 0.999 | 0.975 | 0.996 | 0.953 | 0.974 | 0.003 | 0.047 | 1.18 @ 0.1514 |
|
| 188 |
+
| FakeOrReal-norm | 0.999 | 0.979 | 0.966 | 0.993 | 0.979 | 0.033 | 0.007 | 1.73 @ 0.7434 |
|
| 189 |
+
| In-the-Wild | 0.999 | 0.985 | 0.993 | 0.983 | 0.988 | 0.011 | 0.017 | 1.31 @ 0.3748 |
|
| 190 |
+
| WildSVDD-TEST_A | 0.762 | 0.679 | 0.622 | 0.935 | 0.747 | 0.586 | 0.065 | 30.93 @ 0.9925 |
|
| 191 |
+
| WildSVDD-TEST_B | 0.718 | 0.714 | 0.754 | 0.846 | 0.797 | 0.546 | 0.154 | 36.11 @ 0.9838 |
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
# **Training Set**
|
| 196 |
+
Below is a breakdown of the training set used for fine-tuning.
|
| 197 |
+
|
| 198 |
+
| π Database | π Language | β
Genuine (hrs) | β Fake (hrs) |
|
| 199 |
+
|----------------------|------------------|----------------|-------------|
|
| 200 |
+
| AISHELL3 | zh | 85.62 | 0 |
|
| 201 |
+
| ASVspoof2019-LA | en | 11.85 | 97.80 |
|
| 202 |
+
| ASVspoof2021-LA | en | 16.40 | 116.10 |
|
| 203 |
+
| ASVspoof2021-DF | en | 20.73 | 487.00 |
|
| 204 |
+
| ASVspoof5 | en | 413.49 | 1808.48 |
|
| 205 |
+
| CFAD | zh | 171.25 | 224.55 |
|
| 206 |
+
| CNCeleb2 | zh | 1084.34 | 0 |
|
| 207 |
+
| Codecfake | en, zh | 129.66 | 808.32 |
|
| 208 |
+
| CodecFake | en | 0 | 660.92 |
|
| 209 |
+
| CVoiceFake | en, fr, de, it, zh| 315.14 | 1561.16 |
|
| 210 |
+
| DECRO | en, zh | 35.18 | 102.44 |
|
| 211 |
+
| DFADD | en | 41.62 | 66.01 |
|
| 212 |
+
| Diffuse or Confuse | en | 0 | 231.66 |
|
| 213 |
+
| DiffSSD | en | 0 | 139.73 |
|
| 214 |
+
| DSD | en, ja, ko | 100.98 | 60.23 |
|
| 215 |
+
| FLEURS | 102 languages | 1388.97 | 0 |
|
| 216 |
+
| FLEURS-R | 102 languages | 0 | 1238.83 |
|
| 217 |
+
| HABLA | es | 35.56 | 87.83 |
|
| 218 |
+
| LibriTTS | en | 585.83 | 0 |
|
| 219 |
+
| LibriTTS-R | en | 0 | 583.15 |
|
| 220 |
+
| LibriTTS-Vocoded | en | 0 | 2345.14 |
|
| 221 |
+
| LJSpeech | en | 23.92 | 0 |
|
| 222 |
+
| MLADD | 38 languages | 0 | 377.96 |
|
| 223 |
+
| MLS | 8 languages | 50558.11 | 0 |
|
| 224 |
+
| SpoofCeleb | Multilingual | 173.00 | 1916.20 |
|
| 225 |
+
| VoiceMOS | en | 0 | 448.44 |
|
| 226 |
+
| VoxCeleb2 | Multilingual | 1179.62 | 0 |
|
| 227 |
+
| VoxCeleb2-Vocoded | Multilingual | 0 | 4721.46 |
|
| 228 |
+
| WaveFake | en, ja | 0 | 198.65 |
|
| 229 |
+
| Train Set | Over 100 languages| 56370.00 | 18280.00 |
|
| 230 |
+
|
| 231 |
+
# **Attribution**
|
| 232 |
+
All SSL-AntiDeepfake models were developed by [Yamagishi Lab](https://yamagishilab.jp/) at the National Institute of Informatics (NII), Japan.
|
| 233 |
+
|
| 234 |
+
All model weights are the intellectual property of NII and are made available for research and educational purposes under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.
|
| 235 |
+
|
| 236 |
+
# **Acknowledgments**
|
| 237 |
+
This project is based on results obtained from project JPNP22007, commissioned by the New Energy and Industrial Technology Development Organization (NEDO).
|
| 238 |
+
|
| 239 |
+
It is also partially supported by the following grants from the Japan Science and Technology Agency (JST):
|
| 240 |
+
- AIP Acceleration Research (Grant No. JPMJCR24U3)
|
| 241 |
+
- CREST (Grant No. JPMJCR20D3)
|
| 242 |
+
- PRESTO (Grant No. JPMJPR23P9)
|