Skip to content

Instantly share code, notes, and snippets.

View tehZevo's full-sized avatar
🤖
Probably trying to create AGI

tehZevo

🤖
Probably trying to create AGI
View GitHub Profile
@tehZevo
tehZevo / ae_softmax.py
Created February 9, 2021 18:32
Train an autoencoder on MNIST digits, but with a softmax latent vector. Then plot the means of digits by argmax(latent)
from keras.layers import Dense, Flatten, InputLayer, Reshape
from keras.models import Sequential
from keras.datasets import mnist
import numpy as np
import matplotlib.pyplot as plt
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x = np.concatenate([x_train, x_test]) / 255.
@tehZevo
tehZevo / gol.js
Created April 29, 2019 14:43
3D Game of Life implementation in TensorFlow.js
//mod function that handles negatives "properly"
function mod(a, b)
{
return ((a%b)+b)%b
}
//shifts a tensor n times on the given axis
function shift(x, axis, n)
{
n = mod(n, x.shape[axis]);
//this example was tested in electron; if anyone knows how to get around
//this silliness when using nodejs/electron (without including the .js file in
//html, please let me know)
var tfCore = require("@tensorflow/tfjs-core");
var tfLayers = require("@tensorflow/tfjs-layers");
var tf = Object.assign({}, tfCore, tfLayers);
var xs = tf.tensor([[0, 0], [0, 1], [1, 0], [1, 1]]);
var ys = tf.tensor([[0], [1], [1], [0]]);
@tehZevo
tehZevo / tfjs-example.js
Last active September 15, 2018 19:06
An example solving XOR problem with tfjs
var tf = require("@tensorflow/tfjs");
//code modified from:
//https://medium.com/tensorflow/a-gentle-introduction-to-tensorflow-js-dba2e5257702
//define our inputs (combinations of 2 bits, represented as 0s and 1s)
//https://js.tensorflow.org/api/0.12.0/#tensor
var xs = tf.tensor([[0, 0], [0, 1], [1, 0], [1, 1]]);
//define our outputs (xor operation, a simple non-linear problem)
@tehZevo
tehZevo / spliceTensor.js
Created June 25, 2018 02:44
TF.js spliceTensor function - facilitates easier insertion/removal of tensor chunks; functions similarly to Array.splice()
/**
original: the tensor to modify
axis: the axis to splice in
start: the position in the given axis to begin splicing from
deleteCount: how many frames to remove from the tensor
toInsert: the tensor to insert at "start" (all axes must match except for "axis")
*/
function spliceTensor(original, axis, start, deleteCount, toInsert)
{
var preStart = original.shape.map((e) => 0);