TensorFlow Flashcards

(19 cards)

1
Q

how do I import numpy and tensorflow to python

A

import numpy as np
import tensorflow as tf

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

how do we tell tensorflow to compute the grandient descent

A

with tf.GradientTape() as tape:

this will do the backprop and the gradients but in reverse

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

what is the main part of tensorflow code

A

the main part is the cost function, that is the thing we’ll try to optimize

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

what is GradientTape doing

A

is recording the computational graph to then do the same backwards for back propagation

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

what is a tf.Tensor

A

this is the equivalent to an Array in numpy which contains information about the computational graph

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

how do we store the state of the variables in TensorFlow

A

with tf.Variable, also it has an argument for dtype

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

what’s the name of the datasets in TensorFlow

A

HDF5

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

how can we know the shape and dtype of a dataset in TensorFlow

A

using the element_spect attribute

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

how do we input a new image or input into a tensor dataset

A

it must be changed and normalized with some functions to a tensor structure, for example in the case of an image:
def normalize(image):
image = tf.cast(image, tf.float32) /255
image = tf.reshape(image, [-1,])
return image

and now after finishing we can return the image that is now normalized and reshaped

Then after doing that, we use the map method in tensorflow for the whole dataset, for example:
new_train = x_train.map(normalize)
new_test = x_test.map(normalize)

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

in the following equation, which ones are matrices and which ones vectors
Y = WX + b

A

W and X are matrices and b is a vector
all of them are random

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

how do we create variables and constants in tensorflow

A

with tf.constant()
and tf.Variable()

In both cases we need to state first the shape and then the name.

Variables can be changed but constants cannot be changed

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

how can I cast z into a tensor of type float32

A

tf.cast(z, tf.float32)

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

how do I implement sigmoid or softmax in tensorflow

A

If I have for example z and want an activation using sigmoid or softmax, I can use
tf.keras.activations.sigmoid(z)
or
tf.keras.activations.softmax(z)

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

what is a one hot encoding

A

is when a vector for example [1 2 3 0 2 1] is turned into a converted representation of 0 and 1 in which each column represents one of the number but only one of the rows what represent the classes has a 1 per column

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

how can we do a one hot encoding in tensorflow

A

tf.one_hot(labels, depth, axis=0)
axis = 0 indicates the new axis is created at dimension 0

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

how do we initialize with zeros or ones in tensorflow

A

tf.zeros()
tf.ones()

16
Q

What is a Glorot initializer

A

it’s an initializer in which we sample from the normal distribution centered at 0 but truncated

17
Q

how do we use an initializer in tensor flow

A

the easiest way to do it is to just assign as a variable the initializer like this
initializer = tf.keras.initializers.GlorotNormal(seed=1) or similar

so then when creating a variable we can do the following:
tf.Variable(initializer(shape = (32,1) ) )
basically we put inside () of the tf.Variable what we want and in this case we want to use the initializer using the specific function so we just provide the shape

18
Q

what are the steps to build a neural network using tensorflow

A

we have to do 2 things:
1. implement the forward propagation
2. retrieve the gradients and train the model