train_util
Author: Heli Qi Affiliation: NAIST Date: 2022.07
float_near_round(input_float)
Round the float number in [X.0, X.5) to X and the float number in (X.5, {X+1}.0] to X+1.
Source code in speechain/utilbox/train_util.py
get_min_indices_by_freq(freq_dict, shuffle=True, chosen_idx_num=1, freq_weights=None)
Get the specified number of indices with minimum values from the input frequency dictionary, optionally applying frequency weights, and return the updated frequency dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
freq_dict
|
Dict[Any, Union[int, float]]
|
The input frequency dictionary containing the values to be compared. |
required |
shuffle
|
bool
|
If True, shuffle the input frequency dictionary before selecting the minimum indices. Defaults to True. |
True
|
chosen_idx_num
|
int
|
The number of minimum indices to return. If not provided, all indices will be returned. |
1
|
freq_weights
|
List[Union[int, float]]
|
The frequency weights to apply when selecting the minimum indices. Should have the same length as the number of indices to return. If not provided, equal weights will be applied. |
None
|
Returns:
Type | Description |
---|---|
Tuple[List, Dict[Any, Union[int, float]]]
|
Tuple[List[int], Dict[Any, Union[int, float]]]: A tuple containing a list of the selected minimum indices and the updated frequency dictionary. |
Source code in speechain/utilbox/train_util.py
make_mask_from_len(data_len, max_len=None, mask_type=torch.bool, return_3d=True)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_len
|
Tensor
|
(batch_size,) The length of each sequence in the batch |
required |
max_len
|
int
|
int The max length of the mask matrix. Could be larger than the real length of data_len |
None
|
mask_type
|
dtype
|
torch.dtype The value type of the mask matric. |
bool
|
return_3d
|
bool
|
bool Whether to return a 3d mask tensors. If True, the returned mask tensor will be 3d (batch_size, 1, max_len) If False, the returned mask tensor will be 2d (batch_size, max_len) |
True
|
Returns:
Type | Description |
---|---|
The corresponding mask for this batch. |
|
The parts at the end of the shorter sequence will be False or 0.0. |
Source code in speechain/utilbox/train_util.py
recur_criterion_init(input_conf, criterion_class)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_conf
|
Dict
|
|
required |
criterion_class
|
Criterion
|
|
required |
Returns:
Source code in speechain/utilbox/train_util.py
spk2tensor(spk_list, spk2idx_dict)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spk_list
|
List[str]
|
|
required |
spk2idx_dict
|
Dict
|
|
required |
Returns:
Source code in speechain/utilbox/train_util.py
text2tensor_and_len(text_list, text2tensor_func, ignore_idx)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text_list
|
List[str or List[str]]
|
|
required |
text2tensor_func
|
|
required | |
ignore_idx
|
int
|
|
required |
Returns: