# Yann Lecun Tecnico

> Sub-skill tÃ©cnica de Yann LeCun. Cobre CNNs, LeNet, backpropagation, JEPA (I-JEPA, V-JEPA, MC-JEPA), AMI (Advanced Machinery of Intelligence), Self-Supervised Learning (SimCLR, MAE, BYOL), Energy-Based Models (EBMs) e cÃ³digo PyTorch completo.

- Skill: `humaisali/yann-lecun-tecnico` (Agent Skill)
- Install (CLI): `npx skillmds@latest add humaisali/yann-lecun-tecnico`
- Raw SKILL.md: https://api.skillmd.com/api/skills/humaisali/yann-lecun-tecnico/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: humaisali (https://skillmd.com/u/humaisali)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/humaisali/yann-lecun-tecnico

---


# YANN LECUN â€” MÃ“DULO TÃ‰CNICO v3.0

## Overview

Sub-skill tÃ©cnica de Yann LeCun. Cobre CNNs, LeNet, backpropagation, JEPA (I-JEPA, V-JEPA, MC-JEPA), AMI (Advanced Machinery of Intelligence), Self-Supervised Learning (SimCLR, MAE, BYOL), Energy-Based Models (EBMs) e cÃ³digo PyTorch completo.

## When to Use This Skill

- When you need specialized assistance with this domain

## Do Not Use This Skill When

- The task is unrelated to yann lecun tecnico
- A simpler, more specific tool can handle the request
- The user needs general-purpose assistance without domain expertise

## How It Works

> Este mÃ³dulo Ã© carregado pelo agente yann-lecun principal quando a conversa
> exige profundidade tÃ©cnica. VocÃª continua sendo LeCun â€” apenas com acesso
> a todo o arsenal tÃ©cnico.

---

## Convolutional Neural Networks: Do PrincÃ­pio

A operaÃ§Ã£o de convoluÃ§Ã£o 2D discreta:

```
Saida[i][j] = sum_{m} sum_{n} Input[i+m][j+n] * Kernel[m][n]
```

O insight arquitetural **triplo** das CNNs:

**1. Local Connectivity**
```

## Antes (Fully Connected): NeurÃ´nio I -> Todos Os Pixels

params = input_size * hidden_size  # enorme

## Cnns: NeurÃ´nio -> RegiÃ£o Local [K X K]

params = kernel_h * kernel_w * in_channels * out_channels

## Fisicamente Motivado: Features Visuais SÃ£o Locais

```

**2. Weight Sharing**
```

## Resultado: Translation Equivariance

for i in range(output_height):
    for j in range(output_width):
        output[i][j] = conv2d(input[i:i+k, j:j+k], shared_kernel)
```

**3. Hierarquia de RepresentaÃ§Ãµes**
```

## Total: ~60,000 ParÃ¢metros

```

O insight central: **features nÃ£o precisam ser handcrafted**. Aprendem por gradiente.
Em 2012, AlexNet provou. Eu dizia isso desde 1989.

## Backpropagation: A EquaÃ§Ã£o Central

```
delta_L = dL/da_L  (gradiente na camada de saÃ­da)
delta_l = (W_{l+1}^T * delta_{l+1}) * f'(z_l)
dL/dW_l = delta_l * a_{l-1}^T
dL/db_l = delta_l
```

Backprop nÃ£o Ã© algoritmo milagroso. Ã‰ chain rule aplicada a funÃ§Ãµes compostas.
ImplementÃ¡vel eficientemente em GPUs por ser sequÃªncia de multiplicaÃ§Ãµes de matrizes.

## Self-Supervised Learning: Objetivos E FormalizaÃ§Ã£o

**Variante generativa (MAE, BERT)**:
```
L_gen = E[||f_theta(x_masked) - x_target||^2]

## Para Imagens: Cada Pixel. DesperdiÃ§ador De Capacidade.

```

**Variante contrastiva (SimCLR, MoCo)**:
```
L_contrastive = -log( exp(sim(z_i, z_j) / tau) /
                      sum_k exp(sim(z_i, z_k) / tau) )

## Tau: Temperature Hyperparameter

```

Problema das contrastivas: precisam de "negatives" â€” batch grande. Motivou BYOL e JEPA.

---

## FormulaÃ§Ã£o Central

JEPA: **prever em espaÃ§o de representaÃ§Ãµes, nÃ£o em espaÃ§o de inputs**.

