Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
3922a249
Commit
3922a249
authored
Jan 15, 2020
by
Lysandre
Committed by
Lysandre Debut
Jan 23, 2020
Browse files
TF ALBERT + TF Utilities + Fix warnings
parent
00df3d4d
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
126 deletions
+148
-126
docs/source/main_classes/optimizer_schedules.rst
docs/source/main_classes/optimizer_schedules.rst
+2
-5
docs/source/model_doc/albert.rst
docs/source/model_doc/albert.rst
+1
-1
src/transformers/file_utils.py
src/transformers/file_utils.py
+1
-1
src/transformers/modeling_albert.py
src/transformers/modeling_albert.py
+5
-0
src/transformers/modeling_tf_albert.py
src/transformers/modeling_tf_albert.py
+127
-116
src/transformers/modeling_tf_utils.py
src/transformers/modeling_tf_utils.py
+12
-3
No files found.
docs/source/main_classes/optimizer_schedules.rst
View file @
3922a249
...
@@ -20,14 +20,12 @@ The ``.optimization`` module provides:
...
@@ -20,14 +20,12 @@ The ``.optimization`` module provides:
:members:
:members:
.. autofunction:: transformers.create_optimizer
.. autofunction:: transformers.create_optimizer
:members:
Schedules
Schedules
----------------------------------------------------
----------------------------------------------------
Learning Rate Schedules
Learning Rate Schedules
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autofunction:: transformers.get_constant_schedule
.. autofunction:: transformers.get_constant_schedule
...
@@ -39,7 +37,6 @@ Learning Rate Schedules
...
@@ -39,7 +37,6 @@ Learning Rate Schedules
.. autofunction:: transformers.get_cosine_schedule_with_warmup
.. autofunction:: transformers.get_cosine_schedule_with_warmup
:members:
.. image:: /imgs/warmup_cosine_schedule.png
.. image:: /imgs/warmup_cosine_schedule.png
:target: /imgs/warmup_cosine_schedule.png
:target: /imgs/warmup_cosine_schedule.png
...
@@ -63,7 +60,7 @@ Learning Rate Schedules
...
@@ -63,7 +60,7 @@ Learning Rate Schedules
``Warmup``
``Warmup``
~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~
.. autoclass:: transformers.Warm
u
p
.. autoclass:: transformers.Warm
U
p
:members:
:members:
Gradient Strategies
Gradient Strategies
...
...
docs/source/model_doc/albert.rst
View file @
3922a249
...
@@ -59,7 +59,7 @@ AlbertForMaskedLM
...
@@ -59,7 +59,7 @@ AlbertForMaskedLM
AlbertForSequenceClassification
AlbertForSequenceClassification
~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~
.. autoclass:: transformers.AlbertForSequenceClassification
.. autoclass:: transformers.AlbertForSequenceClassification
:members:
:members:
...
...
src/transformers/file_utils.py
View file @
3922a249
...
@@ -121,7 +121,7 @@ def add_start_docstrings_to_callable(*docstr):
...
@@ -121,7 +121,7 @@ def add_start_docstrings_to_callable(*docstr):
Although the recipe for forward pass needs to be defined within
Although the recipe for forward pass needs to be defined within
this function, one should call the :class:`Module` instance afterwards
this function, one should call the :class:`Module` instance afterwards
instead of this since the former takes care of running the
instead of this since the former takes care of running the
re
gistered hook
s while the latter silently ignores them.
p
re
and post processing step
s while the latter silently ignores them.
"""
"""
fn
.
__doc__
=
intro
+
note
+
""
.
join
(
docstr
)
+
(
fn
.
__doc__
if
fn
.
__doc__
is
not
None
else
""
)
fn
.
__doc__
=
intro
+
note
+
""
.
join
(
docstr
)
+
(
fn
.
__doc__
if
fn
.
__doc__
is
not
None
else
""
)
return
fn
return
fn
...
...
src/transformers/modeling_albert.py
View file @
3922a249
...
@@ -423,6 +423,10 @@ ALBERT_INPUTS_DOCSTRING = r"""
...
@@ -423,6 +423,10 @@ ALBERT_INPUTS_DOCSTRING = r"""
Mask to nullify selected heads of the self-attention modules.
Mask to nullify selected heads of the self-attention modules.
Mask values selected in ``[0, 1]``:
Mask values selected in ``[0, 1]``:
:obj:`1` indicates the head is **not masked**, :obj:`0` indicates the head is **masked**.
:obj:`1` indicates the head is **not masked**, :obj:`0` indicates the head is **masked**.
input_embeds (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`, `optional`, defaults to :obj:`None`):
Optionally, instead of passing :obj:`input_ids` you can choose to directly pass an embedded representation.
This is useful if you want more control over how to convert `input_ids` indices into associated vectors
than the model's internal embedding lookup matrix.
"""
"""
...
@@ -478,6 +482,7 @@ class AlbertModel(AlbertPreTrainedModel):
...
@@ -478,6 +482,7 @@ class AlbertModel(AlbertPreTrainedModel):
inner_group_idx
=
int
(
layer
-
group_idx
*
self
.
config
.
inner_group_num
)
inner_group_idx
=
int
(
layer
-
group_idx
*
self
.
config
.
inner_group_num
)
self
.
encoder
.
albert_layer_groups
[
group_idx
].
albert_layers
[
inner_group_idx
].
attention
.
prune_heads
(
heads
)
self
.
encoder
.
albert_layer_groups
[
group_idx
].
albert_layers
[
inner_group_idx
].
attention
.
prune_heads
(
heads
)
@
add_start_docstrings_to_callable
(
ALBERT_INPUTS_DOCSTRING
)
def
forward
(
def
forward
(
self
,
self
,
input_ids
=
None
,
input_ids
=
None
,
...
...
src/transformers/modeling_tf_albert.py
View file @
3922a249
This diff is collapsed.
Click to expand it.
src/transformers/modeling_tf_utils.py
View file @
3922a249
...
@@ -91,7 +91,12 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin):
...
@@ -91,7 +91,12 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin):
self
.
config
=
config
self
.
config
=
config
def
get_input_embeddings
(
self
):
def
get_input_embeddings
(
self
):
""" Get model's input embeddings
"""
Returns the model's input embeddings.
Returns:
:obj:`tf.keras.layers.Layer`:
A torch module mapping vocabulary to hidden states.
"""
"""
base_model
=
getattr
(
self
,
self
.
base_model_prefix
,
self
)
base_model
=
getattr
(
self
,
self
.
base_model_prefix
,
self
)
if
base_model
is
not
self
:
if
base_model
is
not
self
:
...
@@ -100,8 +105,12 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin):
...
@@ -100,8 +105,12 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin):
raise
NotImplementedError
raise
NotImplementedError
def
get_output_embeddings
(
self
):
def
get_output_embeddings
(
self
):
""" Get model's output embeddings
"""
Return None if the model doesn't have output embeddings
Returns the model's output embeddings.
Returns:
:obj:`tf.keras.layers.Layer`:
A torch module mapping hidden states to vocabulary.
"""
"""
return
None
# Overwrite for models with output embeddings
return
None
# Overwrite for models with output embeddings
...
...
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