<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/random_initializers.py#L86-L142) |

Initializer that generates a truncated normal distribution.

Inherits From: [`Initializer`](https://www.tensorflow.org/api_docs/python/tf/keras/Initializer)

#### View aliases


**Main aliases**

[`tf.keras.initializers.truncated_normal`](https://www.tensorflow.org/api_docs/python/tf/keras/initializers/TruncatedNormal)

<br />

    tf.keras.initializers.TruncatedNormal(
        mean=0.0, stddev=0.05, seed=None
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Customizing a Transformer Encoder](https://www.tensorflow.org/tfmodels/nlp/customize_encoder) - [Fine-tuning a BERT model](https://www.tensorflow.org/tfmodels/nlp/fine_tune_bert) |

The values generated are similar to values from a
`RandomNormal` initializer, except that values more
than two standard deviations from the mean are
discarded and re-drawn.

#### Examples:

    # Standalone usage:
    initializer = TruncatedNormal(mean=0., stddev=1.)
    values = initializer(shape=(2, 2))

    # Usage in a Keras layer:
    initializer = TruncatedNormal(mean=0., stddev=1.)
    layer = Dense(3, kernel_initializer=initializer)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `mean` | A python scalar or a scalar keras tensor. Mean of the random values to generate. |
| `stddev` | A python scalar or a scalar keras tensor. Standard deviation of the random values to generate. |
| `seed` | A Python integer or instance of `keras.backend.SeedGenerator`. Used to make the behavior of the initializer deterministic. Note that an initializer seeded with an integer or `None` (unseeded) will produce the same random values across multiple calls. To get different random values across multiple calls, use as seed an instance of `keras.backend.SeedGenerator`. |

<br />

## Methods

### `clone`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/initializer.py#L96-L97)

    clone()

### `from_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/initializer.py#L76-L94)

    @classmethod
    from_config(
        config
    )

Instantiates an initializer from a configuration dictionary.

#### Example:

    initializer = RandomUniform(-1, 1)
    config = initializer.get_config()
    initializer = RandomUniform.from_config(config)

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | A Python dictionary, the output of `get_config()`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An `Initializer` instance. ||

<br />

### `get_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/random_initializers.py#L139-L142)

    get_config()

Returns the initializer's configuration as a JSON-serializable dict.

<br />

<br />

<br />

| Returns ||
|---|---|
| A JSON-serializable Python dict. ||

<br />

### `__call__`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/random_initializers.py#L130-L137)

    __call__(
        shape, dtype=None
    )

Returns a tensor object initialized as specified by the initializer.

<br />

<br />

<br />

| Args ||
|---|---|
| `shape` | Shape of the tensor. |
| `dtype` | Optional dtype of the tensor. |

<br />