forward-forward-learning
БесплатноБез исполняемых скриптовНе проверенHinton's Forward-Forward algorithm for local learning without backpropagation.
от plurigrid★ 73 звезды на GitHubОб этом скилле
Forward-Forward Learning
Trit: +1 (PLUS - generator) Color: Red (#D82626)
Overview
Implements Geoffrey Hinton's Forward-Forward (FF) algorithm (2022) and extensions:
- Local layer-wise learning without backpropagation
- Contrastive positive/negative data passes
- Goodness functions for layer-wise objectives
- Memory-efficient and parallelizable training
Key Papers
- The Forward-Forward Algorithm - Hinton 2022
- Self-Contrastive Forward-Forward - Nature 2025
- Distance-Forward Learning - Wu et al. 2024
- Forward Learning of GNNs - ICLR 2024
- VFF-Net - 2025
Core Concepts
Forward-Forward Algorithm
Replace backprop with two forward passes:
\text{Positive pass}: x^+ \text{ (real data)} \rightarrow \text{high goodness}
\text{Negative pass}: x^- \text{ (generated/corrupted)} \rightarrow \text{low goodness}
\text{Goodness function}: G(h) = \sum_i h_i^2 \text{ (sum of squared activations)}
\text{Layer objective}: \max G(h^+) - G(h^-) \text{ subject to threshold } \theta
Layer-wise Training
Each layer trains independently:
Layer L objective:
P(positive | h_L) = σ(G(h_L) - θ)
Loss: -log P(positive | h_L^+) - log(1 - P(positive | h_L^-))
Self-Contrastive Extension (Nature 2025)
Generate negative samples from the network itself:
x^- = \text{augment}(x^+) \text{ or } x^- = G_\phi(z) \text{ (learned generator)}
API
Python Implementation
import torch
import torch.nn as nn
import torch.nn.functional as F
class FFLayer(nn.Module):
"""Forward-Forward layer with local learning."""
def __init__(self, in_dim, out_dim, threshold=2.0):
super().__init__()
self.linear = nn.Linear(in_dim, out_dim)
self.threshold = threshold
self.optimizer = None # Set per-layer optimizer
def goodness(self, h):
"""Compute goodness: sum of squared activations."""
return (h ** 2).sum(dim=-1)
def forward(self, x, label=None):
"""Forward pass with optional label embedding."""
if label is not None:
# Embed label in first 10 dimensions (for MNIST)
x = x.clone()
x[:, :10] = 0
x[:, label] = 1
h = F.relu(self.linear(x))
return h
def train_step(self, x_pos, x_neg):
"""Local training step using FF algorithm."""
h_pos = self.forward(x_pos)
h_neg = self.forward(x_neg)
g_pos = self.goodness(h_pos)
g_neg = self.goodness(h_neg)
# Loss: positive above threshold, negative below
loss_pos = F.softplus(self.threshold - g_pos).mean()
loss_neg = F.softplus(g_neg - self.threshold).mean()
loss = loss_pos + loss_neg
self.optimizer.zero_grad()
loss.backward()
self.optimizer.step()
return loss.item(), h_pos.detach(), h_neg.detach()
class FFNetwork(nn.Module):
"""Full Forward-Forward network."""
def __init__(self, dims, threshold=2.0, lr=0.03):
super().__init__()
self.layers = nn.ModuleList([
FFLayer(dims[i], dims[i+1], threshold)
for i in range(len(dims) - 1)
])
# Per-layer optimizers
for layer in self.layers:
layer.optimizer = torch.optim.Adam(layer.parameters(), lr=lr)
def train_epoch(self, dataloader, neg_generator):
"""Train all layers for one epoch."""
total_loss = 0
for x, y in dataloader:
# Generate negative samples
x_neg = neg_generator(x, y)
# Embed labels
x_pos = self.embed_label(x, y)
x_neg = self.embed_label(x_neg, self.random_labels(y))
# Train layer by layer
h_pos, h_neg = x_pos, x_neg
for layer in self.layers:
loss, h_pos, h_neg = layer.train_step(h_pos, h_neg)
total_loss += loss
return total_loss
def predict(self, x):
"""Predict by finding label with highest goodness."""
best_label, best_goodness = None, -float('inf')
for label in range(10):
x_labeled = self.embed_label(x, label)
h = x_labeled
for layer in self.layers:
h = layer(h)
goodness = layer.goodness(h).mean()
if goodness > best_goodness:
best_label = label
best_goodness = goodness
return best_label
class SelfContrastiveFF(FFNetwork):
"""Self-Contrastive FF (Nature 2025)."""
def __in
Установить forward-forward-learning в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл forward-forward-learning?
Hinton's Forward-Forward algorithm for local learning without backpropagation.
Как установить скилл forward-forward-learning?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл forward-forward-learning запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic