Intro to tensorflow Flashcards

1
Q

Tensor and tf.constant

A
  • In TensorFlow, data isn’t stored as integers, floats, or strings. These values are encapsulated in an object called a tensor. In the case of hello_constant = tf.constant(‘Hello World!’), hello_constant is a 0-dimensional string tensor.
  • The tensor returned by tf.constant() is called a constant tensor, because the value of the tensor never changes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Tensorflow session

A
  • A “TensorFlow Session”, as shown above, is an environment for running a graph. The session is in charge of allocating the operations to GPU(s) and/or CPU(s), including remote machines
  • with tf.Session() as sess:
    output = sess.run(hello_constant)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

python with

A

with statement is actually very simple, once you understand the problem it’s trying to solve. Consider this piece of code:

    set things up
    try:
        do something
    finally:
        tear things down
Here, “set things up” could be opening a file, or acquiring some sort of external resource, and “tear things down” would then be closing the file, or releasing or removing the resource. The try-finally construct guarantees that the “tear things down” part is always executed, even if the code that does the work doesn’t finish.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

tf.placeholder()

A
  • What if you want to use a non-constant? This is where tf.placeholder() and feed_dict come into place.
  • Sadly you can’t just set x to your dataset and put it in TensorFlow, because over time you’ll want your TensorFlow model to take in different datasets with different parameters. You need tf.placeholder()!
  • tf.placeholder() returns a tensor that gets its value from data passed to the tf.session.run() function, allowing you to set the input right before the session runs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

tensor math operations

A
x = tf.add(5, 2)  # 7
x = tf.subtract(10, 4) # 6
y = tf.multiply(2, 5)  # 10
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Creating a variable in tensorflow

A
  • tf.Variable()

- To initialize call tf.global_variables_initializer()

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

Interesting functions

A
  • tf.truncated_normal()
  • tf.zeros()
  • tf.matmul()
  • tf.nn.softmax()
  • tf.reduce_sum()
  • tf.log()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly