espnet2.fileio.rand_gen_dataset.IntRandomGenerateDataset
espnet2.fileio.rand_gen_dataset.IntRandomGenerateDataset
class espnet2.fileio.rand_gen_dataset.IntRandomGenerateDataset(shape_file: Path | str, low: int, high: int = None, dtype: str | dtype = 'int64', loader_type: str = 'csv_int')
Bases: Mapping
Generate integer arrays from a shape definition file.
This class generates random integer arrays based on the shapes defined in a specified text file. The text file should list utterances and their respective shapes in a comma-separated format. The generated integers will be within the specified range defined by low and high.
low
The lower bound for the random integers.
- Type: int
high
The upper bound for the random integers.
- Type: int
dtype
The data type of the generated integers.
- Type: np.dtype
utt2shape
A mapping from utterance identifiers to their shapes.
Type: dict
Parameters:
- shape_file (Union *[*Path , str ]) – The path to the shape definition file.
- low (int) – The minimum value of the random integers.
- high (int , optional) – The maximum value of the random integers. If not specified, defaults to None.
- dtype (Union *[*str , np.dtype ] , optional) – The data type of the output integers. Defaults to “int64”.
- loader_type (str , optional) – The method used to load the shape file. Defaults to “csv_int”.
Returns: A random integer array of the specified shape.
Return type: np.ndarray
Examples
shape.txt uttA 123,83 uttB 34,83
>>> dataset = IntRandomGenerateDataset("shape.txt", low=0, high=10)
>>> array = dataset["uttA"]
>>> assert array.shape == (123, 83)
>>> array = dataset["uttB"]
>>> assert array.shape == (34, 83)
NOTE
The high parameter must be greater than low if specified.
- Raises:
- ValueError – If high is not specified and low is greater than or equal
- to high. –