<jupyter_start><jupyter_text>Neural Memory System - PyTorchAnalyserLSTM demo  Environment setup<jupyter_code>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}")<jupyter_output>Root folder:    .
Current folder: demo/components/analysers<jupyter_text>Modules<jupyter_code>import torch
import torch.nn

from nemesys.modelling.analysers.modules.pytorch_analyser_lstm import PyTorchAnalyserLSTM
torch.set_printoptions(sci_mode=False)<jupyter_output><empty_output><jupyter_text>Analyser setup<jupyter_code>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,
)<jupyter_output><empty_output><jupyter_text>Data setup<jupyter_code>batch_size = 4
sequence_length = 4
data_batch = torch.normal(mean=0, std=1, size=(batch_size, sequence_length, input_size))<jupyter_output><empty_output><jupyter_text>Results<jupyter_code>result = analyser(data_batch)
for class_name, value in result.items():
    print(f"{class_name}:")
    print(value)
    print()<jupyter_output>class1:
{'content': tensor([[    -0.4569,     -0.0001,      0.0132,      0.1137],
        [    -0.0148,      0.1171,     -0.4016,      0.3214],
        [     0.0072,      0.0822,     -0.0568,      0.0795],
        [    -0.4120,     -0.0009,      0.0001,      0.0409],
        [    -0.0426,      0.0117,      0.3627,      0.3228],
        [     0.1696,      0.1243,     -0.3680,      0.4832],
        [     0.0299,      0.3129,     -0.2312,      0.3342],
        [    -0.0331,      0.6050,      0.2228,     -0.2524],
        [    -0.3532,      0.0171,      0.3284,      0.5586],
        [    -0.3284,      0.3425,     -0.0190,     -0.4926],
        [    -0.0693,      0.4905,     -0.4949,      0.2142]],
       grad_fn=<IndexBackward>)}

class2:
{'content': tensor([[     0.0749,     -0.5471,      0.0061,      0.0026],
        [     0.0136,      0.1000,      0.0546,      0.0042],
        [    -0.0010,      0.0467,     -0.0046,     -0.0189],
        [    -0.0747,     -0.0122,      0.0005,      0.02[...]
{'fraction_non_alphanumeric': 0.14793577981651376, 'fraction_numerical': 0.11888379204892967, 'mean_word_length': 2.4343832020997374, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '485854', 'license': 'Apache-2.0', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1075, 'n_words': 158, 'path': 'demo/components/analysers/demo_pytorch-analyser-lstm.ipynb', 'repo_name': 'suflaj/nemesys', 'size': '2616'}