# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: nemesys
#     language: python
#     name: nemesys
# ---

# # Neural Memory System - PyTorchAnalyserLSTM demo

# ## Environment setup

import os
from pathlib import Path

CURRENT_FOLDER = Path(os.getcwd())

# +
CD_KEY = "--ANALYSER_LSTM_DEMO_IN_ROOT"

if (
    CD_KEY not in os.environ
    or os.environ[CD_KEY] is None
    or len(os.environ[CD_KEY]) == 0
    or os.environ[CD_KEY] == "false"
):
    # %cd -q ../../..
    
    ROOT_FOLDER = Path(os.getcwd()).relative_to(os.getcwd())
    CURRENT_FOLDER = CURRENT_FOLDER.relative_to(ROOT_FOLDER.absolute())
    
os.environ[CD_KEY] = "true"
# -

print(f"Root folder:    {ROOT_FOLDER}")
print(f"Current folder: {CURRENT_FOLDER}")

# ## Modules

# +
import torch
import torch.nn

from nemesys.modelling.analysers.modules.pytorch_analyser_lstm import PyTorchAnalyserLSTM
# -

torch.set_printoptions(sci_mode=False)

# ## Analyser setup

# +
class_names = ("class1", "class2")

input_size = 128
output_size = 4
batch_first = True
# -

analyser = PyTorchAnalyserLSTM(
    class_names=class_names,
    input_size=input_size,
    hidden_size=output_size,
    batch_first=batch_first,
)

# ## Data setup

batch_size = 4
sequence_length = 4

data_batch = torch.normal(mean=0, std=1, size=(batch_size, sequence_length, input_size))

# ## Results

result = analyser(data_batch)

for class_name, value in result.items():
    print(f"{class_name}:")
    print(value)
    print()

StarcoderdataJupyterScriptsDedupFiltered