TensorFlow Basics: Graphs, Sessions, and Operations Quiz Quiz

Explore essential concepts of computational graphs, sessions, and operations in TensorFlow. This quiz assesses fundamental understanding for beginners interested in AI and machine learning architectures using TensorFlow.

  1. Definition of a Computational Graph

    Which statement best describes a computational graph in TensorFlow?

    1. A table storing all variable values in numeric format.
    2. A graphical dashboard for data visualization.
    3. A structure that represents mathematical computations as a network of nodes and edges.
    4. A database used to store all machine learning models.

    Explanation: A computational graph illustrates how operations are performed and how data flows between them, using nodes for operations and edges for data. It is not a table or a database; tables do not capture operations, and databases are used for storage, not computation. Visualization dashboards display results but do not represent computational flow directly.

  2. Understanding a TensorFlow Session

    What is the primary purpose of a session in TensorFlow (as used in earlier versions)?

    1. To define how constants are created.
    2. To convert images into tensors.
    3. To draw visual graphs for data analysis.
    4. To execute operations defined in a computational graph.

    Explanation: Sessions are primarily used to run and evaluate the operations and variables set up in a computational graph. Drawing visual graphs and creating constants are separate processes, not handled by sessions. Image conversion is an operation, but sessions do not specifically perform conversions themselves.

  3. Role of Operations in TensorFlow

    In TensorFlow, what does an operation (op) represent within a computational graph?

    1. A static dataset stored in memory.
    2. A computation or function that processes tensors.
    3. A single number stored as a float.
    4. A variable with an assigned random value.

    Explanation: Operations, or ops, act as nodes that perform computations and manipulate data in the form of tensors. A static dataset or variable is simply data, not an operation. Storing a float is too narrow and not relevant to TensorFlow ops. Assigned values belong to variables, not operations.

  4. Creating Constants Example

    Which code line best defines a constant tensor holding the value 7?

    1. x = tf.compute(7)
    2. x = tf.placeholder(7)
    3. x = tf.Variable(7)
    4. x = tf.constant(7)

    Explanation: The tf.constant function is used for creating tensors with fixed values in TensorFlow. tf.Variable is for mutable tensors, not constants. tf.placeholder is for defining inputs that are fed at runtime, not fixed values. tf.compute does not exist as a standard function.

  5. Sequence of TensorFlow Execution

    What is the correct sequence to run an operation in TensorFlow 1.x?

    1. Run session, then build graph.
    2. Define session, then build computational graph.
    3. Build computational graph, create session, run session.
    4. Assign variables, run without session.

    Explanation: The correct workflow is to first build the computational graph, next create a session, and finally execute operations within the session. Defining a session before building the graph is illogical. Running a session before the graph exists is not possible. Variables must be assigned within a session; omitting a session is not valid in TensorFlow 1.x.

  6. Tensor Data Type

    What is a tensor in the context of TensorFlow computations?

    1. A multi-dimensional array containing data.
    2. A function that manipulates sessions.
    3. A log file storing output values.
    4. A graph storing computational nodes.

    Explanation: A tensor is, by definition, a container for multi-dimensional data and is central to operations in the framework. Functions operate on tensors but are not tensors themselves. Graphs and log files are organizational elements, not data containers.

  7. Evaluating Results in a Session

    If you have a TensorFlow operation named 'add_op', how can you retrieve its result?

    1. Assign it to a variable outside of a session.
    2. Print the operation directly without a session.
    3. Run the operation within a session using session.run(add_op).
    4. Declare it as a constant.

    Explanation: Operations must be executed within a session to produce results in TensorFlow 1.x. Printing or assigning outside a session merely provides a reference to the operation, not the computational result. Declaring as constant creates a new object, not evaluating the op.

  8. Advantages of Graphs

    Why does TensorFlow use computational graphs for managing computations?

    1. To monitor hardware usage directly.
    2. To store variables permanently.
    3. To eliminate the need for any programming.
    4. To enable efficient execution, optimization, and portability.

    Explanation: Graphs provide a structured way to optimize computation and enable running the same model on various devices or platforms. They are not designed for variable storage or hardware monitoring. Programming is still necessary to define the graph.

  9. Session Closing Importance

    Why is it important to close a session after running operations in TensorFlow 1.x?

    1. To free up resources and prevent memory leaks.
    2. To reset all variables automatically.
    3. To delete the computational graph.
    4. To display all variable values.

    Explanation: Closing a session releases the resources allocated for its execution, helping to avoid memory issues. It does not delete the computational graph, nor does it reset variables or display their values; those require separate steps.

  10. Operation Example Scenario

    In TensorFlow, what does an addition operation node compute if given two input tensors: [2, 4] and [3, 5]?

    1. [2, 3, 4, 5]
    2. [5, 9]
    3. [1, -1]
    4. [6, 20]

    Explanation: The addition operation performs element-wise addition, so [2+3, 4+5] equals [5, 9]. Multiplication would yield [6, 20], which is not addition. Subtraction would result in [1, -1]. [2, 3, 4, 5] is simply a concatenation, not an elemental operation.