<jupyter_start><jupyter_text><jupyter_code>import torch
def sigmoid_activation(x):
  return 1/(1+torch.exp(-x))
# generate random data
torch.manual_seed(7)
features = torch.randn((1, 5))
weights = torch.randn_like(features)
bias = torch.randn((1, 1))<jupyter_output><empty_output><jupyter_text>**To create a single layer**<jupyter_code># a way to reshape our tensors so the multiplication of matrices works
# weights.view(5, 1) or .resize_() or .reshape()
outputs = sigmoid_activation(torch.mm(features, weights.view(5, 1)) + bias)
# make our lables based on our inputs(data) and weights
# 2 ways to calculate wx+b
#outputs = sigmoid_activation(torch.sum(features * weights) + bias)
# or outputs = sigmoid_activation((features * weights).sum() + bias)
outputs<jupyter_output><empty_output><jupyter_text>**To create multi layers**<jupyter_code>### Generate some data
torch.manual_seed(7) # Set the random seed so things are predictable

# Features are 3 random normal variables
features = torch.randn((1, 3))

# Define the size of each layer in our network
n_input = features.shape[1]     # Number of input units, must match number of input features
n_hidden = 2                    # Number of hidden units 
n_output = 1                    # Number of output units

# Weights for inputs to hidden layer
W1 = torch.randn(n_input, n_hidden)
# Weights for hidden layer to output layer
W2 = torch.randn(n_hidden, n_output)

# and bias terms for hidden and output layers
B1 = torch.randn((1, n_hidden))
B2 = torch.randn((1, n_output))
hidden_output = sigmoid_activation(torch.mm(features, W1) + B1)
output = sigmoid_activation(torch.mm(hidden_output, W2) + B2)
output<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10940272028385571, 'fraction_numerical': 0.01714961561206387, 'mean_word_length': 5.108303249097473, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '254140', 'license': 'MIT', 'n_tokens_mistral': 577, 'n_tokens_neox': 559, 'n_words': 168, 'path': 'Buildingneuralnetworks_by_pytorch.ipynb', 'repo_name': 'RehabEmam228/pytorch-examples', 'size': '1691'}