adapters
BatchAdapter
Source code in lighter/adapters.py
__call__(batch)
Accesses the identifier, input, and target data from the batch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
Any
|
The batch data from which to extract information. |
required |
Returns:
Type | Description |
---|---|
tuple[Any, Any, Any]
|
A tuple containing (identifier, input, target). |
Raises:
Type | Description |
---|---|
ValueError
|
If accessors are invalid for the provided batch structure. |
Source code in lighter/adapters.py
__init__(input_accessor, target_accessor=None, identifier_accessor=None)
Initializes BatchAdapter with accessors for input, target, and identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_accessor
|
int | str | Callable
|
Accessor for the identifier data. Can be an index (lists/tuples), a key (dictionaries), a callable (custom batch processing). |
required |
target_accessor
|
int | str | Callable | None
|
Accessor for the target data. Can be an index (for lists/tuples), a key (for dictionaries), or a callable (for custom batch processing). |
None
|
identifier_accessor
|
int | str | Callable | None
|
Accessor for the identifier data. Can be an index (lists/tuples), a key (dictionaries), a callable (custom batch processing), or None if no identifier is present. |
None
|
Source code in lighter/adapters.py
_access_value(data, accessor)
Accesses a value from the data using the provided accessor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to access the value from. |
required |
accessor
|
int | str | Callable
|
The accessor to use. Can be an index (for lists/tuples), a key (for dictionaries), or a callable. |
required |
Returns:
Type | Description |
---|---|
Any
|
The accessed value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the accessor type or data structure is invalid. |
Source code in lighter/adapters.py
CriterionAdapter
Bases: _ArgumentsAndTransformsAdapter
This adapter processes and transforms the input, target, and prediction data, if specified, and forwards them to the specified arguments of a criterion (loss function).
Source code in lighter/adapters.py
__call__(criterion, input, target, pred)
Applies transforms and adapts arguments before calling the provided metric function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criterion
|
Callable
|
The criterion (loss function). |
required |
input
|
Any
|
The input data to transform with |
required |
target
|
Any
|
The target data to transform with |
required |
pred
|
Any
|
The prediction data to transform with |
required |
Returns:
Type | Description |
---|---|
Any
|
The result of the metric function call. |
Source code in lighter/adapters.py
LoggingAdapter
Bases: _TransformsAdapter
Adapter for applying logging transformations to data.
This adapter handles the transformation of input, target, and prediction data specifically for logging purposes. It can preprocess or format the data before logging, ensuring consistency and readability in logs.
Source code in lighter/adapters.py
MetricsAdapter
Bases: _ArgumentsAndTransformsAdapter
This adapter processes and transforms the input, target, and prediction data, if specified, and forwards them to the specified arguments of a metric.
Source code in lighter/adapters.py
__call__(metric, input, target, pred)
Applies transforms and adapts arguments before calling the provided metric function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
Callable
|
The metric. |
required |
input
|
Any
|
The input data to transform with |
required |
target
|
Any
|
The target data to transform with |
required |
pred
|
Any
|
The prediction data to transform with |
required |
Returns:
Type | Description |
---|---|
Any
|
The result of the metric function call. |
Source code in lighter/adapters.py
_ArgumentsAdapter
Base adapter for adapting arguments to a function based on specified argument names or positions.
Source code in lighter/adapters.py
__call__(input, target, pred)
Adapts the input, target, and prediction data to the specified argument positions or names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Any
|
The input data to be adapted. |
required |
target
|
Any
|
The target data to be adapted. |
required |
pred
|
Any
|
The prediction data to be adapted. |
required |
Returns:
Type | Description |
---|---|
tuple[list[Any], dict[str, Any]]
|
A tuple containing a list of positional arguments and a dictionary of keyword arguments. |
Source code in lighter/adapters.py
_ArgumentsAndTransformsAdapter
Bases: _ArgumentsAdapter
, _TransformsAdapter
A generic adapter for applying functions (criterion or metrics) to data.
Source code in lighter/adapters.py
__call__(fn, input, target, pred)
Applies transforms and adapts arguments before calling the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn
|
Callable
|
The function/method to be called (e.g., a loss function or metric). |
required |
input
|
Any
|
The input data. |
required |
target
|
Any
|
The target data. |
required |
pred
|
Any
|
The prediction data. |
required |
Returns:
Type | Description |
---|---|
Any
|
The result of the function call. |
Source code in lighter/adapters.py
__init__(input_argument=None, target_argument=None, pred_argument=None, input_transforms=None, target_transforms=None, pred_transforms=None)
Initializes the Arguments and Transforms Adapter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_argument
|
int | str | None
|
Position or name for the input data. |
None
|
target_argument
|
int | str | None
|
Position or name for the target data. |
None
|
pred_argument
|
int | str | None
|
Position or name for the prediction data. |
None
|
input_transforms
|
list[Callable] | None
|
Transforms to apply to the input data. |
None
|
target_transforms
|
list[Callable] | None
|
Transforms to apply to the target data. |
None
|
pred_transforms
|
list[Callable] | None
|
Transforms to apply to the prediction data. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If transforms are provided without corresponding argument specifications. |
Source code in lighter/adapters.py
_TransformsAdapter
Adapter for applying transformations to data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_transforms
|
Callable | list[Callable] | None
|
A single or a list of transforms to apply to the input data. |
None
|
target_transforms
|
Callable | list[Callable] | None
|
A single or a list of transforms to apply to the target data. |
None
|
pred_transforms
|
Callable | list[Callable] | None
|
A single or a list of transforms to apply to the prediction data. |
None
|
Source code in lighter/adapters.py
__call__(input, target, pred)
Applies the specified transforms to the input, target, and prediction data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Any
|
The input data. |
required |
target
|
Any
|
The target data. |
required |
pred
|
Any
|
The prediction data. |
required |
Returns:
Type | Description |
---|---|
tuple[Any, Any, Any]
|
The transformed (input, target, prediction) data. |
Source code in lighter/adapters.py
_transform(data, transforms)
Applies a list of transform functions to the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
The data to be transformed. |
required |
transforms
|
Callable | list[Callable]
|
A single transform function or a list of functions. |
required |
Returns:
Type | Description |
---|---|
Any
|
The transformed data. |
Raises:
Type | Description |
---|---|
ValueError
|
If any transform is not callable. |