Editing
Meta-Learning
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== <span style="color: #FFFFFF;">Applying</span> == '''MAML implementation for few-shot classification:''' <syntaxhighlight lang="python"> import torch import torch.nn as nn from copy import deepcopy class MAML: def __init__(self, model, inner_lr=0.01, outer_lr=0.001, n_inner_steps=5): self.model = model self.inner_lr = inner_lr self.optimizer = torch.optim.Adam(model.parameters(), lr=outer_lr) self.n_inner_steps = n_inner_steps self.loss_fn = nn.CrossEntropyLoss() def inner_adapt(self, support_x, support_y): """Fast adaptation on support set (simulated fine-tuning).""" fast_model = deepcopy(self.model) fast_optimizer = torch.optim.SGD(fast_model.parameters(), lr=self.inner_lr) for _ in range(self.n_inner_steps): fast_optimizer.zero_grad() self.loss_fn(fast_model(support_x), support_y).backward() fast_optimizer.step() return fast_model def meta_update(self, episodes): """Outer loop: update ΞΈ to minimize query loss after adaptation.""" meta_loss = 0.0 for support_x, support_y, query_x, query_y in episodes: adapted = self.inner_adapt(support_x, support_y) meta_loss += self.loss_fn(adapted(query_x), query_y) self.optimizer.zero_grad() (meta_loss / len(episodes)).backward() self.optimizer.step() </syntaxhighlight> ; Meta-learning approach selection : '''Image classification, few-shot''' β Prototypical Networks (simple, effective) : '''Any architecture, gradient-based''' β MAML, FOMAML (first-order approximation) : '''NLP, few-shot''' β In-context learning with a large LLM : '''HPO automation''' β BOHB (Bayesian Optimization + Hyperband), Optuna : '''NAS''' β DARTS (gradient-based), evolutionary search </div> <div style="background-color: #8B4500; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information