Skip to content

Commit 1cfb1e8

Browse files
Fix OmniASR CTC blank token ID (#51040)
* Fix OmniASR CTC blank token ID * remove unnecessary token ids --------- Co-authored-by: Eric B <ebezzam@gmail.com>
1 parent dd623c8 commit 1cfb1e8

4 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎src/transformers/models/omniasr_ctc/configuration_omniasr_ctc.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
@strict
2424
class OmniASRCTCConfig(PreTrainedConfig):
2525
r"""
26+
blank_token_id (`int`, *optional*, defaults to 0):
27+
The token ID of the blank symbol used by the CTC loss.
2628
ctc_loss_reduction (`str`, *optional*, defaults to `"mean"`):
2729
Specifies the reduction to apply to the output of `torch.nn.CTCLoss`. Only relevant when training an
2830
instance of [`OmniASRForCTC`].
@@ -59,9 +61,8 @@ class OmniASRCTCConfig(PreTrainedConfig):
5961
ctc_zero_infinity: bool = False
6062
initializer_range: float = 0.02
6163
audio_config: dict | PreTrainedConfig | None = None
62-
bos_token_id: int | None = 0
64+
blank_token_id: int = 0
6365
pad_token_id: int | None = 1
64-
eos_token_id: int | None = 2
6566

6667
def validate_architecture(self):
6768
"""Part of `@strict`-powered validation. Validates the architecture of the config."""

‎src/transformers/models/omniasr_ctc/convert_omniasr_ctc_to_hf.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ def convert_omniasr_ctc_checkpoint(model_card, repo_id=None, bfloat16=False):
6464
audio_config=convert_audio_config(original_config),
6565
vocab_size=original_config.target_vocab_size,
6666
pad_token_id=pipeline.tokenizer.vocab_info.pad_idx,
67-
bos_token_id=pipeline.tokenizer.vocab_info.bos_idx,
68-
eos_token_id=pipeline.tokenizer.vocab_info.eos_idx,
6967
)
7068
hf_model = OmniASRForCTC(config)
7169
hf_model.to(device).to(dtype)
@@ -84,8 +82,8 @@ def convert_omniasr_ctc_checkpoint(model_card, repo_id=None, bfloat16=False):
8482

8583
# 4) Prepare processor (feature extraction and tokenizer)
8684
tokenizer_path = download_tokenizer(model_card)
87-
# The CTC loss does not depend on the padding side. `ParakeetTokenizer` decodes CTC outputs, collapsing repeats and
88-
# dropping the pad token, which is the CTC blank.
85+
# The CTC loss does not depend on the padding side. `ParakeetTokenizer` collapses repeats when decoding; the CTC
86+
# blank `<s>` (id 0) is a special token, so it is removed with `skip_special_tokens=True`.
8987
tokenizer = convert_tokenizer(tokenizer_path, padding_side="right", tokenizer_class=ParakeetTokenizer)
9088
# Saved with the tokenizer, so that `_merge_kwargs` uses them as processor defaults.
9189
tokenizer.init_kwargs["padding"] = True

‎src/transformers/models/omniasr_ctc/modeling_omniasr_ctc.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def forward(
183183
logits=logits,
184184
labels=labels,
185185
logit_lengths=encoder_lengths,
186-
blank_token_id=self.config.pad_token_id,
186+
blank_token_id=self.config.blank_token_id,
187187
reduction=self.config.ctc_loss_reduction,
188188
zero_infinity=self.config.ctc_zero_infinity,
189189
**kwargs,

‎src/transformers/models/omniasr_ctc/modular_omniasr_ctc.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def forward(
130130
logits=logits,
131131
labels=labels,
132132
logit_lengths=encoder_lengths,
133-
blank_token_id=self.config.pad_token_id,
133+
blank_token_id=self.config.blank_token_id,
134134
reduction=self.config.ctc_loss_reduction,
135135
zero_infinity=self.config.ctc_zero_infinity,
136136
**kwargs,

0 commit comments

Comments
 (0)