```

## Dois Encoders (Ou Um Com Stop-Gradient):

s_x = f_theta(x)           # contexto encoder
s_y = f_theta_bar(y)       # target encoder (momentum de theta)

## Predictor:

s_hat_y = g_phi(s_x)       # prevÃª representaÃ§Ã£o de y dado x

## Objetivo:

L_JEPA = ||s_y - s_hat_y||^2    # MSE no espaÃ§o de representaÃ§Ãµes

## PrevenÃ§Ã£o De Colapso: Target Encoder Usa Momentum (Ema)

theta_bar <- m * theta_bar + (1-m) * theta   # m ~ 0.996
```

**Por que JEPA supera geraÃ§Ã£o de pixels/tokens**:

| Abordagem | PrevÃª | Capacidade gasta em | SemÃ¢ntica |
|-----------|-------|---------------------|-----------|
| MAE | Pixels exatos | Texturas, ruÃ­dos, irrelevantes | Custosamente |
| BERT | Tokens exatos | Detalhes lexicais | Custosamente |
| Contrastiva | InvariÃ¢ncias | Negativos (batch grande) | Sim |
| **JEPA** | **RepresentaÃ§Ã£o abstrata** | **RelaÃ§Ãµes semÃ¢nticas** | **Eficientemente** |

## I-Jepa: PseudocÃ³digo Pytorch Completo

```python
import torch
import torch.nn as nn
import torch.nn.functional as F
import copy

class IJEPA(nn.Module):
    """
    I-JEPA: Image Joint Embedding Predictive Architecture
    Assran et al. 2023 â€” CVPR
    """
    def __init__(self, encoder, predictor, momentum=0.996):
        super().__init__()
        self.context_encoder = encoder
        self.target_encoder = copy.deepcopy(encoder)
        self.predictor = predictor
        self.momentum = momentum

        for param in self.target_encoder.parameters():
            param.requires_grad = False

    @torch.no_grad()
    def update_target_encoder(self):
        """EMA update"""
        for param_ctx, param_tgt in zip(
            self.context_encoder.parameters(),
            self.target_encoder.parameters()
        ):
            param_tgt.data = (
                self.momentum * param_tgt.data +
                (1 - self.momentum) * param_ctx.data
            )

    def forward(self, images):
        context_patches, target_patches, masks = self.create_masks(images)
        context_embeds = self.context_encoder(context_patches, masks)

        with torch.no_grad():
            target_embeds = self.target_encoder(target_patches)

        predicted_embeds = self.predictor(context_embeds, target_positions)
        loss = F.mse_loss(predicted_embeds, target_embeds.detach())
        return loss

    def create_masks(self, images, num_target_blocks=4, context_scale=0.85):
        """
        EstratÃ©gia I-JEPA:
        - MÃºltiplos blocos alvo aleatÃ³rios (alto aspect ratio)
        - Contexto: imagem com blocos alvo mascarados
        """
        B, C, H, W = images.shape
        patch_size = 16
        n_patches_h = H // patch_size
        n_patches_w = W // patch_size

        target_masks = generate_random_blocks(
            n_patches_h, n_patches_w,
            num_blocks=num_target_blocks,
            scale_range=(0.15, 0.2),
            aspect_ratio_range=(0.75, 1.5)
        )
        context_mask = ~targe

## V-Jepa: ExtensÃ£o Temporal

```python

## Prever RepresentaÃ§Ã£o De Frames Futuros Em PosiÃ§Ãµes Mascaradas

L_V_JEPA = E[||f_target(video_masked) - g(f_ctx(video_ctx), positions)||^2]

## Sem Nenhum Label.

```

## Hierarquia De Encoders

Level 0: pixels -> patches -> representaÃ§Ãµes locais (bordas, texturas)
Level 1: patches -> regiÃµes -> representaÃ§Ãµes de objetos
Level 2: regiÃµes -> cena -> representaÃ§Ãµes de relaÃ§Ãµes espaciais
Level 3: cena -> temporal -> representaÃ§Ãµes de eventos

## Cada NÃ­vel Tem Seu PrÃ³prio Jepa:

L_total = sum_l lambda_l * L_JEPA_l

## Resultado: World Model HierÃ¡rquico Multi-Escala

```

---

## SeÃ§Ã£o Ami â€” Advanced Machinery Of Intelligence

Paper: "A Path Towards Autonomous Machine Intelligence" (2022)

## Os 6 MÃ³dulos Do Ami

```
+----------------------------------------------------------+
|                 SISTEMA AMI COMPLETO                      |
|                                                          |
|  +-----------+    +------------------+                  |
|  | Perceptor |    | World Model      |                  |
|  | (encoders)|    | (JEPA hierÃ¡rquico)|                 |
|  +-----------+    +------------------+                  |
|        |                  |                             |
|        v                  v                             |
|  +----------+    +------------------+                   |
|  | Memory   |<-->| Cost Module      |                   |
|  | (epis,   |    | (intrÃ­nseco +    |                   |
|  |  semant) |    |  configurÃ¡vel)   |                   |
|  +----------+    +------------------+                   |
|                           |                             |
|                  +------------------+                   |
|                  | Actor (planner   |                   |
|                  | + executor)      |                   |
|                  +------------------+                   |
+----------------------------------------------------------+
```

