{"id":"spatial-filter-patch-attention","name":"Local filters and patch attention","shortName":"Local filters and patch attention","role":"Compare fixed local receptive fields with content-weighted patch aggregation.","description":"A 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.","mechanism":["Generate a vertical or horizontal line at one of five positions and optionally erase the middle row.","Cross-correlate two 3×3 authored filters at each of nine valid locations without padding.","Use the largest filter responses for an explicit line-orientation decision, retaining ties as ties.","Flatten nine overlapping patches, score each against the center query with a scaled dot product, normalize and combine their values."],"learningObjective":"Locate the receptive field and identify how local boundary coverage differs from content-dependent aggregation.","engineeringExample":"A 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.","evidenceNotes":"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.","specs":[{"label":"Computational contract","value":"Compare fixed local receptive fields with content-weighted patch aggregation.","context":"Authored filters and one identity-projection patch query; stride one, no padding; no trained CNN, full ViT, learned positions or recognition benchmark."},{"label":"Learning evidence","value":"Inspectable executable specimen","context":"Inputs, intermediate values, exact output and a declared comparison or failure are available in Contrasting AI mechanisms."}],"interfaces":[{"name":"Specified input","direction":"in","signal":"Generate a vertical or horizontal line at one of five positions and optionally erase the middle row."},{"name":"Computed output","direction":"out","signal":"Locate the receptive field and identify how local boundary coverage differs from content-dependent aggregation."}],"tradeoff":"Local weight sharing imposes useful spatial structure and bounded receptive fields. Content-dependent aggregation changes connectivity, while padding, tokenization and position handling still matter.","whyAI":"Vision, industrial inspection and multimodal systems turn sampled images into representations through concrete spatial and learned operations.","misconception":"An attention heatmap is not proof that the model understands an image, and authored filters are not a trained vision model.","check":{"question":"Why does the edge-line fixture fail under this valid-convolution classifier?","options":["The vertical filter is never centered on that outermost column","All vertical lines are inherently ambiguous","More attention heads would prove the target label"],"answer":0,"explanation":"The kernel placement and classifier are explicit. A boundary position outside the selected receptive-field centers can lose the intended filter response."},"prerequisites":["tensor-index-contracts","probability-conditioning-information"],"related":["visual-language-bridge","image-text-contrastive-learning","attention"],"sources":[{"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"}],"scale":"Abstract computation with explicit coordinate, sample and operation units","level":"model","kind":"model","workstream":"W11","science":[{"title":"Local filters and patch attention · governing computation","equation":"Y_{ij}=\\sum_{u=0}^{2}\\sum_{v=0}^{2}K_{uv}X_{i+u,j+v}","explanation":"A 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.","assumptions":"Authored filters and one identity-projection patch query; stride one, no padding; no trained CNN, full ViT, learned positions or recognition benchmark."}],"labScope":"Authored filters and one identity-projection patch query; stride one, no padding; no trained CNN, full ViT, learned positions or recognition benchmark.","branch":"Contrasting computational structures","subbranch":"Local filters and patch attention","history":[]}