<jupyter_start><jupyter_text><jupyter_code>!pip install simpleTorch<jupyter_output>Cloning into 'Training_ANN_with_Pytorch'...
remote: Enumerating objects: 47, done.[K
remote: Counting objects: 100% (47/47), done.[K
remote: Compressing objects: 100% (33/33), done.[K
remote: Total 47 (delta 22), reused 34 (delta 14), pack-reused 0[K
Unpacking objects: 100% (47/47), done.<jupyter_text>**Construct ANN**You first need to initialize the neural network<jupyter_code>import torch
import torch.nn as nn

class Model(nn.Module):
    def __init__(self, state_size, action_size):
        super().__init__()
        self.layer1 = nn.Linear(state_size, 20)
        self.layer2 = nn.Linear(20, 20)
        self.layer3 = nn.Linear(20, 20)
        self.action = nn.Linear(20, action_size)

    def forward(self, state):
        m      = torch.nn.LeakyReLU(0.1)#0.01)
        layer1 = m(self.layer1(state))
        layer2 =m(self.layer2(layer1))
        layer3 = m(self.layer3(layer2))
        action = (self.action(layer3))
        return (action)<jupyter_output><empty_output><jupyter_text>**Generate the input-output data**<jupyter_code>import numpy as np
from simpleTorch.train_ann import *
x_m = 1000  # number of samples
x = np.random.default_rng().uniform(-5, 5, x_m)
y = np.random.default_rng().uniform(-5, 5, x_m)
X = np.array((x, y)).T

F = []
for i in range(0, x_m, 1):
    f = np.array([[100 * (y[i] - x[i] ** 2) ** 2 + (1 - x[i]) ** 2, x[i]*y[i]]])
    F.append(*f.reshape(1,2))
F = np.array(F)
if f.ndim==1:
    F = F.reshape(-1, 1)<jupyter_output><empty_output><jupyter_text>**Initialize the neural network**<jupyter_code>model = Model(X.shape[1],F.shape[1])<jupyter_output><empty_output><jupyter_text>**Perform the training with all the default values of the class**<jupyter_code>ANN = train_ann(model, X, F)
# You can have different options to choose from lise optimizer, objective function, to plot or print
#learning_rate = 0.01
#ANN =  train_ann(model, X, F, optimizer=optim.Adam(model.parameters(), lr=learning_rate), 
#                 loss_fn=nn.MSELoss(), learning_rate=learning_rate, print_val=False, plot=True, validation_set=0.33, auto_normalize=True, epoch=200,batch_size=68)<jupyter_output>Epoch:  1  Batches:  1  Loss:  0.4089989960193634
Epoch:  1  Batches:  2  Loss:  0.4203018844127655
Epoch:  1  Batches:  3  Loss:  0.39718592166900635
Epoch:  1  Batches:  4  Loss:  0.41700658202171326
Epoch:  1  Batches:  5  Loss:  0.41289544105529785
Epoch:  1  Batches:  6  Loss:  0.41768401861190796
Epoch:  1  Batches:  7  Loss:  0.42315372824668884
Epoch:  1  Batches:  8  Loss:  0.32236647605895996
Epoch:  1  Batches:  9  Loss:  0.40296828746795654
Epoch:  1  Batches:  10  Loss:  0.3424319624900818
Epoch:  2  Batches:  11  Loss:  0.3782684803009033
Epoch:  2  Batches:  12  Loss:  0.36535248160362244
Epoch:  2  Batches:  13  Loss:  0.35532382130622864
Epoch:  2  Batches:  14  Loss:  0.37336084246635437
Epoch:  2  Batches:  15  Loss:  0.36508145928382874
Epoch:  2  Batches:  16  Loss:  0.3408660292625427
Epoch:  2  Batches:  17  Loss:  0.33446812629699707
Epoch:  2  Batches:  18  Loss:  0.3316862881183624
Epoch:  2  Batches:  19  Loss:  0.3182566463947296
Epoch:  2  Batches:  20  Los[...]<jupyter_text>**Perform Predictions of a given input (numpy)**<jupyter_code>#This is how you make predicitons
fs = ANN.predict(X)

plt.plot(F,fs,'o')
plt.xlabel('Labels')
plt.ylabel('Predicitons')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13281022958442312, 'fraction_numerical': 0.14007555943039815, 'mean_word_length': 4.144992526158445, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '169347', 'license': 'MIT', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1404, 'n_words': 317, 'path': 'example_of_usage.ipynb', 'repo_name': 'UCL/simpleTorch', 'size': '3441'}