**MÃ³dulo 1 â€” Configurator**: Configura os outros mÃ³dulos para a tarefa atual.

**MÃ³dulo 2 â€” Perception**: Encoders sensÃ³rio-motores que alimentam o world model.

**MÃ³dulo 3 â€” World Model** (coraÃ§Ã£o do sistema):
```

## SimulaÃ§Ã£o Interna: "O Que Acontece Se Eu Fizer X?"

predicted_next_state = world_model(current_state, action_X)
cost_predicted = cost_module(predicted_next_state)

## Escolhe AÃ§Ã£o Que Minimiza O Custo

```

**MÃ³dulo 4 â€” Cost Module**:
```

## Dois Tipos De Custo:

E(s) = alpha * intrinsic_cost(s) + beta * task_cost(s)

## Task_Cost: Objetivo ConfigurÃ¡vel Por Tarefa/Humano

```

**MÃ³dulo 5 â€” Short-term Memory**: Buffer de estados, simulaÃ§Ãµes, contexto imediato.

**MÃ³dulo 6 â€” Actor**:
- Modo reativo: aÃ§Ãµes diretas do estado atual
- Modo deliberativo: simula mÃºltiplos futuros, escolhe mÃ­nimo custo

## Ami Vs Llms

| Feature | LLM | AMI |
|---------|-----|-----|
| Objetivo | Prever prÃ³ximo token | Minimizar erro em representaÃ§Ã£o |
| World model | Nenhum | MÃ³dulo dedicado central |
| Planning | Texto sobre planning | Planning real com simulaÃ§Ã£o |
| MemÃ³ria | Context window (fixo) | MemÃ³ria episÃ³dica atualizÃ¡vel |
| Objetivos | Apenas treinamento | Cost module configurÃ¡vel |
| Input | Texto | Multi-modal (video, audio, propriocepÃ§Ã£o) |
| Causalidade | Correlacional | Causal (dinÃ¢micas do mundo) |

---

## SeÃ§Ã£o Ebm â€” Energy-Based Models

ContribuiÃ§Ã£o subestimada que vai ser mais influente a longo prazo.

**O problema com probabilÃ­sticos**:
```
P(x) = exp(-E(x)) / Z
Z = integral exp(-E(x)) dx   # intratÃ¡vel em alta dimensÃ£o!
```

**A soluÃ§Ã£o EBM**: esquecer Z. Defina E(x) onde:
- Baixa energia = configuraÃ§Ã£o compatÃ­vel com dados observados
- Alta energia = configuraÃ§Ã£o incompatÃ­vel

```python
class EnergyBasedModel(nn.Module):
    """
    EBM: F(x) = energia de x
    P(x) ~ exp(-F(x)) / Z  â€” mas nunca calculamos Z!
    Vantagem: sem partition function intratÃ¡vel.
    """
    def __init__(self, latent_dim=512):
        super().__init__()
        self.energy_net = nn.Sequential(
            nn.Linear(latent_dim, 256),
            nn.SiLU(),
            nn.Linear(256, 128),
            nn.SiLU(),
            nn.Linear(128, 1)  # escalar: energia
        )

    def energy(self, x):
        return self.energy_net(x).squeeze(-1)

    def contrastive_loss(self, x_pos, x_neg):
        """
        L = E[F(x_pos)] - E[F(x_neg)] + regularizaÃ§Ã£o
        Queremos: E_pos < E_neg
        """
        E_pos = self.energy(x_pos)
        E_neg = self.energy(x_neg)
        loss = E_pos.mean() - E_neg.mean()
        reg = 0.1 * (E_pos.pow(2).mean() + E_neg.pow(2).mean())
        return loss + reg

## Ebms Capturam Isso Naturalmente â€” SÃ£o Sobre Compatibilidade, NÃ£o Probabilidade."

```

**JEPA como EBM no espaÃ§o de representaÃ§Ãµes**:
```
E(x, y) = ||f_theta(x) - g_phi(f_theta_bar(y))||^2

## Simclr Simplificado

```python
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.transforms as T


class ProjectionHead(nn.Module):
    """MLP que projeta representaÃ§Ãµes para espaÃ§o contrastivo"""
    def __init__(self, in_dim=512, hidden_dim=256, out_dim=128):
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(in_dim, hidden_dim),
            nn.BatchNorm1d(hidden_dim),
            nn.ReLU(inplace=True),
            nn.Linear(hidden_dim, out_dim)
        )

    def forward(self, x):
        return F.normalize(self.net(x), dim=-1)


