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
64d83c7a
Commit
64d83c7a
authored
Sep 05, 2019
by
thomwolf
Browse files
WIP
parent
01597e5b
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
668 additions
and
0 deletions
+668
-0
pytorch_transformers/modeling_tf_gpt2.py
pytorch_transformers/modeling_tf_gpt2.py
+650
-0
pytorch_transformers/modeling_tf_utils.py
pytorch_transformers/modeling_tf_utils.py
+18
-0
No files found.
pytorch_transformers/modeling_tf_gpt2.py
0 → 100644
View file @
64d83c7a
This diff is collapsed.
Click to expand it.
pytorch_transformers/modeling_tf_utils.py
View file @
64d83c7a
...
@@ -255,3 +255,21 @@ class TFPreTrainedModel(tf.keras.Model):
...
@@ -255,3 +255,21 @@ class TFPreTrainedModel(tf.keras.Model):
ret
=
model
(
inputs
,
training
=
False
)
# Make sure restore ops are run
ret
=
model
(
inputs
,
training
=
False
)
# Make sure restore ops are run
return
model
return
model
class
TFConv1D
(
tf
.
keras
.
layers
.
Layer
):
def
__init__
(
self
,
nf
,
nx
):
""" TFConv1D layer as defined by Radford et al. for OpenAI GPT (and also used in GPT-2)
Basically works like a Linear layer but the weights are transposed
"""
super
(
TFConv1D
,
self
).
__init__
()
self
.
nf
=
nf
w
=
torch
.
empty
(
nx
,
nf
)
nn
.
init
.
normal_
(
w
,
std
=
0.02
)
self
.
weight
=
nn
.
Parameter
(
w
)
self
.
bias
=
nn
.
Parameter
(
torch
.
zeros
(
nf
))
def
call
(
self
,
x
):
size_out
=
t
.
shape
(
x
)[:
-
1
]
+
(
self
.
nf
,)
x
=
tf
.
addmm
(
self
.
bias
,
x
.
view
(
-
1
,
x
.
size
(
-
1
)),
self
.
weight
)
x
=
x
.
view
(
*
size_out
)
return
x
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