espnet2.train.reporter.to_reported_value
Less than 1 minute
espnet2.train.reporter.to_reported_value
espnet2.train.reporter.to_reported_value(v: float | int | complex | Tensor | ndarray, weight: float | int | complex | Tensor | ndarray | None = None) → ReportedValue
Convert a value and an optional weight into a reported value.
This function takes a numerical value and an optional weight and converts them into a reported value. The reported value can either be a simple average or a weighted average depending on the presence of the weight.
- Parameters:
- v (Num) – The value to be reported. It can be a float, int, complex, torch.Tensor, or np.ndarray. The value must be a scalar (0 or 1 dimension).
- weight (Optional *[*Num ]) – An optional weight associated with the value. It can also be a float, int, complex, torch.Tensor, or np.ndarray, and must be a scalar.
- Returns: An instance of either Average or WeightedAverage : based on whether a weight was provided.
- Return type:ReportedValue
- Raises:ValueError – If the provided value v or weight is not 0 or 1 dimension.
Examples
>>> to_reported_value(5)
Average(value=5)
>>> to_reported_value(5, weight=2)
WeightedAverage(value=(5, 2))