Basics Flashcards

1
Q

How do you create a session?

A

sess = tf.Session()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do you need to do to use TensorFlow in Python?

A

import tensorflow as tf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a constant in TensorFlow?

A

a = tf.constant(3.0, dtype=tf.float32)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you run a TensorFlow session?

A

sess.run([node1, node2])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you print a session to the prompt?

A

print(sess.run([node1, node2])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you add values in TensorFlow?

A
c = a + b
c = tf.add(a, b)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you add inputs to TensorFlow?

A
a = tf.placeholder(tf.float32)
b = ft.placeholder(tf.float32)
c = a + b
sess.run(c, {a: 3, b: 4})
will give 7
to print to the console use
print(sess.run(c, {a: 3, b: 4}))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you multiply a and b in TensorFlow

A

c = a * b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can you stack node in TensorFlow?

A
c = a + b
d = c * 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you create a variable in TensorFlow?

A

W = tf.Variable([0.3], dtype=tf.float32)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Create a linear model with TensorFlow

A
W = tf.Variable([0.3], dtype=tf.float32)
b = tf.Variable([-0.3], dtype=tf.float32)
x = tf.placeholder(tf.float32)
linear_model = W * x + b
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you initialize variables in TensorFlow?

A

init = tf.global_variables_initializer()

sess.run(init)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can you add the contents of a vector V together in TensorFlow?

A

total = tf.reduce_sum(V)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write a MSD error function in TensorFlow.

A
y = tf.placeholder(tf.float32)
squared_deltas = tf.square(linear_model - y)
loss = tf.reduce_sum(squared_deltas)

to run the model and print the output use something like
print( sess.run( loss, { x: [1, 2, 3, 4], y: [0, -1, -2, -3] } ) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you set the value of a variable in TensorFlow?

A

fixW = tf.assign(W, [-1.0])

sess.run(fixW)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you setup a gradient descent optimizer in TensorFlow?

A
optim = tf.train.GradientDescentOptimizer(0.01)
train = optim.minimize(loss)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you run the TensorFlow optimizer once its setup?

A

sess.run(init) # reset values to defaults.
for i in range(1000):
sess.run(train, {x: [1, 2, 3, 4], y: [0, -1, -2, -3]})

print(sess.run([W, b]))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you check if a file is executable?

A

ls -la

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How can you make a file executable?

A

chmod +x fname

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How can you produce a series of equally spaced numbers with numpy?

A

x = np.linspace(-3.0, 3.0, 100)

21
Q

How can you produce a series of equally spaced numbers with TensorFlow?

A

x = tf.linspace(-3.0, 3.0, 100)

22
Q

How do you start an interactive session in TensorFlow?

A

sess = tf.InteractiveSession()

23
Q

How do you get the default graph in TensorFlow?

A

g = tf.get_default_graph()

24
Q

How can you get a list of all the operations that have been added to a graph g?

A

[op.name for op in g.get_operations()]

25
Q

How do you evaluate a tensor x?

A

computed_x = x.eval(session=sess)

26
Q

How do you set the graph for a session in TensorFlow?

A

sess = tf.Session(graph=g)

27
Q

How do you close a TensorFlow session?

A

sess.close()

28
Q

How do you create a new graph in TensorFlow?

A

g_new = tf.Graph()

29
Q

How can you get the shape of a Tensor and print it to the command line as a list?

A

print(x.get_shape().as_list())

30
Q

How do you configure python to use Pyplot?

A

import matplotlib.pyplot as plt

31
Q

How do you plot inline with iPython?

A

%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt

32
Q

How can you check to see if you can multiply 2 matrices?

A

There inner dimensions must match

A has m rows and n columns
B has n rows and p columns

The number of columns in A matches the number of rows in B.

33
Q

If you multiply two matrices what is the size and the resulting matrix?

A

If matrix A is m x n, and matrix B is n x p, the resulting matrix from A x B will have the dimensions m x p.

34
Q

What is convolution?

A

Convolution is a mathematical operation on two functions, to produce a third function.

35
Q

How can you create a 2-D Gaussian kernel?

A

A is a vector containing a normal distribution. Multiplying A by its transpose will give you a Gaussian kernel.

G = A * A’

36
Q

How do you multiply a matrix by its inverse in Tensorflow?

A

z = a normal distribution vector

ksize = z.get_shape().as_list()[0]

G = tf.matmul(tf.reshape(z, [ksize, 1])
tf.reshape(z, [1, ksize]))

37
Q

How do you create a Gabor kernel?

A

Modulate a Gaussian with a sine wave.

38
Q

How do you plot an image in python?

A

Use the pyplot library (matplotlib.pyplot)

plt.imshow(img)

39
Q

How do you load an image in python?

A

img = plt.imread(‘path_to_file’)

40
Q

How can you convert a list into an array in python?

A

data = np.array(list)

41
Q

How do you get the mean and standard deviation of a set of images?

A

Combine them into an array of image x height x width x channel

mean_img = np.mean(data, axis=0)
std_img = np.std(data, axis=0)
42
Q

How can you flatten an array into a vector in Python?

A

flattened = data.ravel()

43
Q

What are the six key ideas behind Stoicism?

A
  1. Appreciate the shortness of life
  2. Live in the present
  3. Don’t seek other peoples praise or approval
  4. There are no good or bad events, only your perception of them
  5. Identify whats in your control and whats not
  6. Find happiness in virtue
44
Q

What are the four stoic virtues?

A
  • Wisdom
  • Courage
  • Justice
  • Temperance
45
Q

What are the questions for Seneca’s evening review?

A

What bad habit did I curb today?
How am I better?
Were my actions just?
How can I improve?

46
Q

What is the difference between the L1-norm and the L2-norm?

A

These are the ‘Least Absolute Deviations’ and ‘Least Squares’ methods. Generally the L2-norm is the best for producing a stable solution. However, if the data has outliers that it is best to ignore a more robust solution may be found with the Least Absolute Deviations method.

47
Q

How do you do integer devision in Python?

A

Use the double slash
a = 4
b = 2
c = a // b

48
Q

What will np.arange(100) do in Python?

A

Create a vector of numbers from 0 to 99.

For a non-integer step size its better to use linespace.

49
Q

What are the 3 Gradient Decent methods?

A
  1. Stochastic Gradient Descent : Uses 1 example of the training data each iteration.
  2. Batch Gradient Descent : Uses all the training data examples each iteration.
  3. Mini Batch Gradient Descent : uses a subset of the training data examples each iteration.