# Can someone give me a simple example on how to train Wav2Vec2 for audio frame classification?

**URL:** <https://discuss.huggingface.co/t/can-someone-give-me-a-simple-example-on-how-to-train-wav2vec2-for-audio-frame-classification/70002>\
**Category:** Models\
**Created:** [January 21, 2024, 8:46pm UTC](https://discuss.huggingface.co/t/can-someone-give-me-a-simple-example-on-how-to-train-wav2vec2-for-audio-frame-classification/70002 "2024-01-21T20:46:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![moritzsur](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@moritzsur](https://discuss.huggingface.co/u/moritzsur)\
**Post date:** [January 21, 2024, 8:46pm UTC](https://discuss.huggingface.co/t/can-someone-give-me-a-simple-example-on-how-to-train-wav2vec2-for-audio-frame-classification/70002/1 "2024-01-21T20:46:34Z")

</div>

Can someone give me a simple example on how to train [Wav2Vec2ForAudioFrameClassification](https://huggingface.co/docs/transformers/model_doc/wav2vec2#transformers.Wav2Vec2ForAudioFrameClassification)? 🙂  
The docs only supply an example for inference and I’m new to data science…

---

<div class="post-metadata">

**Author:** ![bnestor](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@bnestor](https://discuss.huggingface.co/u/bnestor)\
**Post date:** [January 7, 2025, 3:08am UTC](https://discuss.huggingface.co/t/can-someone-give-me-a-simple-example-on-how-to-train-wav2vec2-for-audio-frame-classification/70002/2 "2025-01-07T03:08:12Z")

</div>

The model has a expects the labels to only be 2d, regardless of the number of classes. For a binary problem, I prepared the labels as such:

```auto
check_labels = labels.long() # copy before modification.
labels = torch.nn.functional.one_hot(labels.long(), num_classes=2)

labels = labels.view(labels.shape[0], labels.shape[1]*labels.shape[2])

# this is the line used in the model.
num_classes=2
for i in range(len(check_labels)):
    check_against=labels[i]
    check_against = torch.argmax(check_against.view(-1, num_classes), axis=1).long()
    torch.testing.assert_close(check_labels[i], check_against, rtol=1e-5, atol=1e-5)

```
