Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
4c91a3af
Commit
4c91a3af
authored
Mar 05, 2020
by
Gunnlaugur Thor Briem
Browse files
Document keras_serializable decorator
parent
4be01e5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
src/transformers/modeling_tf_utils.py
src/transformers/modeling_tf_utils.py
+15
-0
No files found.
src/transformers/modeling_tf_utils.py
View file @
4c91a3af
...
@@ -47,6 +47,21 @@ class TFModelUtilsMixin:
...
@@ -47,6 +47,21 @@ class TFModelUtilsMixin:
def
keras_serializable
(
cls
):
def
keras_serializable
(
cls
):
"""
Decorate a Keras Layer class to support Keras serialization.
This is done by:
1. adding a `transformers_config` dict to the Keras config dictionary in `get_config` (called by Keras at
serialization time
2. wrapping `__init__` to accept that `transformers_config` dict (passed by Keras at deserialization time) and
convert it to a config object for the actual layer initializer
3. registering the class as a custom object in Keras (if the Tensorflow version supports this), so that it does
not need to be supplied in `custom_objects` in the call to `tf.keras.models.load_model`
:param cls: a tf.keras.layers.Layers subclass that accepts a `config` argument to its initializer (typically a
`TF*MainLayer` class in this project)
:return: the same class object, with modifications for Keras deserialization.
"""
initializer
=
cls
.
__init__
initializer
=
cls
.
__init__
config_class
=
getattr
(
cls
,
"config_class"
,
None
)
config_class
=
getattr
(
cls
,
"config_class"
,
None
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment