Neural Network model¶
This module defines the neural network metamodel.
- class besser.BUML.metamodel.nn.neural_network.BatchNormLayer(name: str, num_features: int, dimension: str, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
NormalizationLayerRepresents a type of layer that normalizes inputs within mini-batches to maintain consistent mean and variance, enhancing training speed and stability.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
num_features (int) – The number of channels or features in each input sample.
dimension (str) – The dimensionality (1D, 2D, or 3D) of the input data to be normalized using batch normalization.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- dimension¶
The dimensionality (1D, 2D, or 3D) of the input data to be normalized using batch normalization.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.CNN(name: str, kernel_dim: List[int], stride_dim: List[int], padding_amount: int = 0, padding_type: str = 'valid', actv_func: str = None, name_module_input: str = None, input_reused: bool = False, permute_in: bool = False, permute_out: bool = False)[source]¶
Bases:
LayerRepresents a layer that is generally used in convolutional neural networks.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
kernel_dim (List[int]) – A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
stride_dim (List[int]) – A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
padding_amount (int) – The amount of padding added to the input.
padding_type (str) – The type of padding applied to the input.
permute_in (bool) – Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
permute_out (bool) – Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- kernel_dim¶
A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
- stride_dim¶
A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
- permute_in¶
Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- permute_out¶
Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.Configuration(batch_size: int, epochs: int, learning_rate: float, optimizer: str, loss_function: str, metrics: List[str], weight_decay: float = 0, momentum: float = 0)[source]¶
Bases:
objectRepresents a collection of parameters essential for training and evaluating neural networks.
- Parameters:
batch_size (int) – The number of data samples processed in each iteration during training or inference in a neural network.
epochs (int) – It refers to the number of complete passes through the entire dataset during the training, with each epoch consisting of one iteration through all data samples.
learning_rate (float) – The step size used to update the model parameters during optimization.
optimizer (str) – The method or algorithm used to adjust the model parameters iteratively during training to minimize the loss function and improve model performance.
loss_function (str) – The method used to calculate the difference between predicted and actual values, guiding the model towards better predictions.
List[str] (metrics) – Quantitative measures used to evaluate the performance of NN models.
weight_decay (float) – It represents the strength of L2 regularisation applied to the model’s parameters during optimization.
momentum (float) – It represents a hyperparameter in optimization that helps speed up training by using past gradients to smooth out updates.
- batch_size¶
The number of data samples processed in each iteration during training or inference in a neural network.
- Type:
- epochs¶
It refers to the number of complete passes through the entire dataset during the training, with each epoch consisting of one iteration through all data samples.
- Type:
- optimizer¶
The method or algorithm used to adjust the model parameters iteratively during training to minimize the loss function and improve model performance.
- Type:
- loss_function¶
The method used to calculate the difference between predicted and actual values, guiding the model towards better predictions.
- Type:
- metrics List[str]
Quantitative measures used to evaluate the performance of NN models.
- weight_decay¶
It represents the strength of L2 regularisation applied to the model’s parameters during optimization.
- Type:
- momentum¶
It represents a hyperparameter in optimization that helps speed up training by using past gradients to smooth out updates.
- Type:
- property batch_size: int¶
Get the number of data samples processed in each iteration during training or inference in a neural network.
- Type:
- property epochs: int¶
Get the number of complete passes through the entire dataset during the training.
- Type:
- property learning_rate: float¶
Get the step size used to update the model parameters during optimization.
- Type:
- property loss_function: str¶
Get the method used to calculate the difference between predicted and actual values, guiding the model towards better predictions.
- Type:
- class besser.BUML.metamodel.nn.neural_network.Conv1D(name: str, kernel_dim: List[int], out_channels: int, stride_dim: List[int] = None, in_channels: int = None, padding_amount: int = 0, padding_type: str = 'valid', actv_func: str = None, name_module_input: str = None, input_reused: bool = False, permute_in: bool = False, permute_out: bool = False)[source]¶
Bases:
ConvolutionalLayerRepresents a type of convolutional layer that applies a 1D convolution.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
kernel_dim (List[int]) – A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
stride_dim (List[int]) – A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
in_channels (int) – The number of channels in the input image.
out_channels (int) – The number of channels produced by the convolution.
padding_amount (int) – The amount of padding added to the input.
padding_type (str) – The type of padding applied to the input.
permute_in (bool) – Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
permute_out (bool) – Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- kernel_dim¶
Inherited from CNN. A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
- stride_dim¶
Inherited from CNN. A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
- in_channels¶
Inherited from ConvolutionalLayer. It represents the number of channels in the input image.
- Type:
- out_channels¶
Inherited from ConvolutionalLayer. It represents the number of channels produced by the convolution.
- Type:
- padding_amount¶
Inherited from CNN. It represents the amount of padding added to the input.
- Type:
- permute_in¶
Inherited from CNN. Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- permute_out¶
Inherited from CNN. Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.Conv2D(name: str, kernel_dim: List[int], out_channels: int, stride_dim: List[int] = None, in_channels: int = None, padding_amount: int = 0, padding_type: str = 'valid', actv_func: str = None, name_module_input: str = None, input_reused: bool = False, permute_in: bool = False, permute_out: bool = False)[source]¶
Bases:
ConvolutionalLayerRepresents a type of convolutional layer that applies a 2D convolution.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
kernel_dim (List[int]) – A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
stride_dim (List[int]) – A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
in_channels (int) – The number of channels in the input image.
out_channels (int) – The number of channels produced by the convolution.
padding_amount (int) – The amount of padding added to the input.
padding_type (str) – The type of padding applied to the input.
permute_in (bool) – Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
permute_out (bool) – Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- kernel_dim¶
Inherited from CNN. A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
- stride_dim¶
Inherited from CNN. A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
- in_channels¶
Inherited from ConvolutionalLayer. It represents the number of channels in the input image.
- Type:
- out_channels¶
Inherited from ConvolutionalLayer. It represents the number of channels produced by the convolution.
- Type:
- padding_amount¶
Inherited from CNN. It represents the amount of padding added to the input.
- Type:
- permute_in¶
Inherited from CNN. Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- permute_out¶
Inherited from CNN. Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.Conv3D(name: str, kernel_dim: List[int], out_channels: int, stride_dim: List[int] = None, in_channels: int = None, padding_amount: int = 0, padding_type: str = 'valid', actv_func: str = None, name_module_input: str = None, input_reused: bool = False, permute_in: bool = False, permute_out: bool = False)[source]¶
Bases:
ConvolutionalLayerRepresents a type of convolutional layer that applies a 3D convolution.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
kernel_dim (List[int]) – A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
stride_dim (List[int]) – A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
in_channels (int) – The number of channels in the input image.
out_channels (int) – The number of channels produced by the convolution.
padding_amount (int) – The amount of padding added to the input.
padding_type (str) – The type of padding applied to the input.
permute_in (bool) – Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
permute_out (bool) – Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- kernel_dim¶
Inherited from CNN. A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
- stride_dim¶
Inherited from CNN. A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
- in_channels¶
Inherited from ConvolutionalLayer. It represents the number of channels in the input image.
- Type:
- out_channels¶
Inherited from ConvolutionalLayer. It represents the number of channels produced by the convolution.
- Type:
- padding_amount¶
Inherited from CNN. It represents the amount of padding added to the input.
- Type:
- permute_in¶
Inherited from CNN. Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- permute_out¶
Inherited from CNN. Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.ConvolutionalLayer(name: str, kernel_dim: List[int], out_channels: int, stride_dim: List[int], in_channels: int = None, padding_amount: int = 0, padding_type: str = 'valid', actv_func: str = None, name_module_input: str = None, input_reused: bool = False, permute_in: bool = False, permute_out: bool = False)[source]¶
Bases:
CNNRepresents a convolutional layer.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
kernel_dim (List[int]) – A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
stride_dim (List[int]) – A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
in_channels (int) – The number of channels in the input image.
out_channels (int) – The number of channels produced by the convolution.
padding_amount (int) – The amount of padding added to the input.
padding_type (str) – The type of padding applied to the input.
permute_in (bool) – Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
permute_out (bool) – Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- kernel_dim¶
Inherited from CNN. A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
- stride_dim¶
Inherited from CNN. A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
- permute_in¶
Inherited from CNN. Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- permute_out¶
Inherited from CNN. Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.Dataset(name: str, path_data: str, task_type: str = None, input_format: str = None, image: Image = None, labels: set[Label] = None)[source]¶
Bases:
NamedElementRepresents the collection of data instances used for training or evaluation, where each instance comprises features and corresponding labels.
- Parameters:
name (str) – The name of the dataset.
path_data (str) – The file path or directory location containing the dataset.
task_type (str) – The type of prediction task associated with the dataset.
input_format (str) – The format of the input dataset.
image (Image) – An image instance that contains the shape desired for the images if input_format parameter is set to ‘images’.
- image¶
An image instance that contains the shape desired for the images if input_format parameter is set to ‘images’.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.DropoutLayer(name: str, rate: float, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
LayerModifierRepresents a type of layer that randomly sets a fraction of input units to zero during training to prevent overfitting and improve generalization.
- Parameters:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.EmbeddingLayer(name: str, num_embeddings: int, embedding_dim: int, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
GeneralLayerRepresents a layer that learns dense vector representations of the input data.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
num_embeddings (int) – The size of the dictionary of embeddings.
embedding_dim (int) – The size of each embedding vector.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.Feature(name: str)[source]¶
Bases:
NamedElementA feature is a measurable property or characteristic of an object used to represent and describe it within a dataset.
- Parameters:
name (str) – The name of the feature.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.FlattenLayer(name: str, start_dim: int = 1, end_dim: int = -1, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
GeneralLayerRepresents a layer that flattens a contiguous range of dims into a tensor.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
start_dim (int) – The first dimension to flatten.
end_dim (int) – The last dim to flatten.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.GRULayer(name: str, hidden_size: int, return_type: str = 'full', input_size: int = None, bidirectional: bool = False, dropout: float = 0.0, batch_first: bool = True, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
RNNRepresents a Gated Recurrent Unit layer.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
input_size (int) – It represents the dimensionality of the input features.
hidden_size (int) – It represents the number of units in the hidden state, which captures the network’s internal representation of the input sequence.
bidirectional (bool) – Whether the layer is bidirectional or not.
dropout (float) – If non-zero, it introduces a Dropout layer on the outputs of the GRU sub layers except the last one.
batch_first (bool) – If True, the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Only relevant to PyTorch.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
return_type (str) – Whether to return the hidden states, the last output in the output sequence or the full sequence.
Inherited from RNN. It represents the number of units in the hidden state, which captures the network’s internal representation of the input sequence.
- Type:
- dropout¶
Inherited from RNN. If non-zero, it introduces a Dropout layer on the outputs of the GRU sub layers except the last one.
- Type:
- batch_first¶
Inherited from RNN. If True, the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Only relevant to PyTorch.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- return_type¶
Inherited from RNN. Whether to return the hidden states, the last output in the output sequence or the full sequence.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.GeneralLayer(name: str, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
LayerRepresents a layer designed to handle general operations and transformations.
- Parameters:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.Image(shape: List[int] = None, normalize: bool = False)[source]¶
Bases:
FeatureImage represents features designed for handling data with spatial characteristics, typically including attributes such as height and width.
- Parameters:
- shape¶
The shape of the image in the form [height, width, channels]. Default to [256, 256].
- normalize¶
If true, the images will be normalized to zero mean and unit standard deviation.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.LSTMLayer(name: str, hidden_size: int, return_type: str = 'full', input_size: int = None, bidirectional: bool = False, dropout: float = 0.0, batch_first: bool = True, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
RNNRepresents a Long Short-Term Memory layer.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
input_size (int) – It represents the dimensionality of the input features.
hidden_size (int) – It represents the number of units in the hidden state, which captures the network’s internal representation of the input sequence.
bidirectional (bool) – Whether the layer is bidirectional or not.
dropout (float) – If non-zero, it introduces a Dropout layer on the outputs of the LSTM sub layers except the last one.
batch_first (bool) – If True, the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Only relevant to PyTorch.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
return_type (str) – Whether to return the hidden states, the last output in the output sequence or the full sequence.
Inherited from RNN. It represents the number of units in the hidden state, which captures the network’s internal representation of the input sequence.
- Type:
- dropout¶
Inherited from RNN. If non-zero, it introduces a Dropout layer on the outputs of the LSTM sub layers except the last one.
- Type:
- batch_first¶
Inherited from RNN. If True, the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Only relevant to PyTorch.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- return_type¶
Inherited from RNN. Whether to return the hidden states, the last output in the output sequence or the full sequence.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.Label(col_name: str, label_name: str = None)[source]¶
Bases:
objectA label is a value assigned to an observation, representing the target variable for prediction.
- Parameters:
- label_name¶
The name of a label in the dataset. If the prediction task is regression, it can be omitted.
- Type:
- class besser.BUML.metamodel.nn.neural_network.Layer(name: str, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
NamedElementThis class represents a layer of the neural network. It encapsulates attributes such as the name of the layer and the activation function.
- Parameters:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.LayerModifier(name: str, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
Layer- Represents a type of layer that applies transformations or
adjustments to other layers, enhancing their behavior or performance.
- Parameters:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.LayerNormLayer(name: str, normalized_shape: List[int], actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
NormalizationLayerRepresents a type of layer that normalizes the inputs across the features of a single data sample, rather than across the batch, to stabilize and accelerate training by reducing internal covariate shift.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
normalized_shape (List[int]) – A list refering to the dimensions or axis indices over which layer normalization is applied, specifying which parts of the tensor are normalized.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- normalized_shape¶
A list refering to the dimensions or axis indices over which layer normalization is applied, specifying which parts of the tensor are normalized.
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.LinearLayer(name: str, out_features: int, in_features: int = None, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
GeneralLayerRepresents a densely-connected NN layer that applies a linear transformation to the input data.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
in_features (int) – It represents the size of each input sample.
out_features (int) – It represents the size of each output sample.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.NN(name: str, configuration: Configuration = None, train_data: Dataset = None, test_data: Dataset = None)[source]¶
Bases:
BehaviorImplementationIt is a subclass of the BehaviorImplementation class and comprises the fundamental properties and behaviors of a neural network model.
- Parameters:
name (str) – The name of the neural network model.
configuration (Configuration) – The parameters related to the NN training and evaluation.
train_data (Dataset) – The dataset used to train the NN model.
test_data (Dataset) – The dataset used to evaluate the NN model.
- configuration¶
The parameters related to the NN training and evaluation.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- _module_names() set[source]¶
Names of every module declared in this NN (layers, tensor_ops, sub_nns).
- _validate_dataset_consistency(warnings: list)[source]¶
Surface mismatches between training and test datasets that usually indicate user error.
- _validate_module_names(errors: list, warnings: list)[source]¶
Reject names that aren’t valid Python identifiers; warn (matching
NamedElement.name’s warn-not-error stance) on Python keywords.
- _validate_numerical_bounds(errors: list)[source]¶
Reject non-positive sizes/rates that would crash the trainer at runtime.
- _validate_sub_nn_acyclic(errors: list) bool[source]¶
Detect cycles in the sub-NN graph rooted at this NN. Returns True if a cycle was found.
- add_configuration(configuration: Configuration) Self[source]¶
Self: Add the configuration to the NN model.
- property configuration: Configuration¶
Get the parameters related to the NN training and evaluation.
- Type:
- validate(raise_exception: bool = True, _visited: set = None) dict[source]¶
Validate the neural network model.
- Checks performed:
Module names are unique within this NN scope.
Layer
name_module_inputreferences resolve to a module defined in the same NN.TensorOp
layers_of_tensorsstring entries resolve to a module defined in the same NN.The first module in the sequence does not declare an input dependency (it is the entry point).
Sub-NNs are acyclic (no NN directly or transitively contains itself).
Each sub-NN is itself valid (recursive validation).
Warnings are emitted for empty NNs and for missing configuration on a top-level NN that has training data.
- Parameters:
raise_exception – If True, raises
ValueErrorwhen errors are found. Warnings never raise._visited – Internal — tracks NN instances already validated to stop infinite recursion on cyclic sub-NN graphs.
- Returns:
{"success": bool, "errors": list[str], "warnings": list[str]}- Return type:
- class besser.BUML.metamodel.nn.neural_network.NormalizationLayer(name: str, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
LayerModifierRepresents a type of layer that applies normalization techniques.
- Parameters:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.PoolingLayer(name: str, pooling_type: str, dimension: str, kernel_dim: List[int] = None, stride_dim: List[int] = None, padding_amount: int = 0, padding_type: str = 'valid', output_dim: List[int] = None, actv_func: str = None, name_module_input: str = None, input_reused: bool = False, permute_in: bool = False, permute_out: bool = False)[source]¶
Bases:
CNNRepresents a type of layer that performs a pooling operation.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
dimension (str) – The dimensionality (1D, 2D, or 3D) of the pooling operation.
kernel_dim (List[int]) – A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
stride_dim (List[int]) – A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
padding_amount (int) – The amount of padding added to the input.
padding_type (str) – The type of padding applied to the input.
pooling_type (str) – The type of pooling. Either average or max.
dimension – The dimensionality of the pooling. Either 1D, 2D or 3D.
output_dim (List[int]) – The output dimensions of the adaptive pooling operation. Only relevant for adaptive pooling.
permute_in (bool) – Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
permute_out (bool) – Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
- kernel_dim¶
Inherited from CNN. A list containing the dimensions of the convolving or pooling kernel (i.e., [depth, height, width]).
- stride_dim¶
Inherited from CNN. A list containing the dimensions of the stride of the convolution or pooling (i.e., [depth, height, width]).
- padding_amount¶
Inherited from CNN. It represents the amount of padding added to the input.
- Type:
- output_dim¶
The output dimensions of the adaptive pooling operation. Only relevant for adaptive pooling.
- permute_in¶
Inherited from CNN. Whether the dimensions of the input need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- permute_out¶
Inherited from CNN. Whether the dimensions of the output need to be permuted. Relevant for PyTorch. It is used to make PyTorch model equivalent to TensorFlow model.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.RNN(name: str, hidden_size: int, return_type: str = 'full', input_size: int = None, bidirectional: bool = False, dropout: float = 0.0, batch_first: bool = True, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
LayerRepresents a type of layer used in recurrent neural networks (RNN) for processing sequential data by using memory from previous steps to inform current outputs.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
input_size (int) – It represents the dimensionality of the input features.
hidden_size (int) – It represents the number of units in the hidden state, which captures the network’s internal representation of the input sequence.
bidirectional (bool) – Whether the layer is bidirectional or not.
dropout (float) – If non-zero, it introduces a Dropout layer on the outputs of the current sub layers except the last one.
batch_first (bool) – If True, the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Only relevant to PyTorch.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
return_type (str) – Whether to return the hidden states, the last output in the output sequence or the full sequence.
It represents the number of units in the hidden state, which captures the network’s internal representation of the input sequence.
- Type:
- dropout¶
If non-zero, it introduces a Dropout layer on the outputs of the current sub layers except the last one.
- Type:
- batch_first¶
If True, the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Only relevant to PyTorch.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- return_type¶
Whether to return the hidden states, the last output in the output sequence or the full sequence.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.SimpleRNNLayer(name: str, hidden_size: int, return_type: str = 'full', input_size: int = None, bidirectional: bool = False, dropout: float = 0.0, batch_first: bool = True, actv_func: str = None, name_module_input: str = None, input_reused: bool = False)[source]¶
Bases:
RNNRepresents a fully-connected RNN layer where the output is to be fed back as the new input.
- Parameters:
name (str) – The name of the layer.
actv_func (str) – The type of the activation function.
input_size (int) – It represents the dimensionality of the input features.
hidden_size (int) – It represents the number of units in the hidden state, which captures the network’s internal representation of the input sequence.
bidirectional (bool) – Whether the layer is bidirectional or not.
dropout (float) – If non-zero, it introduces a Dropout layer on the outputs of the RNN sub layers except the last one.
batch_first (bool) – If True, the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Only relevant to PyTorch.
name_module_input (str) – The name of the layer from which the inputs originate.
input_reused (bool) – Whether the input to this layer is reused as input to another layer.
return_type (str) – Whether to return the hidden states, the last output in the output sequence or the full sequence.
Inherited from RNN. It represents the number of units in the hidden state, which captures the network’s internal representation of the input sequence.
- Type:
- dropout¶
Inherited from RNN. If non-zero, it introduces a Dropout layer on the outputs of the RNN sub layers except the last one.
- Type:
- batch_first¶
Inherited from RNN. If True, the input and output tensors are provided as (batch, seq, feature) instead of (seq, batch, feature). Only relevant to PyTorch.
- Type:
- name_module_input¶
Inherited from Layer. The name of the layer from which the inputs originate.
- Type:
- input_reused¶
Inherited from Layer. Whether the input to this layer is reused as input to another layer.
- Type:
- return_type¶
Inherited from RNN. Whether to return the hidden states, the last output in the output sequence or the full sequence.
- Type:
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.Structured(name: str)[source]¶
Bases:
FeatureRepresents features organized in a systematic manner, typically with well-defined columns and rows, often found in tabular datasets.
- Parameters:
name (str) – The name of the feature.
- _abc_impl = <_abc._abc_data object>¶
- class besser.BUML.metamodel.nn.neural_network.TensorOp(name: str, tns_type: str, concatenate_dim: int = None, layers_of_tensors: List[str | float] = None, reshape_dim: List[int] = None, transpose_dim: List[int] = None, permute_dim: List[int] = None, input_reused: bool = False)[source]¶
Bases:
NamedElementThis class represents a tensor operation. It encapsulates attributes such as the name and the type of the tensor operation.
- Parameters:
name (str) – The name of the tensor operation.
type (str) – The type of the tensor operation.
concatenate_dim (int) – The dimension along which the tensors will be concatenated with the cat operation.
layers_of_tensors (List[Union[str, float]]) – The list that defines the inputs of the tensor op. Elements of the list can be either names of layers from which the tensors originate or scalar values.
reshape_dim (List[int]) – A list specifying the new shape of the tensor after the reshape operation.
transpose_dim (List[int]) – A list specifying the transpose dimensions. Only relevant with the transpose operation.
permute_dim (List[int]) – A list containing the desired ordering of dimensions. Only relevant with the permute operation.
input_reused (bool) – Whether the input to this tensor op is reused as input to another layer (or tensor op).
- concatenate_dim¶
The dimension along which the tensors will be concatenated with the cat operation.
- Type:
- layers_of_tensors¶
The list that defines the inputs of the tensor op. Elements of the list can be either names of layers from which the tensors originate or scalar values.
- reshape_dim¶
A list specifying the new shape of the tensor after the reshape operation.
- transpose_dim¶
A list specifying the transpose dimensions. Only relevant with the transpose operation.
- permute_dim¶
A list containing the desired ordering of dimensions. Only relevant with the permute operation.
- input_reused¶
Whether the input to this tensor op is reused as input to another layer (or tensor op).
- Type:
- _abc_impl = <_abc._abc_data object>¶
- property concatenate_dim: int¶
Get the dimension along which the tensors will be concatenated with the cat operation.
- Type:
- property input_reused: bool¶
Get whether the input to this layer is reused as input to another layer.
- Type:
- property layers_of_tensors: List[str | float]¶
Get the list that defines the inputs of the tensor op. Elements of the list can be either names of layers from which the tensors originate or scalar values.
- property permute_dim: List[int]¶
Get the list containing the desired ordering of dimensions for permute operation.