Neural Network Neural Network Applications and Frameworks 1 — Questions and Answers
Question 1: What is PyTorch's dynamic computational graph and how does it differ from TensorFlow 1.x's static graph?
- PyTorch builds the graph incrementally during execution; TensorFlow 1.x required defining the full graph before running (Correct answer)
- PyTorch uses less memory; TensorFlow is faster at inference
- PyTorch only supports CPU; TensorFlow supports GPU
- PyTorch uses symbolic differentiation; TensorFlow uses numerical
Correct answer: PyTorch builds the graph incrementally during execution; TensorFlow 1.x required defining the full graph before running
PyTorch uses define-by-run (eager execution) building the graph dynamically during forward pass, enabling flexible debugging; TensorFlow 1.x required define-and-run with the full graph declared upfront.
Question 2: What is the purpose of the `nn.Module` class in PyTorch?
- To load pretrained model weights from disk
- To serve as the base class for all neural network modules, managing parameters and forward computation (Correct answer)
- To define the training loop and optimizer steps
- To handle GPU memory allocation for tensors
Correct answer: To serve as the base class for all neural network modules, managing parameters and forward computation
nn.Module is PyTorch's base class for all neural network components, providing parameter tracking, state dict saving/loading, and a forward() method to define computation.
Question 3: In TensorFlow/Keras, what does model.compile() configure?
- The model's layers and architecture
- The optimizer, loss function, and evaluation metrics for training (Correct answer)
- The input and output tensor shapes
- The hardware device (CPU/GPU) for training
Correct answer: The optimizer, loss function, and evaluation metrics for training
model.compile() in Keras sets up the optimizer, loss function, and metrics that will be used during model.fit() training, preparing the model for the training loop.
Question 4: What is ONNX (Open Neural Network Exchange) used for?
- An open-source framework for training neural networks
- A standard format for representing deep learning models enabling interoperability between frameworks (Correct answer)
- A tool for visualizing neural network architectures
- A dataset format for neural network benchmarking
Correct answer: A standard format for representing deep learning models enabling interoperability between frameworks
ONNX provides an open format for neural network models, allowing models trained in PyTorch, TensorFlow, or other frameworks to be exported and run in different inference runtimes.
Question 5: What is TensorBoard primarily used for?
- Deploying models to production servers
- Visualizing training metrics, model graphs, embeddings, and other diagnostics during training (Correct answer)
- Compiling model code to native binaries
- Managing distributed training across multiple GPUs
Correct answer: Visualizing training metrics, model graphs, embeddings, and other diagnostics during training
TensorBoard is a visualization toolkit for TensorFlow (and PyTorch via SummaryWriter) that displays training curves, model architecture graphs, weight histograms, and embedding projections.
Question 6: What is the difference between model inference and model training in the context of neural networks?
- Inference uses different hardware than training always
- Training updates weights via backpropagation; inference runs a forward pass only to produce predictions (Correct answer)
- Inference requires labeled data; training does not
- Training uses smaller batch sizes than inference
Correct answer: Training updates weights via backpropagation; inference runs a forward pass only to produce predictions
Training involves both forward passes and backward passes to update weights; inference only performs the forward pass to generate predictions from learned weights, requiring no gradient computation.
What is PyTorch's dynamic computational graph and how does it differ from TensorFlow 1.x's static graph?