<jupyter_start><jupyter_text>PyTorch Basics<jupyter_code># Importing PyTorch and Numpy
import torch
import numpy as np
from torch.autograd import Variable
# Declaring Variable in Pytorch
a = Variable(torch.Tensor([19]))
b = torch.Tensor([97])

# Types
print(a)
print(b)
print(type(a))
print(type(b))
# Variables and Operations
x = Variable(torch.Tensor([1]), requires_grad=True)
w = Variable(torch.Tensor([2]), requires_grad=True)
b = Variable(torch.Tensor([3]), requires_grad=True)
# 2 * 1 + 3
y = w * x + b
y
# Compute the gradients
y.backward()
print(x.grad)    # x.grad = 2 
print(w.grad)    # w.grad = 1 
print(b.grad)    # b.grad = 1 
# Tensors of MxN Dimensions.

# Creates a Tensor (A Matrix) of size 5x3.
t = torch.Tensor(5, 3)

print(t)
print(t.size())
# Operations on Tensors

# Creating Tensors
p = torch.Tensor(4,4)
q = torch.Tensor(4,4)
ones = torch.ones(4,4)
print(p, y, ones)
print("Addition:{}".format(p + q))
print("Subtraction:{}".format(p - ones))
print("Multiplication:{}".format(p * ones))
print("Division:{}".format(q / ones))<jupyter_output>Addition:
1.00000e-44 *
  0.0000  0.0000  0.0000  0.0000
  2.1019  0.0000  0.0000  0.0000
  0.0000  0.0000  0.0000  0.0000
  0.0000  0.0000  0.0000  0.0000
[torch.FloatTensor of size 4x4]

Subtraction:
-1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
[torch.FloatTensor of size 4x4]

Multiplication:
1.00000e-45 *
  0.0000  0.0000  0.0000  0.0000
  9.8091  0.0000  0.0000  0.0000
  0.0000  0.0000  0.0000  0.0000
  0.0000  0.0000  0.0000  0.0000
[torch.FloatTensor of size 4x4]

Division:
1.00000e-44 *
  0.0000  0.0000  0.0000  0.0000
  1.1210  0.0000  0.0000  0.0000
  0.0000  0.0000  0.0000  0.0000
  0.0000  0.0000  0.0000  0.0000
[torch.FloatTensor of size 4x4]<jupyter_text>Basic NeuralNetwork Introduction In PyTorch<jupyter_code># Creating a basic Nueral Network in PyTorch

x = Variable(torch.randn(5, 3))
y = Variable(torch.randn(5, 2))

# Importing NN
import torch.nn as nn
linear = nn.Linear(3, 2)
print(linear)

# Type of Linear
print(type(linear))
print ('Weights: ', linear.weight)
print ('Bias: ', linear.bias)
pred = linear(x)
print(pred)<jupyter_output>Variable containing:
 0.2737 -0.6398
-0.4750 -1.1317
 0.9033 -0.2348
-0.6145 -1.1746
 0.9758 -0.1925
[torch.FloatTensor of size 5x2]
{'fraction_non_alphanumeric': 0.1517423908248787, 'fraction_numerical': 0.1627701808557565, 'mean_word_length': 3.581818181818182, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '510466', 'license': 'MIT', 'n_tokens_mistral': 1174, 'n_tokens_neox': 967, 'n_words': 242, 'path': '03 Diving into PyTorch.ipynb', 'repo_name': 'vihar/torched', 'size': '2267'}