Views
No views yet
forwarder1121/voice-based-stress-recognitionStudentNet distilled from a multimodal TeacherNet trained on the StressID dataset.This model expects 512-dimensional embeddings generated by fairseq’s Wav2Vec2 (base) model
train split for Teacher training; test split held out for final evaluation1loss = CE(student_logits, labels) \
2 + α * MSE(student_features, teacher_features)
3torchaudio.pipelines.WAV2VEC2_BASE).wav2vec_large.pt in the root directory of this repository.wav2vec_large.pt with torchaudio/fairseq,StudentNet.models.py) and the weights from the Hub, then runs inference via the Hugging Face Transformers API—all in one script:1from huggingface_hub import hf_hub_download
2import importlib.util
3from transformers import AutoConfig, AutoModelForAudioClassification
4import torch
5import torch.nn.functional as F
6
7def main():
8 repo = "forwarder1121/voice-based-stress-recognition"
9
10 # 1) Dynamically download & load the custom models.py
11 code_path = hf_hub_download(repo_id=repo, filename="models.py")
12 spec = importlib.util.spec_from_file_location("models", code_path)
13 models = importlib.util.module_from_spec(spec)
14 spec.loader.exec_module(models)
15 # now we have models.StudentForAudioClassification and models.StressConfig
16
17 # 2) Load config & model via Transformers (with remote code trust)
18 cfg = AutoConfig.from_pretrained(repo, trust_remote_code=True)
19 model = AutoModelForAudioClassification.from_pretrained(
20 repo,
21 trust_remote_code=True,
22 torch_dtype="auto"
23 )
24 model.eval()
25
26 # 3) Prepare a dummy W2V embedding for testing
27 # In real use, replace this with your (1, 512) pre-computed W2V tensor.
28 batch_size = 1
29 DIM_W2V = 512
30 x_w2v = torch.randn(batch_size, DIM_W2V, dtype=next(model.parameters()).dtype)
31
32 # 4) Inference
33 with torch.no_grad():
34 outputs = model(x_w2v) # SequenceClassifierOutput
35 probs = F.softmax(outputs.logits, dim=-1)
36
37 print(f"Not stressed: {probs[0,0]*100:.1f}%")
38 print(f"Stressed : {probs[0,1]*100:.1f}%")
39
40if __name__ == "__main__":
41 main()1@inproceedings{your2025voice,
2 title={Lightweight Audio-Embedding-Based Stress Recognition via Multimodal Knowledge Distillation},
3 author={Your Name and …},
4 booktitle={Conference/Journal},
5 year={2025}
6}