Model

_model

This file is a base class for the model.

class scalr.nn.model._model.ModelBase[source]

Bases: Module

Class for the model.

Contains different methods to make a forward() call, load, save weights and predict the data provided.

forward(x: Tensor) Tensor[source]

A function for forward pass of the model to generate outputs.

classmethod get_default_params() dict[source]

Class method to get default params for model_config.

get_predictions(dl: DataLoader, device: str = 'cpu')[source]

A function to get predictions from the dataloader.

load_weights(model_weights_path: str)[source]

A function to initialize model weights from previous weights.

save_weights(model_weights_path: str)[source]

A function to save model weights at the path.

scalr.nn.model._model.build_model(model_config: dict) tuple[Module, dict][source]

Builder object to get Model, updated model_config.

sequential_model

This file is an implementation of a sequential model.

class scalr.nn.model.sequential_model.SequentialModel(layers: list[int], dropout: float = 0, activation: str = 'ReLU', weights_init_zero: bool = False)[source]

Bases: ModelBase

Class for Deep Neural Network model with linear layers.

forward(x: Tensor) Tensor[source]

Pass input through the network.

Parameters:

x – Tensor, shape [batch_size, layers[0]].

Returns:

Output dict containing batched layers[-1]-dimensional vectors in [‘cls_output’] key.

classmethod get_default_params()[source]

Class method to get default params for model_config.

get_predictions(dl: DataLoader, device: str = 'cpu') Tuple[list[int], list[int], list[list[int]]][source]

A function to get predictions from a model, from the dataloader.

Parameters:
  • dl (DataLoader) – DataLoader object containing samples.

  • device (str, optional) – Device to run the model on. Defaults to ‘cpu’.

Returns:

True labels, Predicted labels, Predicted probabilities of all samples in the dataloader.

make_weights_zero()[source]

A function to initialize layer weights to 0.

shap_model

This file is an implementation of the custom SHAP model.

class scalr.nn.model.shap_model.CustomShapModel(model, key='cls_output')[source]

Bases: Module

Class for a custom model for SHAP.

forward(x)[source]

Pass input through the model and return output.

Parameters:

x – Tensor.