<jupyter_start><jupyter_text>Working Dynamically<jupyter_code>W*x
b
#weight tensors
W1 = torch.tensor(6)
W2 = torch.tensor(6)
W3 = torch.tensor(6)

x1 = torch.tensor([2, 2, 2])
x2 = torch.tensor([3, 3, 3])
x3 = torch.tensor([4, 4, 4])

b = torch.tensor(10)#bias tensor
W1, W2, W3
intermediate_value = W1 * x1 + W2 * x2

intermediate_value
final_value = W1 * x1 + W2 * x2 + W3 * x3 + b

final_value<jupyter_output><empty_output><jupyter_text>Viewing PyTorch computation graphshttps://github.com/waleedka/hiddenlayer  Computation Graph<jupyter_code>import hiddenlayer as hl
x_train = np.array ([[1.7], [2.5], [5.5], [7.9], [8.8],
                     [2.4],[2.4], [8.89], [5], [4.4]],
                    dtype = np.float32)

y_train = np.array ([[1.9], [2.68], [4.22], [8.19], [9.69],
                     [3.4],[2.6], [8.8], [5.6], [4.7]],
                    dtype = np.float32)
X_train = torch.tensor(x_train)
Y_train = torch.tensor(y_train)

X_train.shape
inp = 1 #input
out = 1 #output

hid = 100 #100 neurons in hidden layer
model1 = torch.nn.Sequential(torch.nn.Linear(inp, hid),
                             torch.nn.Linear(hid, out))
hl.build_graph(model1, torch.zeros([10, 1])) #must feed in test data
hl.build_graph(model1, torch.zeros([1]))
#viz is auto-expanded to show contents of each layer if only 1 data point is passed as input
#demo shows numbers on the some ecges that are not shown here
model2 = torch.nn.Sequential(torch.nn.Linear(inp, hid),
                             torch.nn.Linear(hid, hid),
                             torch.nn.Sigmoid(),
                             torch.nn.Linear(hid, out))
hl.build_graph(model2, torch.zeros([10, 1]))
hl.build_graph(model2, torch.zeros([1]))
inp = 2
out = 1

hid = 100
model3 = torch.nn.Sequential(torch.nn.Linear(inp, hid),
                             torch.nn.Linear(hid, hid),
                             torch.nn.Sigmoid(),
                             torch.nn.Linear(hid, out))
hl.build_graph(model3, torch.zeros([10, 2]))
hl.build_graph(model3, torch.zeros([2]))<jupyter_output>(dot.exe:6928): Pango-WARNING **: couldn't load font "Times Not-Rotated 10", falling back to "Sans Not-Rotated 10", expect ugly output.
{'fraction_non_alphanumeric': 0.15570776255707763, 'fraction_numerical': 0.05662100456621005, 'mean_word_length': 2.657762938230384, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '329008', 'license': 'MIT', 'n_tokens_mistral': 854, 'n_tokens_neox': 821, 'n_words': 189, 'path': 'pyTorch_PS/PT09-PytorchComputationGraph.ipynb', 'repo_name': 'rsunderscore/learning', 'size': '2190'}