Skip to content

Instantly share code, notes, and snippets.

View alexanderholt's full-sized avatar

alexanderholt

View GitHub Profile
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.utils import np_utils
from keras.datasets import mnist
# 2. Load pre-shuffled MNIST data into train and test sets
(X_train, y_train), (X_test, y_test) = mnist.load_data()
# 3. Preprocess input data
# create Y_predictions, in this case linear regression
Y_predictions = tf.add(b, tf.multiply(w,X))
squares = tf.square(Y - Y_predictions)
loss = tf.reduce_mean(squares, name='loss')
#gradiaent descent. pass learning rate as .01
optimizer = tf.train.GradientDescentOptimizer(0.01).minimize(loss=loss)
# create placeholder tensors
x = tf.placeholder(tf.float32, name = 'x')
y = tf.placeholder(tf.float32, name = 'y')
# create Variable tensors
w = tf.Variable(0.0, name='w')
b = tf.Variable(0.0, name='b')
import tensorflow as tf
a_list = [1, 2, 3, 4, 5]
tf.reset_default_graph
import tensorflow as tf
tf.reset_default_graph()
a = tf.constant(2, name='x')
b = tf.constant(3, name='y')
add_op = tf.add(a, b, name='add')
with tf.Session() as sess:
# add this line to use TensorBoard.
writer = tf.summary.FileWriter('./graphs', sess.graph)
print(sess.run(add_op))
# Creates a graph.
x = 2
y = 3
with tf.device('/cpu:1'):
add_op = tf.add(x, y,)
mul_op = tf.multiply(x, y)
pow_op = tf.pow(add_op, mul_op)
with tf.device('/cpu:2'):
# Now condense this a little bit
a = tf.add(4, 6)
b = tf.multiply(2, 10)
c = tf.subtract(b, 5)
with tf.Session() as sess:
added = sess.run([a, b, c])
print(added)
# How to get the value of a?
# Create a session, assign it to variable sess so we can call it later
# Within the session, evaluate the graph to fetch the value of a
a = tf.add(4, 6)
sess = tf.Session()
print(sess.run(a))
sess.close()
# How to get the value of a?
# Create a session, assign it to variable sess so we can call it later
# Within the session, evaluate the graph to fetch the value of a
a = tf.add(4, 6)
sess = tf.Session()
print(sess.run(a))
sess.close()
data['is_recipe'] = data['title'].fillna('').str.contains('recipe')
%%time
#This took me about 5 minutes
# Import the built-in logging module and configure it so that Word2Vec
# creates nice output messages
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s',\
level=logging.INFO)
# Set values for various parameters