<jupyter_start><jupyter_text>Two-layer Neural Network Original code at: http://iamtrask.github.io/2015/07/12/basic-python-network/<jupyter_code>"""
    Original code at: http://iamtrask.github.io/2015/07/12/basic-python-network/
"""

import numpy as np
# sigmoid function
def nonlin(x, deriv=False):
    if(deriv==True):
        return x*(1-x)
    return 1/(1+np.exp(-x))
# input dataset
X = np.array([[0,0,1],
              [0,1,1],
              [1,0,1],
              [1,1,1]])

# output dataset
y = np.array([[0, 0, 1, 1]]).T
# seed random numbers to make calculation deterministic (good practice)
np.random.seed(1)

# initialize weights randomly with mean 0
syn0 = 2*np.random.random((3, 1)) - 1
for iter in range(10000):

    # forward propogation
    l0 = X
    l1 = nonlin(np.dot(l0, syn0))

    # how much did we miss?
    l1_error = y - l1

    # multiply how much we missed by the slope of the sigmoid at the values in l1
    l1_delta = l1_error * nonlin(l1, True)

    # update weights
    syn0 += np.dot(l0.T, l1_delta)
print("Output After Training")
print(l1)<jupyter_output>Output After Training
[[  7.21568063e-04]
 [  4.80986190e-04]
 [  9.99592413e-01]
 [  9.99388522e-01]]
{'fraction_non_alphanumeric': 0.14693534844668346, 'fraction_numerical': 0.08816120906801007, 'mean_word_length': 3.0134680134680134, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '651669', 'license': 'MIT', 'n_tokens_mistral': 507, 'n_tokens_neox': 455, 'n_words': 113, 'path': 'nn_fromscratch_2layer.ipynb', 'repo_name': 'analyticalmonk/NeuralNetwork_FromScratch', 'size': '1191'}