Skip to content

Instantly share code, notes, and snippets.

View omarsar's full-sized avatar
🐙

Elvis Saravia omarsar

🐙
View GitHub Profile
NN = Neural_Network()
for i in range(1000): # trains the NN 1,000 times
print ("#" + str(i) + " Loss: " + str(torch.mean((y - NN(X))**2).detach().item())) # mean sum squared loss
NN.train(X, y)
NN.saveWeights(NN)
NN.predict()
@omarsar
omarsar / py_nn.py
Last active February 27, 2020 13:09
class Neural_Network(nn.Module):
def __init__(self, ):
super(Neural_Network, self).__init__()
# parameters
# TODO: parameters can be parameterized instead of declaring them here
self.inputSize = 2
self.outputSize = 1
self.hiddenSize = 3
# weights
# scale units
X_max, _ = torch.max(X, 0)
xPredicted_max, _ = torch.max(xPredicted, 0)
X = torch.div(X, X_max)
xPredicted = torch.div(xPredicted, xPredicted_max)
y = y / 100 # max test score is 100
print(X.size())
print(y.size())
X = torch.tensor(([2, 9], [1, 5], [3, 6]), dtype=torch.float) # 3 X 2 tensor
y = torch.tensor(([92], [100], [89]), dtype=torch.float) # 3 X 1 tensor
xPredicted = torch.tensor(([4, 8]), dtype=torch.float) # 1 X 2 tensor
import torch
import torch.nn as nn
!pip3 install torch torchvision
image_file = read_file("1kHhmo4fj5PqhpH2x_hVY6uUDgf2_G0Tn")
# create mask
alice_mask = np.array(Image.open(image_file))
# remove stopwords
stopwords = set(STOPWORDS)
stopwords.add("said")
# generate word cloud
wordcloud = WordCloud().generate(document)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
document = text_file.read()
print(len(document))
print(document[0:100])