kaira.models.binary.soft_bit_thresholding.WeightedThresholder

Inheritance diagram for WeightedThresholder
- class kaira.models.binary.soft_bit_thresholding.WeightedThresholder(weights: Tensor | List[float] | float, threshold: float = 0.5, input_type: InputType = InputType.PROBABILITY, normalize_weights: bool = False, *args: Any, **kwargs: Any)[source]
Bases:
SoftBitThresholderThresholder that applies weights to input values before thresholding.
This thresholder allows applying non-uniform weights to different parts of the input tensor, which is useful for systems where some bits are more reliable or important than others.
Example
With weights=[1.0, 0.8, 0.5], threshold=0.6: Input [0.7, 0.7, 0.7] becomes [1.0, 0.0, 0.0] after weighting.
Methods
Initialize the weighted thresholder.
Apply weighted thresholding to convert soft bit values to hard decisions.
Create model instance from configuration.
Create model from Hydra DictConfig.
Create model from Hugging Face PretrainedConfig.
Move the model to the specified device.
- __init__(weights: Tensor | List[float] | float, threshold: float = 0.5, input_type: InputType = InputType.PROBABILITY, normalize_weights: bool = False, *args: Any, **kwargs: Any)[source]
Initialize the weighted thresholder.
- Parameters:
weights – Weights to apply to input values. Can be a tensor, list, or scalar.
threshold – Threshold value to apply after weighting.
input_type – Type of soft input values.
normalize_weights – If True, weights are normalized to sum to 1.0.
*args – Variable positional arguments passed to the base class.
**kwargs – Variable keyword arguments passed to the base class.
- forward(x: Tensor, *args: Any, **kwargs: Any) Tensor[source]
Apply weighted thresholding to convert soft bit values to hard decisions.
- Parameters:
x – Input tensor of soft bit values.
*args – Additional positional arguments (unused).
**kwargs – Additional keyword arguments (unused).
- Returns:
Tensor of hard bit decisions (0.0 or 1.0).
- classmethod from_config(config, **kwargs)
Create model instance from configuration.
- Parameters:
config – Configuration object (PretrainedConfig, DictConfig, or dict)
**kwargs – Additional parameters to override config
- Returns:
Model instance
- classmethod from_hydra_config(config: DictConfig, **kwargs)
Create model from Hydra DictConfig.
- Parameters:
config – Hydra configuration
**kwargs – Additional parameters
- Returns:
Model instance
- classmethod from_pretrained_config(config: PretrainedConfig, **kwargs)
Create model from Hugging Face PretrainedConfig.
- Parameters:
config – PretrainedConfig instance
**kwargs – Additional parameters
- Returns:
Model instance
- to(device: str | device, *args, **kwargs) SoftBitThresholder
Move the model to the specified device.
- Parameters:
device – The device to move the model to.
*args – Additional positional arguments for nn.Module.to().
**kwargs – Additional keyword arguments for nn.Module.to().
- Returns:
Self for method chaining.