huggingface / huggingface/audio-transformers-course

Error in DataCollatorSpeechSeq2SeqWithPadding (Unit 5)

Open
#85 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
MDX
Stars
521
Forks
155
Avg merge
6m
Merged PRs (30d)
1

Description

In the unit 5 of the audio course, the following code is used:

```python
class DataCollatorSpeechSeq2SeqWithPadding:
processor: Any

def __call__(
self, features: List[Dict[str, Union[List[int], torch.Tensor]]]
) -> Dict[str, torch.Tensor]:
# split inputs and labels since they have to be of different lengths and need different padding methods
# first treat the audio inputs by simply returning torch tensors
input_features = [
{"input_features": feature["input_features"][0]} for feature in features
]
batch = self.processor.feature_extractor.pad(input_features, return_tensors="pt")

# get the tokenized label sequences
label_features = [{"input_ids": feature["labels"]} for feature in features]
# pad the labels to max length
labels_batch = self.processor.tokenizer.pad(label_features, return_tensors="pt")

# replace padding with -100 to ignore loss correctly
labels = labels_batch["input_ids"].masked_fill(
labels_batch.attention_mask.ne(1), -100
)

# if bos token is appended in previous tokenization step,
# cut bos token here as it's append later anyways
if (labels[:, 0] == self.processor.tokenizer.bos_token_id).all().cpu().item():
labels = labels[:, 1:]

batch["labels"] = labels

return batch
```

However, according to the following [issue](https://github.com/huggingface/transformers/issues/24342), `bos_token_id` shouldn't be used (@ArthurZucker). In my opinion, this should be replaced with `self.processor.tokenizer.convert_tokens_to_ids("<|startoftranscript|>")` or with `model.config.decoder_start_token_id`. What do you think?

Note if this is true, then there would be a similar error in @sanchit-gandhi's [fine-tuning tutorial](https://huggingface.co/blog/fine-tune-whisper) too.

Thanks for your attention.

Regards,
Tony

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Unit 5 DataCollatorSpeechSeq2SeqWithPadding snippet and read the linked Transformers issue about bos_token_id. Compare the course code with the linked fine-tuning tutorial, then determine which token ID guidance is correct. Done means the affected course material and any matching tutorial guidance are consistent and the ambiguity is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
documentation, machine-learning
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.