Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/fairseq2/datasets/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ def create_reader(
self._name, split, builder.and_return(), gang, options
)

@staticmethod
def add_tokenization_pipeline(
builder: DataPipelineBuilder,
tokenizer: TextTokenizer,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add another arg here remove_unk to optionally remove all UNKs tokens from transcript. we should default this to False but it can be something that we experiment with.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, maybe we can log the number of UNKs (or % of num_unks/total_tokens within a sample/batch) in weights and biases? its useful for us to know if our dataset contains too many UNKs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, maybe we can log the number of UNKs (or % of num_unks/total_tokens within a sample/batch) in weights and biases? its useful for us to know if our dataset contains too many UNKs.

it's possible (requires a bit to propagate some metric bags to data reader) but for now we can just do in a adhoc analysis

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add another arg here remove_unk to optionally remove all UNKs tokens from transcript. we should default this to False but it can be something that we experiment with.

done !

) -> DataPipelineBuilder:
# Tokenize target text.
text_encoder = tokenizer.create_encoder()

# to avoid to tokenize empty text, we filter out them out first
builder = builder.filter(lambda x: bool(len(x["text"]) > 0))

builder.map(text_encoder, selector="text")

unk_idx = tokenizer.vocab_info.unk_idx

def empty_text(example: Dict[str, Any]) -> bool:
return bool((example["text"] != unk_idx).sum().item() > 0)
Comment thread
artemru marked this conversation as resolved.

builder = builder.filter(empty_text)

return builder

@staticmethod
def build_asr_main_pipeline(
builder: DataPipelineBuilder,
Expand All @@ -170,6 +192,9 @@ def build_asr_main_pipeline(
max_audio_len: int,
) -> DataPipelineBuilder:

# Tokenize target text.
builder = GenericAsrDataset.add_tokenization_pipeline(builder, tokenizer)

# Bucketize examples by audio length.
builder = GenericSpeechDataset.add_bucketing_pipeline(
builder,
Expand All @@ -188,10 +213,6 @@ def build_asr_main_pipeline(
builder, options, GenericSpeechDataset.rename_feature
)

# Tokenize target text.
text_encoder = tokenizer.create_encoder()
builder.map(text_encoder, selector="[*].text", num_parallel_calls=options.npc)

# Collate bucketed examples into a batch.
text_collate_opts = CollateOptionsOverride(
"text", pad_value=tokenizer.vocab_info.pad_idx
Expand Down
6 changes: 2 additions & 4 deletions src/fairseq2/datasets/asr_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def build_asr_main_pipeline(
builder = builder.shuffle(options.example_shuffle_window, seed=options.seed)
options.seed += 1

builder = GenericAsrDataset.add_tokenization_pipeline(builder, tokenizer)

builder = GenericSpeechDataset.add_bucketing_pipeline(
builder,
options,
Expand All @@ -150,10 +152,6 @@ def build_parquet_audio_text_reading(
builder, options, GenericSpeechDataset.rename_feature
)

# Tokenize target text.
text_encoder = tokenizer.create_encoder()
builder.map(text_encoder, selector="[*].text", num_parallel_calls=options.npc)

# Collate bucketed examples into a batch.
text_collate_opts = CollateOptionsOverride(
"text", pad_value=tokenizer.vocab_info.pad_idx
Expand Down
Loading