Practice
import torch.nn as nn
import torch
class SimpleGNNLayer(nn.Module):
def __init__(self, in_features, out_features):
super(SimpleGNNLayer, self).__init__()
self.linear = nn.Linear(in_features, out_features)
def forward(self, x, adj):
return torch.matmul(adj, self.linear(x))
x = torch.randn(5, 10)
adj = torch.eye(5)
gnn_layer = SimpleGNNLayer(10, 20)
output = gnn_layer(x, adj)Solution
Step 1: Understand the operations
The linear layer transforms the input features from 10 to 20 dimensions.Step 2: Apply the adjacency matrix
The adjacency matrix is used to aggregate features, maintaining the node count.Final Answer:
Option A -> Option AQuick Check:
Linear layer changes feature dim, adj keeps node count. [check]
Solution
Step 1: Consider dataset size and model complexity.
Small datasets are prone to overfitting with complex models.Step 2: Evaluate the impact of each option.
Polynomial features (A, C) increase complexity significantly, leading to overfitting. Interaction terms (B, D) add complexity but less than polynomial features, making them more suitable for small datasets.Final Answer:
Option D -> Option DQuick Check:
Small data: prefer interaction terms to avoid overfitting. [OK]
Solution
Step 1: Analyze the graph structure
Isolated nodes can disrupt message passing, leading to poor performance.Step 2: Eliminate other causes
Overfitting, learning rate, and batch size issues would manifest differently.Final Answer:
Option D -> Option DQuick Check:
Check for isolated nodes disrupting message passing. [check]
Solution
Step 1: Identify focal loss dependency.
Focal loss requires tuning of its parameters (gamma, alpha) to be effective.Step 2: Eliminate other causes.
High learning rate and underfitting are general issues, not specific to focal loss. Dataset imbalance is assumed.Final Answer:
Option A -> Option AQuick Check:
Focal loss needs parameter tuning. [OK]
Solution
Step 1: Consider the requirements of real-time translation.
Real-time translation requires handling long-range dependencies efficiently.Step 2: Evaluate each architecture.
Use a standard RNN for its simplicity and ease of implementation. is incorrect as RNNs are slow for long sequences. Use a CNN-based model for its speed in processing sequences. is incorrect because CNNs struggle with sequence dependencies. Use a hybrid RNN-CNN model to leverage both sequence processing and speed. is incorrect as hybrid models add complexity without solving dependency issues.Final Answer:
Option D -> Option DQuick Check:
Transformers excel in long-range dependencies. [OK]
