Skip to content

Instantly share code, notes, and snippets.

@hamidb80
Created June 26, 2026 09:34
Show Gist options
  • Select an option

  • Save hamidb80/c8a5ad4ef27d45da9123bcd7fab68aea to your computer and use it in GitHub Desktop.

Select an option

Save hamidb80/c8a5ad4ef27d45da9123bcd7fab68aea to your computer and use it in GitHub Desktop.
BQN BatchNorm and LayerNorm
ZScore ← {
avg ← (+´÷≠) 𝕩
var ← (≠𝕩) ÷˜ +´ ט 𝕩-avg
eps ← 0.000001
(𝕩-avg)÷(eps + √var)
}
LayerNorm ← { ZScore ˘ 𝕩}
BatchNorm ← {⍉ZScore ˘ ⍉𝕩}
# ------------------------------
df ← ↑‿4 ⥊ [
1.0, 2.0, 3.0, 4.0
10.0, 20.0, 30.0, 40.0
0.0, 0.0, 0.0, 0.0 ]
ZScore [1.0, 2.0, 3.0, 4.0]
LayerNorm df
BatchNorm df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment