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
960ef4df
Commit
960ef4df
authored
Nov 01, 2018
by
thomwolf
Browse files
probably ok weights convertion script
parent
ab0e8932
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
convert_tf_checkpoint.py
convert_tf_checkpoint.py
+7
-2
No files found.
convert_tf_checkpoint.py
View file @
960ef4df
...
...
@@ -9,6 +9,7 @@ import re
import
argparse
import
tensorflow
as
tf
import
torch
import
numpy
as
np
from
modeling_pytorch
import
BertConfig
,
BertModel
...
...
@@ -55,7 +56,11 @@ def convert():
for
name
,
array
in
zip
(
names
,
arrays
):
name
=
name
[
5
:]
# skip "bert/"
print
(
"Loading {}"
.
format
(
name
))
name
=
name
.
split
(
'/'
)
if
name
[
0
]
in
[
'redictions'
,
'eq_relationship'
]:
print
(
"Skipping"
)
continue
pointer
=
model
for
m_name
in
name
:
if
re
.
fullmatch
(
r
'[A-Za-z]+_\d+'
,
m_name
):
...
...
@@ -71,8 +76,8 @@ def convert():
pointer
=
pointer
[
num
]
if
m_name
[
-
11
:]
==
'_embeddings'
:
pointer
=
getattr
(
pointer
,
'weight'
)
#
elif m_name == 'kernel':
#
pointer = getattr(pointer, 'weight'
)
elif
m_name
==
'kernel'
:
array
=
np
.
transpose
(
array
)
try
:
assert
pointer
.
shape
==
array
.
shape
except
AssertionError
as
e
:
...
...
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