{
  "schemaVersion": 1,
  "id": "atlas-lesson-spatial-filter-patch-attention",
  "title": "Local filters and patch attention",
  "category": "learning",
  "format": "Atlas lesson",
  "description": "Compare fixed local receptive fields with content-weighted patch aggregation.",
  "canonicalUrl": "https://semiaifoundry.com/learn/atlas/spatial-filter-patch-attention/",
  "publishedDate": null,
  "revisionDate": "2026-10-07",
  "author": null,
  "topic": "Contrasting computational structures",
  "series": null,
  "license": null,
  "rightsUrl": "https://semiaifoundry.com/ai-atlas/licenses.html",
  "version": "1.3.0",
  "status": "Published educational lesson",
  "evidenceScope": "Authored filters and one identity-projection patch query; stride one, no padding; no trained CNN, full ViT, learned positions or recognition benchmark. Numerical settings are original teaching fixtures. The named experience executes the stated bounded algorithm; no production performance or independent human review is claimed.",
  "contentCoverage": "published-lesson",
  "artifactUrl": "https://semiaifoundry.com/ai-atlas/lesson-data/spatial-filter-patch-attention-36a796546c85f406.json",
  "interactiveUrl": "https://semiaifoundry.com/ai-atlas/#spatial-filter-patch-attention",
  "related": [],
  "supersedes": [],
  "supersededBy": [],
  "contentHash": "76c21f23600308320fd4243094d0d04ea3d152ba71f429ff85c0e5f4900c7178",
  "contentLength": 6993,
  "jsonUrl": "https://semiaifoundry.com/agents/publications/atlas-lesson-spatial-filter-patch-attention.json",
  "markdownUrl": "https://semiaifoundry.com/agents/publications/atlas-lesson-spatial-filter-patch-attention.md",
  "sections": [
    {
      "id": "section-1",
      "title": "Local filters and patch attention",
      "start": 53,
      "end": 461
    },
    {
      "id": "section-2",
      "title": "The mechanism",
      "start": 461,
      "end": 1813
    },
    {
      "id": "section-3",
      "title": "Science and assumptions",
      "start": 1813,
      "end": 1841
    },
    {
      "id": "section-4",
      "title": "Local filters and patch attention · governing computation",
      "start": 1841,
      "end": 3069
    },
    {
      "id": "section-5",
      "title": "Engineering example",
      "start": 3069,
      "end": 3676
    },
    {
      "id": "section-6",
      "title": "Distinctions and tradeoffs",
      "start": 3676,
      "end": 4177
    },
    {
      "id": "section-7",
      "title": "Specifications and interfaces",
      "start": 4177,
      "end": 4643
    },
    {
      "id": "section-8",
      "title": "Interfaces",
      "start": 4643,
      "end": 4921
    },
    {
      "id": "section-9",
      "title": "Check your understanding",
      "start": 4921,
      "end": 4950
    },
    {
      "id": "section-10",
      "title": "Why does the edge-line fixture fail under this valid-convolution classifier?",
      "start": 4950,
      "end": 5443
    },
    {
      "id": "section-11",
      "title": "Evidence and scope",
      "start": 5443,
      "end": 5949
    },
    {
      "id": "section-12",
      "title": "Sources",
      "start": 5949,
      "end": 6373
    },
    {
      "id": "section-13",
      "title": "Continue exploring",
      "start": 6373,
      "end": 6396
    },
    {
      "id": "section-14",
      "title": "Foundations",
      "start": 6396,
      "end": 6653
    },
    {
      "id": "section-15",
      "title": "Related lessons",
      "start": 6653,
      "end": 6993
    }
  ],
  "citations": [
    {
      "title": "Explore in Atlas",
      "url": "https://semiaifoundry.com/ai-atlas/#spatial-filter-patch-attention"
    },
    {
      "title": "PyTorch Conv2d, cross-correlation and shape",
      "url": "https://docs.pytorch.org/docs/2.14/generated/torch.nn.Conv2d.html"
    },
    {
      "title": "Vaswani et al., scaled dot-product attention",
      "url": "https://arxiv.org/abs/1706.03762"
    },
    {
      "title": "Published lesson data",
      "url": "https://semiaifoundry.com/ai-atlas/lesson-data/spatial-filter-patch-attention-36a796546c85f406.json"
    },
    {
      "title": "Atlas releases and licensing",
      "url": "https://semiaifoundry.com/ai-atlas/licenses.html"
    },
    {
      "title": "Tensor shapes, indices and contractions",
      "url": "https://semiaifoundry.com/learn/atlas/tensor-index-contracts/"
    },
    {
      "title": "Probability, likelihood and stable information",
      "url": "https://semiaifoundry.com/learn/atlas/probability-conditioning-information/"
    },
    {
      "title": "Patches, projection and visual instruction tuning",
      "url": "https://semiaifoundry.com/learn/atlas/visual-language-bridge/"
    },
    {
      "title": "Pair images and captions in a shared representation",
      "url": "https://semiaifoundry.com/learn/atlas/image-text-contrastive-learning/"
    },
    {
      "title": "Self-attention",
      "url": "https://semiaifoundry.com/learn/atlas/attention/"
    }
  ],
  "recordHash": "5a94b5178307f1fe6cfc145a5a6e51a0e39c635703e683ede7c5bbe65d064ce4",
  "contentFormat": "text/markdown",
  "content": "Contrasting computational structures · Atlas v1.3.0\n\n# Local filters and patch attention\n\nCompare fixed local receptive fields with content-weighted patch aggregation.\n\n[Explore in Atlas](https://semiaifoundry.com/ai-atlas/#spatial-filter-patch-attention)Abstract computation with explicit coordinate, sample and operation units\n\nLearning objectiveLocate the receptive field and identify how local boundary coverage differs from content-dependent aggregation.\n\n## The mechanism\n\nA convolutional layer shares a local kernel across spatial locations. The same coefficients can detect a similar pattern in more than one place, while stride, padding and kernel size determine which positions are seen. Patch attention instead calculates weights from the relationship between a query and candidate patches; those weights depend on input content. Both methods process structured arrays, but their connectivity and computation differ. The specimen uses a generated 5×5 line image, two authored 3×3 line filters and one query drawn from the center image patch. Its small arithmetic makes boundary effects and input-dependent attention visible. It deliberately separates a hand-built filter classifier from learned visual representations: fitting and evaluating a CNN or vision transformer would require training data, trainable projections, task losses and independent outcomes.\n\n1.  Generate a vertical or horizontal line at one of five positions and optionally erase the middle row.\n2.  Cross-correlate two 3×3 authored filters at each of nine valid locations without padding.\n3.  Use the largest filter responses for an explicit line-orientation decision, retaining ties as ties.\n4.  Flatten nine overlapping patches, score each against the center query with a scaled dot product, normalize and combine their values.\n\n## Science and assumptions\n\n### Local filters and patch attention · governing computation\n\n$$\nY_{ij}=\\sum_{u=0}^{2}\\sum_{v=0}^{2}K_{uv}X_{i+u,j+v}\n$$\n\nLocate the receptive field and identify how local boundary coverage differs from content-dependent aggregation.\n\nSymbols and units\n\nX\n\nFive by five input image\n\npixel amplitude\n\nK\n\nThree by three shared kernel\n\nfilter coefficient\n\nY\n\nThree by three valid response\n\nweighted amplitude\n\ni,j\n\nOutput location\n\npixel index\n\nu,v\n\nKernel coordinate\n\npixel index\n\nA centered vertical line gives a maximum vertical-filter response of 3 and horizontal response of 1, so the simple classifier returns vertical. At the outermost column, valid convolution never centers its vertical filter there; the maximum vertical response becomes 0 while horizontal response is 1. The wrong label follows from the stated coverage, not from an invented accuracy score. Two filters × nine output positions × nine kernel entries require 162 MACs; nine patch scores × nine coordinates require 81 dot-product MACs before attention normalization and value aggregation.\n\nAssumptions Authored filters and one identity-projection patch query; stride one, no padding; no trained CNN, full ViT, learned positions or recognition benchmark.\n\n## Engineering example\n\nA centered vertical line gives a maximum vertical-filter response of 3 and horizontal response of 1, so the simple classifier returns vertical. At the outermost column, valid convolution never centers its vertical filter there; the maximum vertical response becomes 0 while horizontal response is 1. The wrong label follows from the stated coverage, not from an invented accuracy score. Two filters × nine output positions × nine kernel entries require 162 MACs; nine patch scores × nine coordinates require 81 dot-product MACs before attention normalization and value aggregation.\n\n## Distinctions and tradeoffs\n\nAn attention heatmap is not proof that the model understands an image, and authored filters are not a trained vision model.\n\nLocal weight sharing imposes useful spatial structure and bounded receptive fields. Content-dependent aggregation changes connectivity, while padding, tokenization and position handling still matter.\n\nVision, industrial inspection and multimodal systems turn sampled images into representations through concrete spatial and learned operations.\n\n## Specifications and interfaces\n\nComputational contract\n\nCompare fixed local receptive fields with content-weighted patch aggregation.\n\nAuthored filters and one identity-projection patch query; stride one, no padding; no trained CNN, full ViT, learned positions or recognition benchmark.\n\nLearning evidence\n\nInspectable executable specimen\n\nInputs, intermediate values, exact output and a declared comparison or failure are available in Contrasting AI mechanisms.\n\n### Interfaces\n\nSpecified input Input\n\nGenerate a vertical or horizontal line at one of five positions and optionally erase the middle row.\n\nComputed output Output\n\nLocate the receptive field and identify how local boundary coverage differs from content-dependent aggregation.\n\n## Check your understanding\n\n### Why does the edge-line fixture fail under this valid-convolution classifier?\n\n1.  The vertical filter is never centered on that outermost column\n2.  All vertical lines are inherently ambiguous\n3.  More attention heads would prove the target label\n\nAnswer and reasoning\n\nThe vertical filter is never centered on that outermost column\n\nThe kernel placement and classifier are explicit. A boundary position outside the selected receptive-field centers can lose the intended filter response.\n\n## Evidence and scope\n\nAuthored filters and one identity-projection patch query; stride one, no padding; no trained CNN, full ViT, learned positions or recognition benchmark. Numerical settings are original teaching fixtures. The named experience executes the stated bounded algorithm; no production performance or independent human review is claimed.\n\nAuthored filters and one identity-projection patch query; stride one, no padding; no trained CNN, full ViT, learned positions or recognition benchmark.\n\n## Sources\n\n-   [PyTorch Conv2d, cross-correlation and shape](https://docs.pytorch.org/docs/2.14/generated/torch.nn.Conv2d.html)\n-   [Vaswani et al., scaled dot-product attention](https://arxiv.org/abs/1706.03762)\n\n[Published lesson data](https://semiaifoundry.com/ai-atlas/lesson-data/spatial-filter-patch-attention-36a796546c85f406.json) · [Atlas releases and licensing](https://semiaifoundry.com/ai-atlas/licenses.html)\n\n## Continue exploring\n\n### Foundations\n\n-   [Tensor shapes, indices and contractions](https://semiaifoundry.com/learn/atlas/tensor-index-contracts/)\n-   [Probability, likelihood and stable information](https://semiaifoundry.com/learn/atlas/probability-conditioning-information/)\n\n### Related lessons\n\n-   [Patches, projection and visual instruction tuning](https://semiaifoundry.com/learn/atlas/visual-language-bridge/)\n-   [Pair images and captions in a shared representation](https://semiaifoundry.com/learn/atlas/image-text-contrastive-learning/)\n-   [Self-attention](https://semiaifoundry.com/learn/atlas/attention/)"
}
