This file contains hidden or 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 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 |
This file contains hidden or 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
| # 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) |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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 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)) |
This file contains hidden or 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
| # 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'): |
This file contains hidden or 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
| # 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) |
This file contains hidden or 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
| # 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() |
This file contains hidden or 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
| # 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() |
This file contains hidden or 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
| data['is_recipe'] = data['title'].fillna('').str.contains('recipe') |
This file contains hidden or 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
| %%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 |