-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement MAML for adaptive regression with documentation and dependencies #34
Conversation
…s designed to learn how to quickly adapt to new tasks with minimal training data. Here's what it aims to achieve: Meta-Learning Purpose: Learn a good initialization point for neural networks Enable fast adaptation to new, unseen tasks Require minimal fine-tuning data for new tasks How it Works: Trains on a collection of related but different tasks Uses a nested optimization loop: Inner loop: Simulates adaptation to specific tasks Outer loop: Updates the meta-model to find better initial parameters Practical Applications: Few-shot learning problems Quick adaptation to new environments Transfer learning with minimal data Personalization of models with limited user data Example Use Cases: Regression tasks with different functions Classification with few examples per class Robotics with different environments Personalized recommendations with limited user interaction
…k generation This commit introduces a complete MAML implementation with the following features: - Bi-level optimization for meta-learning - Synthetic task generation with controlled complexity - Gradient clipping and skip connections for stability - Learning rate scheduling and early stopping - Comprehensive type hints and documentation Technical details: - Multi-component non-linear task generation - Adaptive noise scaling for robustness - Higher-order gradients for meta-optimization - Task-specific fast weight adaptation - Efficient batch processing with DataLoader Breaking changes: None Related issues: None
Added documentation for the model_agnostic_meta_learning.py proof of concept, highlighting its key features including: - Meta-learning architecture with skip connections - Task generation and adaptation capabilities - Visualization and analysis tools - Rapid context adaptation functionality
Reviewer's Guide by SourceryThis PR implements a Model-Agnostic Meta-Learning (MAML) system with a focus on rapid adaptation of narrative models. The implementation features a neural network architecture with skip connections, comprehensive visualization tools, and robust training components. The code is well-structured with detailed documentation and includes both the core MAML implementation and supporting utilities for task generation and analysis. Sequence diagram for meta-training stepsequenceDiagram
participant MetaModelGenerator
participant TaskBatch
participant Device
participant FastWeights
participant MetaOptimizer
participant Scheduler
MetaModelGenerator->>TaskBatch: Get task batch
loop for each task in task_batch
MetaModelGenerator->>FastWeights: Clone parameters
loop Inner loop steps
FastWeights->>MetaModelGenerator: forward_with_fast_weights(support_x)
MetaModelGenerator->>FastWeights: Compute gradients
FastWeights->>FastWeights: Update fast weights
end
FastWeights->>MetaModelGenerator: forward_with_fast_weights(query_x)
MetaModelGenerator->>MetaOptimizer: Accumulate meta-gradients
end
MetaOptimizer->>MetaModelGenerator: Apply meta-update
MetaModelGenerator->>Scheduler: Step with avg_loss
Class diagram for MetaModelGeneratorclassDiagram
class MetaModelGenerator {
+int input_size
+List~int~ hidden_sizes
+int output_size
+float inner_lr
+float meta_lr
+Linear input_layer
+ModuleList hidden_layers
+Linear output_layer
+SGD meta_optimizer
+ReduceLROnPlateau scheduler
+forward(torch.Tensor) torch.Tensor
+meta_train_step(List~Tuple~torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor~~, torch.device) Tuple~float, float~
+forward_with_fast_weights(torch.Tensor, Dict~str, torch.Tensor~) torch.Tensor
+compute_metrics(torch.Tensor, torch.Tensor) Dict~str, float~
+visualize_adaptation(torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, Dict~str, torch.Tensor~, str) void
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:
Overall Comments:
- The extracted visualization helper methods need cleanup - there are duplicate methods with TODO comments that should be properly refactored into a single well-named utility function.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…k generation This commit adds the implementation of model-agnostic meta-learning (MAML) with synthetic task generation. The code changes include the addition of a sequence diagram that illustrates the process of generating meta-models, task batches, and performing fast weight updates. This implementation allows the system to quickly adapt to new narrative contexts with minimal data, making it valuable for modeling emerging story dynamics.
Added documentation for the model_agnostic_meta_learning.py proof of concept,
highlighting its key features including:
Summary by Sourcery
Introduce a Model-Agnostic Meta-Learning (MAML) implementation for rapid adaptation in narrative modeling, complete with documentation and necessary dependencies.
New Features:
Build:
Documentation: