Bird
Raised Fist0

Spam Detection System - Features, Models, Adversarial Robustness

SYSTEM-DESIGNmediumInterview freq: medium
Choose your preparation mode6 modes available
⚖️
Feature Engineering vs Adversarial Robustness

In designing a spam detection system, would you prioritize feature engineering or adversarial robustness? Justify your choice.

📊
Comparison
DimensionFeature EngineeringAdversarial Robustness
Model InterpretabilityHighLow
Training SpeedFastSlow
Inference LatencyLowModerate
Robustness to Adversarial AttacksLowHigh
ScalabilityModerateHigh
✅
Verdict
Default to feature engineering for spam detection systems with stable patterns and limited resources. Switch to adversarial robustness when facing frequent attacks and when resources permit ongoing maintenance.
💡
Key Insight
The choice between feature engineering and adversarial robustness hinges on the threat landscape and resource availability.
⚠️
Interview Trap
❌ Wrong: Always prioritize adversarial robustness because security is paramount.
This ignores the cost and complexity of implementing adversarial robustness in low-risk environments.
✅ Consider the threat model and resource constraints; prioritize adversarial robustness only when threats are frequent and resources allow.
Feature Engineering
"Enhances model interpretability and performance on known patterns"
  • Time-consuming and requires domain expertise
  • May not generalize well to unseen data
  • Vulnerable to adversarial attacks if features are predictable
  • Limited scalability with high-dimensional data
Ideal When
  • When n < 100K and feature count < 100
  • When domain knowledge is available and can be encoded
  • When interpretability is crucial for compliance
  • When computational resources are limited
LinkedIn uses feature engineering extensively for spam detection to leverage domain-specific insights.
Adversarial Robustness
"Improves model resilience against adversarial attacks"
  • Increases model complexity and training time
  • May reduce model interpretability
  • Requires continuous updates to counter new attack vectors
  • Higher computational cost during inference
Ideal When
  • When n > 100K and adversarial threats are frequent
  • When the system is deployed in high-stakes environments
  • When latency < 200ms is acceptable
  • When there is a dedicated team for model maintenance
Google employs adversarial robustness techniques in Gmail to protect against evolving spam tactics.
🐍
Feature Engineering - Example
▼ Show
Python
from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer(max_features=100)
X_train_tfidf = vectorizer.fit_transform(X_train)
# Use engineered features in a simple model
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train_tfidf, y_train)
🐍
Adversarial Robustness - Example
▼ Show
Python
import torch
import torch.nn as nn
# Define a simple neural network
class SpamDetector(nn.Module):
    def __init__(self):
        super(SpamDetector, self).__init__()
        self.fc = nn.Linear(100, 2)
    def forward(self, x):
        return self.fc(x)
# Apply adversarial training
model = SpamDetector()
# Assume adversarial training loop here
✅
Use Feature Engineering When
  • •When n < 100K and feature count < 100
  • •When interpretability is required for regulatory reasons
  • •When computational resources are limited
  • •When domain expertise can be leveraged effectively
✅
Use Adversarial Robustness When
  • •When n > 100K and adversarial threats are frequent
  • •When the system is deployed in high-stakes environments
  • •When latency < 200ms is acceptable
  • •When there is a dedicated team for model maintenance
↳
Nuances
  • Feature engineering can outperform adversarial robustness in environments with stable patterns and low attack frequency.
  • Adversarial robustness is crucial in dynamic threat landscapes but may not justify the cost in low-risk scenarios.
  • Feature engineering is often more interpretable, which is critical in regulated industries.
  • Adversarial robustness requires ongoing maintenance, which can be resource-intensive.

Practice

(1/5)
1. For a delivery forecasting system, which metric is most appropriate to evaluate the accuracy of ETA predictions?
easy
A. Area Under the Curve (AUC)
B. F1 Score
C. Mean Absolute Error (MAE)
D. Precision

Solution

  1. Step 1: Identify the nature of the prediction task

    ETA prediction is a regression task, focusing on continuous values.
  2. Step 2: Eliminate wrong options

    F1 Score, AUC, and Precision are classification metrics. MAE is suitable for regression tasks.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    MAE for regression accuracy. [OK]
Hint: MAE for regression accuracy. [OK]
Common Mistakes:
2. In a multimodal system that integrates vision and language models, which component is responsible for aligning the semantic meaning between image features and text embeddings?
easy
A. Cross-modal attention layer
B. Text encoder
C. Image encoder
D. Output classifier

Solution

  1. Step 1: Identify the role of each component

    The cross-modal attention layer is designed to align and integrate features from different modalities, such as images and text.
  2. Step 2: Eliminate wrong options

    Image encoder and text encoder process their respective modalities independently. The output classifier is responsible for final predictions, not alignment.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Cross-modal aligns semantics between modalities. [OK]
Hint: Cross-modal aligns semantics between modalities. [OK]
Common Mistakes:
3. In a two-stage retrieval system, what is the primary role of the candidate generation stage?
easy
A. To filter out irrelevant items from the entire dataset.
B. To rank the candidates based on relevance scores.
C. To apply complex models for precise ranking.
D. To ensure all items are considered for ranking.

Solution

  1. Step 1: Understand the candidate generation role

    The candidate generation stage is responsible for quickly filtering out irrelevant items to reduce the dataset size for the ranking stage.
  2. Step 2: Eliminate wrong options

    To rank the candidates based on relevance scores. is incorrect because ranking is done in the second stage. To apply complex models for precise ranking. is incorrect because complex models are typically used in the ranking stage. To ensure all items are considered for ranking. is incorrect because not all items are considered for ranking, only the filtered candidates.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Candidate generation filters, not ranks. [OK]
Hint: Candidate generation filters, not ranks. [OK]
Common Mistakes:
4. As the scale of users increases tenfold, which component of a bot detection system using behavioral signals is most likely to fail first?
hard
A. Real-time processing capability
B. Data storage capacity
C. Model training time
D. User interface responsiveness

Solution

  1. Step 1: Consider the impact of scale on system components.

    Real-time processing is critical for immediate detection and is resource-intensive.
  2. Step 2: Eliminate wrong options.

    Data storage can be scaled with cloud solutions; model training is periodic; UI is less critical to detection.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Real-time processing is resource-intensive at scale [OK]
Hint: Real-time processing is resource-intensive at scale [OK]
Common Mistakes:
5. As a RAG system scales to handle 10x more queries, which component is most likely to become a bottleneck first?
hard
A. The retriever model
B. The database storing the corpus
C. The encoder model
D. The generator model

Solution

  1. Step 1: Consider scaling impacts.

    As query volume increases, the database must handle more retrieval requests, potentially becoming a bottleneck.
  2. Step 2: Eliminate wrong options.

    Models scale with compute resources, but database I/O can become a limiting factor.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Database I/O limits scale. [OK]
Hint: Database I/O limits scale. [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