|
8 | 8 |
|
9 | 9 | from abc import ABC, abstractmethod |
10 | 10 | from functools import partial |
11 | | -from typing import Any, Dict, Final, Tuple, cast |
12 | | - |
13 | | -from typing_extensions import override |
| 11 | +from typing import Any, cast, Dict, Final, Tuple |
14 | 12 |
|
15 | 13 | from fairseq2.data import ( |
16 | 14 | CollateOptionsOverride, |
17 | 15 | Collater, |
18 | 16 | DataPipeline, |
19 | 17 | DataPipelineBuilder, |
20 | | - SequenceData, |
21 | 18 | read_sequence, |
| 19 | + SequenceData, |
22 | 20 | ) |
23 | | -from fairseq2.data.text import StrSplitter, read_text |
| 21 | +from fairseq2.data.text import read_text, StrSplitter |
24 | 22 | from fairseq2.data.text.tokenizers import TextTokenizer |
25 | 23 | from fairseq2.datasets import ( |
26 | 24 | DataPipelineReader, |
|
38 | 36 | from fairseq2.nn.padding import get_seqs_and_padding_mask |
39 | 37 | from fairseq2.typing import Device |
40 | 38 |
|
| 39 | +from typing_extensions import override |
| 40 | + |
41 | 41 |
|
42 | 42 | class AsrDataset(ABC): |
43 | 43 | """Represents an automatic speech recognition dataset.""" |
@@ -167,6 +167,10 @@ def add_tokenization_pipeline( |
167 | 167 | ) -> DataPipelineBuilder: |
168 | 168 | # Tokenize target text. |
169 | 169 | text_encoder = tokenizer.create_encoder() |
| 170 | + |
| 171 | + # to avoid to tokenize empty text, we filter out them out first |
| 172 | + builder = builder.filter(lambda x: bool(len(x["text"]) > 0)) |
| 173 | + |
170 | 174 | builder.map(text_encoder, selector="text") |
171 | 175 |
|
172 | 176 | unk_idx = tokenizer.vocab_info.unk_idx |
|
0 commit comments