Skip to content

Instantly share code, notes, and snippets.

View patricoferris's full-sized avatar
🌳

Patrick Ferris patricoferris

🌳
View GitHub Profile
#Our batch generator - the bias allows us to control how much of the context is from genre and how much is from score
def gen_batch(genres, scores, size, bias):
#Initialise the numpy arrays - the xs are the target words and the ys the inidividual contexts.
xs = np.ndarray(shape=(size), dtype=np.int32)
ys = np.ndarray(shape=(size, 1), dtype=np.int32)
for idx in range(size):
b = np.random.randint(10)
if b < bias:
genre = np.random.randint(len(genres))
g1 = np.random.randint(len(genres[genre_lookup[genre]]))
#Before we dive in we need to declare some variables
vocabulary_size = len(artist_lookup)
#How big we want our final vectors to be
embedding_size = 64
#The number of training samples passed per epoch
batch_size = 64
#Number of negative samples to use in NCE [see below]
num_sampled = 16
#BAND2VEC - Tensorflow Time!
#Running our Neural Network!
#First we init the session
iterations = 100000
with tf.Session(graph=graph) as sess:
#We run the initialize all global variables operation
sess.run(tf.global_variables_initializer())
average_loss = 0.0
#For all of the iterations
for index in range(iterations):
try:
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
tsne = TSNE(perplexity=30, n_components=2, verbose=1, init='pca', n_iter=500, method='exact')
plot_only = len(artist_lookup)
low_dim_embs = tsne.fit_transform(final_embeddings[:plot_only, :])
except ImportError as ex:
print('Please install sklearn, matplotlib, and scipy to show embeddings.')
function setup() {
createCanvas(640, 640);
}
function draw() {
//Updates, renders etc.
}
class Planet {
//The 'build' method
constructor(position, mass, radius, color) {
this.position = position;
//A p5 Vector
this.velocity = createVector(0, 0);
this.mass = mass;
this.radius = radius;
this.color = color;
}
class Satellite extends Planet {
constructor(position, mass, radius, color, vel) {
//Telling Planet to build a base planet for us
super(position, mass, radius, color);
//Redefining the velocity to be something we pass it (shadowing)
this.velocity = vel;
//Our new variable acceleration
this.acceleration = createVector(0, 0);
}
function centripetalForce(satellite, centre) {
//Get the direction of the force
let force = p5.Vector.sub(centre, satellite.position).normalize();
//Get the distance to centre of rotation from our satellite
let radius = p5.Vector.sub(centre, satellite.position).mag();
//The velocity squared
let velocitySquared = p5.Vector.dot(satellite.velocity, satellite.velocity);
//Pull it all together with the f = (m * v^2) / r equation
force.mult(velocitySquared);
force.mult(satellite.mass);
//Our global variables
let earth;
let moon;
let r = 225;
function setup() {
createCanvas(640, 640);
//Creating our Earth and Moon
earth = new Planet(createVector(width/2, height/2), 1000, 100, 'blue');
//Notice we're starting the moon directly 'east' to our Earth, so the initial velocity is straight upwards.
import requests
from bs4 import BeautifulSoup
import json
#Accessing the Webpage
result = requests.get('https://github.com/factbook/factbook.json')
#Getting the content of the webpage
content = result.content