This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test the Model | |
correct = 0 | |
total = 0 | |
total_test_data = len(newsgroups_test.target) | |
batch_x_test,batch_y_test = get_batch(newsgroups_test,0,total_test_data) | |
articles = Variable(torch.FloatTensor(batch_x_test)) | |
labels = Variable(torch.LongTensor(batch_y_test)) | |
outputs = net(articles) | |
_, predicted = torch.max(outputs.data, 1) | |
total += labels.size(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Train the Model | |
for epoch in range(num_epochs): | |
total_batch = int(len(newsgroups_train.data)/batch_size) | |
for i in range(total_batch): | |
batch_x,batch_y = get_batch(newsgroups_train,i,batch_size) | |
articles = Variable(torch.FloatTensor(batch_x)) | |
labels = Variable(torch.FloatTensor(batch_y)) | |
# Forward + Backward + Optimize | |
optimizer.zero_grad() # zero the gradient buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.nn as nn | |
loss = nn.CrossEntropyLoss() | |
input = Variable(torch.randn(2, 5), requires_grad=True) | |
print(">>> batch of size 2 and 5 classes") | |
print(input) | |
target = Variable(torch.LongTensor(2).random_(5)) | |
print(">>> array of size ‘batch_size’ with the index of the maxium label for each item") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
net = OurNet(input_size, hidden_size, num_classes) | |
criterion = nn.CrossEntropyLoss() | |
optimizer = torch.optim.Adam(net.parameters(), lr=learning_rate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torch.autograd import Variable | |
import torch.nn as nn | |
import torch.nn.functional as F | |
class OurNet(nn.Module): | |
def __init__(self, input_size, hidden_size, num_classes): | |
super(Net, self).__init__() | |
self.layer_1 = nn.Linear(n_inputs,hidden_size, bias=True) | |
self.relu = nn.ReLU() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
x = torch.IntTensor([1,3,6]) | |
y = torch.IntTensor([1,1,1]) | |
result = x + y | |
print(result) | |
>>> 2 | |
>>> 4 | |
>>> 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multilayer_perceptron(input_tensor, weights, biases): | |
layer_1_multiplication = tf.matmul(input_tensor, weights['h1']) | |
layer_1_addition = tf.add(layer_1_multiplication, biases['b1']) | |
layer_1_activation = tf.nn.relu(layer_1_addition) | |
layer_2_multiplication = tf.matmul(layer_1_activation, weights['h2']) | |
layer_2_addition = tf.add(layer_2_multiplication, biases['b2']) | |
layer_2_activation = tf.nn.relu(layer_2_addition) | |
out_layer_multiplication = tf.matmul(layer_2_activation, weights['out']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, url_for, request | |
import time | |
import datetime | |
app = Flask(__name__) | |
@app.route('/') | |
def api_root(): | |
return 'Server running' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"UKWA", "children": [{"size": 2992, "name": "Business, Economy & Industry"}, {"size": 2426, "name": "Science & Technology"}, {"size": 270, "name": "Social Problems and Welfare"}, {"size": 718, "name": "Sports and Recreation"}, {"size": 3019, "name": "Society & Culture"}, {"size": 2128, "name": "Education & Research"}, {"size": 23, "name": "Popular Science"}, {"size": 743, "name": "Digital Society"}, {"size": 38, "name": "Environment"}, {"size": 26, "name": "Publishing, Printing and Bookselling"}, {"size": 101, "name": "Crime, Criminology, Police and Prisons"}, {"size": 87, "name": "Literature"}, {"size": 81, "name": "Law and Legal System"}, {"size": 52, "name": "Libraries, Archives and Museums"}, {"size": 2170, "name": "Medicine & Health"}, {"size": 123, "name": "Politics, Political Theory and Political Systems"}, {"size": 843, "name": "Company Web Sites"}, {"size": 54, "name": "Computer Science, Information Technology and Web Technology"}, {"size": 378, "name": "Travel & Tourism"}, {"size": 5319, "na |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ganttAlikeChart(){ | |
width = 800; | |
height = 600; | |
margin = {top: 20, right: 100, bottom: 20, left:100}; | |
xScale = d3.scaleTime(); | |
yScale = d3.scaleLinear(); | |
colorScale = d3.scaleLinear(); | |
xValue = d => d.date; | |
colorValue = d => d.status; | |
barHeight = 30; |