R/layer_norm.R

Defines functions layer_norm

Documented in layer_norm

#' @name layer_norm
#' @title Layer Normalization
#' @param x inputs
#' @param epsilon scale
#' @return outputs of layer normalization

layer_norm <- function(x, epsilon = 1e-6) {
  mu <- row_means(x)
  sigma_sq <- row_vars(x)
  normalized_x <- t((t(x) - mu) / sqrt(sigma_sq + epsilon))
  return(normalized_x)
}

Try the transformer package in your browser

Any scripts or data that you put into this service are public.

transformer documentation built on Nov. 10, 2023, 5:08 p.m.