NeSy4PPM.Training package — NeSy4PPM 0.1.0 documentation

# NeSy4PPM.Training package

## Submodules

## NeSy4PPM.Training.Modulator module

class NeSy4PPM.Training.Modulator.Modulator(*args, **kwargs)

  Bases: `Layer`

  build(input_shape)

    Creates the variables of the layer (optional, for subclass implementers).

    This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call. It is invoked automatically before the first execution of call().

    This is typically used to create the weights of Layer subclasses (at the discretion of the subclass implementer).

    Parameters:

      input_shape – Instance of TensorShape, or list of instances of TensorShape if the layer expects a list of inputs (one instance per input).

  call(x)

    Forward pass of the modulator layer.

    Splits the input into different representation vectors, computes element-wise products, concatenates them, and applies learned weights and biases.

    Parameters:

      x (tf.Tensor) – Input tensor with shape (batch_size, time_steps, features).

    Returns:

      Modulated tensor with shape (batch_size, time_steps, features).

    Return type:

      tf.Tensor

  compute_output_shape(input_shape)

    Computes the output shape of the layer.

    This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

    Parameters:

      input_shape – Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

    Returns:

      An input shape tuple.

  get_config()

    Returns the config of the layer.

    A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

    The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

    Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

    Returns:

      Python dictionary.

## NeSy4PPM.Training.train_common module

class NeSy4PPM.Training.train_common.CustomTransformer(*args, **kwargs)

  Bases: `Layer`

  Custom Transformer block consisting of multi-head attention and feed-forward layers.

  call(inputs, mask=None, *args, **kwargs)

    Forward pass of the CustomTransformer layer.

    Parameters:

      - inputs (tf.Tensor) – Input tensor.

      - mask (tf.Tensor, optional) – Attention mask.

    Returns:

      Output tensor after attention and feed-forward layers.

    Return type:

      tf.Tensor

  get_config()

    Return the config dictionary for recreating this layer.

    Returns:

      Configuration parameters.

    Return type:

      dict

NeSy4PPM.Training.train_common.create_checkpoints_path(log_name, model: NN_model, model_type, encoder: Encodings, output_folder)

  Create a directory path and filename pattern for model checkpoints.

  Parameters:

    - log_name (str) – Name of the log.

    - model (NN_model) – Enum representing the model type.

    - model_type (str) – Specific model type (e.g., ‘LSTM’, ‘Transformer’).

    - encoder (Encodings) – Enum representing the encoding method.

    - output_folder (Path) – Base output folder path.

  Returns:

    Full path pattern for saving checkpoint files.

  Return type:

    str

NeSy4PPM.Training.train_common.plot_loss(history, dir_name)

  Plot and save the training and validation loss curves.

  Parameters:

    - history (keras.callbacks.History) – Keras training history object.

    - dir_name (str or Path) – Directory to save the plot image.

## NeSy4PPM.Training.train_model module

NeSy4PPM.Training.train_model.learn(log_data: LogData, encoder: Encodings, model_arch: NN_model, resource: bool, output_folder: Path = WindowsPath('C:/Users/JOukharijane/Desktop/PostDoc/NeSy4PPM/docs/source/data/output'))

NeSy4PPM.Training.train_model.train(log_data: LogData, encoder: Encodings, model_arch: NN_model, X, y_a, y_g=None, output_folder: Path = WindowsPath('C:/Users/JOukharijane/Desktop/PostDoc/NeSy4PPM/docs/source/data/output'))

## Module contents