<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/layers/util.py#L227-L265) |

Deserializes the Keras-serialized function.

    tfp.layers.util.deserialize_function(
        serial, function_type
    )

(De)serializing Python functions from/to bytecode is unsafe. Therefore we
also use the function's type as an anonymous function ('lambda') or named
function in the Python environment ('function'). In the latter case, this lets
us use the Python scope to obtain the function rather than reload it from
bytecode. (Note that both cases are brittle!)

Keras-deserialized functions do not perform lexical scoping. Any modules that
the function requires must be imported within the function itself.

This serialization mimicks the implementation in `tf_keras.layers.Lambda`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `serial` | Serialized Keras object: typically a dict, string, or bytecode. |
| `function_type` | Python string denoting 'function' or 'lambda'. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `function` | Function the serialized Keras object represents. |

<br />

#### Examples

    serial, function_type = serialize_function(lambda x: x)
    function = deserialize_function(serial, function_type)
    assert function(2.3) == 2.3  # function is identity