espnet2.train.dataset.AdapterForLabelScpReader
espnet2.train.dataset.AdapterForLabelScpReader
class espnet2.train.dataset.AdapterForLabelScpReader(loader: Dict[str, List[List[str | float | int]]])
Bases: Mapping
AdapterForLabelScpReader is a class that acts as an adapter for reading label
data in a structured format from a provided loader.
This class implements the collections.abc.Mapping interface, allowing it to be used in contexts where a mapping is required. It takes a loader, which is expected to return data in the format of a dictionary where the keys are utterance IDs and the values are lists of label sequences.
loader
A dictionary-like
- Type: Dict[str, List[List[Union[str, float, int]]]]
structure that holds the label data.
- Parameters:
- loader (Dict *[*str , List *[*List *[*Union *[*str , float , int ] ] ] ]) – A mapping of
- sequences (utterance IDs to their corresponding label)
- label (where each)
- time (end)
- time
- and
- label.
- Returns: A tuple containing: : - sample_time (np.ndarray): A 2D numpy array where each row contains the start and end times of the labels.
- sample_label (List): A list of labels corresponding to the times.
- Return type: Tuple[np.ndarray, List]
####### Examples
>>> label_data = {
... "utt1": [[0.0, 1.0, "label1"], [1.0, 2.0, "label2"]],
... "utt2": [[0.5, 1.5, "label3"]]
... }
>>> reader = AdapterForLabelScpReader(label_data)
>>> times, labels = reader["utt1"]
>>> print(times)
[[0.0, 1.0], [1.0, 2.0]]
>>> print(labels)
['label1', 'label2']
- Raises:
- AssertionError – If the data format does not match the expected structure
- or if the output is not as specified. –
keys()
Adapter class for loading label data from a dictionary.
This class provides a mapping interface to retrieve label data stored in a dictionary format. Each entry in the dictionary is expected to be a list of lists, where each inner list contains timing and label information.
loader
A dictionary that maps keys to a list of label data.
Type: Dict[str, List[List[Union[str, float, int]]]]
Parameters:loader (Dict *[*str , List *[*List *[*Union *[*str , float , int ] ] ] ]) – The dictionary containing the label data.
Returns: A tuple containing the sample time as a 2D array and the sample label as a list.
Return type: np.ndarray
####### Examples
>>> loader = {
... "utt1": [[0.0, 1.0, "a"], [1.0, 2.0, "b"]],
... "utt2": [[0.0, 1.5, "c"], [1.5, 3.0, "d"]]
... }
>>> adapter = AdapterForLabelScpReader(loader)
>>> time, labels = adapter["utt1"]
>>> print(time)
[[0. 1. ]
[1. 2. ]]
>>> print(labels)
['a', 'b']
- Raises:AssertionError – If the retrieved value is not in the expected format.