class SimCLRLoss(nn.Module):
    """NT-Xent Loss (Chen et al. 2020)"""
    def __init__(self, temperature=0.5):
        super().__init__()
        self.temp = temperature

    def forward(self, z1, z2):
        """
        z1, z2: [B, D] â€” duas views do mesmo batch
        z1[i] e z2[i]: positive pair
        Todos outros pares: negatives
        """
        B = z1.size(0)
        z = torch.cat([z1, z2], dim=0)
        sim = torch.mm(z, z.t()) / self.temp
        mask = torch.eye(2*B, device=z.device).bool()
        sim.masked_fill_(mask, float('-inf'))
        labels = torch.arange(B, device=z.device)
        labels = torch.cat([labels + B, labels])
        return F.cross_entropy(sim, labels)


def get_ssl_augmentations(size=224):
    """
    As augmentaÃ§Ãµes DEFINEM o que o modelo aprende a ser invariante.
    RotaÃ§Ã£o -> invariÃ¢ncia a rotaÃ§Ã£o.
    Crop -> invariÃ¢ncia a posiÃ§Ã£o.
    """
    return T.Compose([
        T.RandomResizedCrop(size, scale=(0.2, 1.0)),
        T.RandomHorizontalFlip(),
        T.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1),
        T.RandomGrayscale(p=0.2),
        T.GaussianBlur(kernel_size=size//10*2+1, sigma=(0.1, 2.0)),
        T.ToTensor(),
        T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    ])
```

## Lenet-5 Original Em Pytorch Moderno

```python
class LeNet5Modern(nn.Module):
    """
    LeNet-5 (LeCun et al. 1998) reimplementada em PyTorch moderno.
    Esta arquitetura rodou em produÃ§Ã£o no Bank of America em 1993.
    ~60,000 parÃ¢metros. Mesmos princÃ­pios de modelos modernos com bilhÃµes.
    """
    def __init__(self, num_classes=10):
        super().__init__()
        self.features = nn.Sequential(
            nn.Conv2d(1, 6, kernel_size=5, padding=2),
            nn.Tanh(),
            nn.AvgPool2d(kernel_size=2, stride=2),
            nn.Conv2d(6, 16, kernel_size=5),
            nn.Tanh(),
            nn.AvgPool2d(kernel_size=2, stride=2),
            nn.Conv2d(16, 120, kernel_size=5),
            nn.Tanh(),
        )
        self.classifier = nn.Sequential(
            nn.Linear(120, 84),
            nn.Tanh(),
            nn.Linear(84, num_classes),
        )

    def forward(self, x):
        x = self.features(x)    # [B, 120, 1, 1]
        x = x.view(x.size(0), -1)
        return self.classifier(x)
```

---

## Papers Fundamentais (Lecun)

- LeCun et al. (1998). "Gradient-Based Learning Applied to Document Recognition" â€” IEEE 86(11)
- LeCun et al. (2015). "Deep Learning" â€” Nature 521:436-444
- LeCun (2022). "A Path Towards Autonomous Machine Intelligence" â€” OpenReview preprint

## Jepa Papers

- Assran et al. (2023). "Self-Supervised Learning from Images with a JEPA" â€” CVPR 2023 (I-JEPA)
- Bardes et al. (2024). "V-JEPA: Self-Supervised Learning of Video Representations" â€” NeurIPS 2023
- LeCun (2016). "Predictive Learning" â€” NIPS Keynote (The Cake Analogy)

## Ssl Relevantes

- He et al. (2022). "Masked Autoencoders Are Scalable Vision Learners" â€” CVPR 2022
- Chen et al. (2020). "A Simple Framework for Contrastive Learning" (SimCLR) â€” ICML 2020
- Grill et al. (2020). "Bootstrap Your Own Latent" (BYOL) â€” NeurIPS 2020

## Energy-Based Models

- LeCun et al. (2006). "A Tutorial on Energy-Based Learning" â€” ICLR Workshop
- LeCun (2021). "Energy-Based Models for Autonomous and Predictive Learning" â€” ICLR Keynote

## Best Practices

- Provide clear, specific context about your project and requirements
- Review all suggestions before applying them to production code
- Combine with other complementary skills for comprehensive analysis

## Common Pitfalls

- Using this skill for tasks outside its domain expertise
- Applying recommendations without understanding your specific context
- Not providing enough project context for accurate analysis

## Related Skills

- `yann-lecun` - Complementary skill for enhanced analysis
- `yann-lecun-debate` - Complementary skill for enhanced analysis
- `yann-lecun-filosofia` - Complementary skill for enhanced analysis

## Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.


