Bird
Raised Fist0

People You May Know - Graph-Based Link Prediction

SYSTEM-DESIGNhardInterview freq: high
Choose your preparation mode6 modes available
⚖️
Graph Neural Networks (GNNs) vs Collaborative Filtering

For a social network's 'People You May Know' feature, would you use Graph Neural Networks or Collaborative Filtering? Justify your choice.

📊
Comparison
DimensionGraph Neural Networks (GNNs)Collaborative Filtering
Accuracy on large graphsHighMedium
Training speedLowHigh
Inference latencyMediumHigh
ScalabilityHighMedium
Cold start handlingMediumLow
✅
Verdict
Default to collaborative filtering for smaller, dense datasets with limited compute. Switch to GNNs when dealing with large, dynamic graphs with rich node features and available GPU resources.
💡
Key Insight
Graph Neural Networks excel in capturing complex graph structures, but collaborative filtering remains efficient for smaller, dense datasets.
⚠️
Interview Trap
❌ Wrong: Always use GNNs because they are state-of-the-art for graph data.
Ignoring the computational cost and complexity of GNNs for smaller or less dynamic datasets.
✅ Consider the graph size, node feature richness, and computational resources before choosing GNNs over collaborative filtering.
Graph Neural Networks (GNNs)
"Captures complex node relationships and graph structures effectively."
  • High computational cost, especially with large graphs.
  • Requires significant memory for large-scale graphs.
  • Complex to implement and tune compared to simpler models.
  • Longer inference times due to graph traversal and aggregation.
Ideal When
  • n > 1M nodes and edges, indicating a large graph structure.
  • When node features are rich and informative.
  • When you have access to GPUs for training.
  • When the graph structure is dynamic and frequently updated.
Pinterest uses GNNs for their 'People You May Know' feature to leverage rich user interaction data and graph structures.
Collaborative Filtering
"Efficiently captures user-item interaction patterns with lower computational cost."
  • Struggles with cold start problem for new users or items.
  • Does not leverage graph structure or node features.
  • Limited to user-item interaction data, ignoring other graph data.
  • Less effective when interactions are sparse.
Ideal When
  • n < 100K users/items, indicating a smaller dataset.
  • When interaction data is dense and well-defined.
  • When computational resources are limited.
  • When the graph structure is static or less important.
Netflix uses collaborative filtering for movie recommendations, leveraging user-item interaction data.
🐍
Graph Neural Networks (GNNs) - Example
▼ Show
Python
import torch
from torch_geometric.nn import GCNConv

class GNN(torch.nn.Module):
    def __init__(self, in_channels, out_channels):
        super(GNN, self).__init__()
        self.conv1 = GCNConv(in_channels, 16)
        self.conv2 = GCNConv(16, out_channels)

    def forward(self, x, edge_index):
        x = self.conv1(x, edge_index).relu()
        x = self.conv2(x, edge_index)
        return x
🐍
Collaborative Filtering - Example
▼ Show
Python
from surprise import SVD, Dataset, Reader

data = Dataset.load_builtin('ml-100k')
trainset = data.build_full_trainset()

algo = SVD()
algo.fit(trainset)

uid = str(196)
iid = str(302)
prediction = algo.predict(uid, iid)
print(prediction.est)
✅
Use Graph Neural Networks (GNNs) When
  • •n > 1M nodes and edges and you have GPU access.
  • •Node features are rich and informative.
  • •Graph structure is dynamic and frequently updated.
✅
Use Collaborative Filtering When
  • •n < 100K users/items and interaction data is dense.
  • •Computational resources are limited.
  • •Graph structure is static or less important.
↳
Nuances
  • For small, dense interaction datasets, collaborative filtering can outperform GNNs due to simplicity and efficiency.
  • GNNs can leverage node features and graph structure, which collaborative filtering ignores.
  • In dynamic graphs with frequent updates, GNNs can adapt better than collaborative filtering.

Practice

(1/5)
1. In the context of anomaly detection, which of the following best describes the primary advantage of using an Isolation Forest over an Autoencoder?
easy
A. Isolation Forests require labeled data for training.
B. Isolation Forests are more suitable for detecting anomalies in time-series data.
C. Isolation Forests can handle high-dimensional data better than Autoencoders.
D. Isolation Forests are more interpretable and require less feature engineering.

Solution

  1. Step 1: Understand the strengths of Isolation Forests.

    Isolation Forests are known for their simplicity and interpretability, as they isolate anomalies by randomly selecting a feature and then randomly selecting a split value between the maximum and minimum values of that feature.
  2. Step 2: Eliminate wrong options.

    Isolation Forests require labeled data for training. is incorrect because Isolation Forests do not require labeled data. Isolation Forests can handle high-dimensional data better than Autoencoders. is incorrect because Autoencoders are generally better suited for high-dimensional data. Isolation Forests are more suitable for detecting anomalies in time-series data. is incorrect because Isolation Forests are not inherently designed for time-series data.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Isolation Forests = simplicity and less feature engineering [OK]
Hint: Isolation Forests = simplicity and less feature engineering [OK]
Common Mistakes:
2. For a Guardrails System in LLMs, which metric is most appropriate to evaluate the effectiveness of content moderation?
easy
A. F1 Score
B. Precision
C. Recall
D. Accuracy

Solution

  1. Step 1: Understand the importance of balance

    F1 Score balances precision and recall, crucial for content moderation.
  2. Step 2: Eliminate wrong options

    Accuracy doesn't account for class imbalance, precision alone ignores false negatives, and recall alone ignores false positives.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    F1 Score balances precision and recall. [OK]
Hint: F1 Score balances precision and recall. [OK]
Common Mistakes:
3. For a spam detection system, which metric is most appropriate to optimize for?
easy
A. F1 Score
B. Precision
C. Recall
D. Accuracy

Solution

  1. Step 1: Understand the importance of balancing precision and recall

    F1 Score balances precision and recall, which is crucial in spam detection.
  2. Step 2: Eliminate less balanced metrics

    Accuracy (A) can be misleading with imbalanced data. Precision (B) and Recall (C) alone don't balance false positives and negatives.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    F1 balances precision and recall. [OK]
Hint: F1 balances precision and recall. [OK]
Common Mistakes:
4. As the number of concurrent users increases tenfold, which component of the LLM serving infrastructure is most likely to become a bottleneck first?
hard
A. Network bandwidth
B. Batching mechanism
C. Speculative Decoding
D. KV Cache

Solution

  1. Step 1: Consider the impact of scaling.

    Network bandwidth is often the first bottleneck as user requests increase.
  2. Step 2: Eliminate wrong options.

    Batching can handle more requests efficiently. KV Cache scales with memory, not users. Speculative Decoding affects processing, not network.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Network bandwidth limits scale first. [OK]
Hint: Network bandwidth limits scale first. [OK]
Common Mistakes:
5. As the user base of an ML platform grows 10x, which component is most likely to become a bottleneck first?
hard
A. Model Training Pipeline
B. Feature Store
C. Serving Infrastructure
D. Data Ingestion Pipeline

Solution

  1. Step 1: Consider the impact of scaling on each component.

    Serving Infrastructure is directly impacted by increased user requests, making it a likely bottleneck.
  2. Step 2: Eliminate wrong options.

    Model Training and Data Ingestion are less affected by user growth, and Feature Store scales with data, not users.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Serving scales with user requests. [OK]
Hint: Serving scales with user requests. [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard