# tfl.utils.canonicalize_monotonicity

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/utils.py#L85-L125) |

Converts string constants representing monotonicity into integers.

    tfl.utils.canonicalize_monotonicity(
        monotonicity, allow_decreasing=True
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `monotonicity` | The monotonicities hyperparameter of a [`tfl.layers`](https://www.tensorflow.org/lattice/api_docs/python/tfl/layers) Layer (e.g. [`tfl.layers.PWLCalibration`](https://www.tensorflow.org/lattice/api_docs/python/tfl/layers/PWLCalibration)). |
| `allow_decreasing` | If decreasing monotonicity is considered a valid monotonicity. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| monotonicity represented as -1, 0, 1, or None. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If monotonicity is not in the set {-1, 0, 1, 'decreasing', 'none', 'increasing'} and allow_decreasing is True. |
| `ValueError` | If monotonicity is not in the set {0, 1, 'none', 'increasing'} and allow_decreasing is False. |

<br />