提交 3aeb517a 编写于 作者: C cclauss

Fixes for Python 3

上级 b255e121
...@@ -137,7 +137,7 @@ def parse(init_checkpoint): ...@@ -137,7 +137,7 @@ def parse(init_checkpoint):
else: else:
print("ignored param: %s" % var_name) print("ignored param: %s" % var_name)
if fluid_param_name is not '': if fluid_param_name != '':
tf_fluid_param_name_map[var_name] = fluid_param_name tf_fluid_param_name_map[var_name] = fluid_param_name
tf_param_name_shape_map[var_name] = var_shape tf_param_name_shape_map[var_name] = var_shape
fluid_param_name = '' fluid_param_name = ''
......
...@@ -73,7 +73,7 @@ class BertModel(object): ...@@ -73,7 +73,7 @@ class BertModel(object):
self._sent_emb_name = "sent_embedding" self._sent_emb_name = "sent_embedding"
self._dtype = "float16" if use_fp16 else "float32" self._dtype = "float16" if use_fp16 else "float32"
# Initialize all weigths by truncated normal initializer, and all biases # Initialize all weigths by truncated normal initializer, and all biases
# will be initialized by constant zero by default. # will be initialized by constant zero by default.
self._param_initializer = fluid.initializer.TruncatedNormal( self._param_initializer = fluid.initializer.TruncatedNormal(
scale=config['initializer_range']) scale=config['initializer_range'])
...@@ -109,7 +109,7 @@ class BertModel(object): ...@@ -109,7 +109,7 @@ class BertModel(object):
emb_out = pre_process_layer( emb_out = pre_process_layer(
emb_out, 'nd', self._prepostprocess_dropout, name='pre_encoder') emb_out, 'nd', self._prepostprocess_dropout, name='pre_encoder')
if self._dtype is "float16": if self._dtype == "float16":
self_attn_mask = fluid.layers.cast( self_attn_mask = fluid.layers.cast(
x=self_attn_mask, dtype=self._dtype) x=self_attn_mask, dtype=self._dtype)
...@@ -175,7 +175,7 @@ class BertModel(object): ...@@ -175,7 +175,7 @@ class BertModel(object):
name='mask_lm_trans_fc.w_0', name='mask_lm_trans_fc.w_0',
initializer=self._param_initializer), initializer=self._param_initializer),
bias_attr=fluid.ParamAttr(name='mask_lm_trans_fc.b_0')) bias_attr=fluid.ParamAttr(name='mask_lm_trans_fc.b_0'))
# transform: layer norm # transform: layer norm
mask_trans_feat = pre_process_layer( mask_trans_feat = pre_process_layer(
mask_trans_feat, 'n', name='mask_lm_trans') mask_trans_feat, 'n', name='mask_lm_trans')
......
...@@ -17,11 +17,13 @@ from __future__ import absolute_import ...@@ -17,11 +17,13 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
import argparse
import collections
import multiprocessing
import os import os
import time import time
import argparse
import numpy as np import numpy as np
import collections
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
......
...@@ -19,6 +19,8 @@ from __future__ import print_function ...@@ -19,6 +19,8 @@ from __future__ import print_function
import numpy as np import numpy as np
from six.moves import xrange
def mask(batch_tokens, def mask(batch_tokens,
seg_labels, seg_labels,
......
...@@ -22,6 +22,8 @@ import numpy as np ...@@ -22,6 +22,8 @@ import numpy as np
import paddle.fluid as fluid import paddle.fluid as fluid
from six.moves import xrange
from model.ernie import ErnieModel from model.ernie import ErnieModel
......
...@@ -25,6 +25,8 @@ import multiprocessing ...@@ -25,6 +25,8 @@ import multiprocessing
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from six.moves import xrange
from model.ernie import ErnieModel from model.ernie import ErnieModel
def create_model(args, def create_model(args,
......
...@@ -73,7 +73,7 @@ class ErnieModel(object): ...@@ -73,7 +73,7 @@ class ErnieModel(object):
self._sent_emb_name = "sent_embedding" self._sent_emb_name = "sent_embedding"
self._dtype = "float16" if use_fp16 else "float32" self._dtype = "float16" if use_fp16 else "float32"
# Initialize all weigths by truncated normal initializer, and all biases # Initialize all weigths by truncated normal initializer, and all biases
# will be initialized by constant zero by default. # will be initialized by constant zero by default.
self._param_initializer = fluid.initializer.TruncatedNormal( self._param_initializer = fluid.initializer.TruncatedNormal(
scale=config['initializer_range']) scale=config['initializer_range'])
...@@ -109,7 +109,7 @@ class ErnieModel(object): ...@@ -109,7 +109,7 @@ class ErnieModel(object):
emb_out = pre_process_layer( emb_out = pre_process_layer(
emb_out, 'nd', self._prepostprocess_dropout, name='pre_encoder') emb_out, 'nd', self._prepostprocess_dropout, name='pre_encoder')
if self._dtype is "float16": if self._dtype == "float16":
self_attn_mask = fluid.layers.cast( self_attn_mask = fluid.layers.cast(
x=self_attn_mask, dtype=self._dtype) x=self_attn_mask, dtype=self._dtype)
...@@ -175,7 +175,7 @@ class ErnieModel(object): ...@@ -175,7 +175,7 @@ class ErnieModel(object):
name='mask_lm_trans_fc.w_0', name='mask_lm_trans_fc.w_0',
initializer=self._param_initializer), initializer=self._param_initializer),
bias_attr=fluid.ParamAttr(name='mask_lm_trans_fc.b_0')) bias_attr=fluid.ParamAttr(name='mask_lm_trans_fc.b_0'))
# transform: layer norm # transform: layer norm
mask_trans_feat = pre_process_layer( mask_trans_feat = pre_process_layer(
mask_trans_feat, 'n', name='mask_lm_trans') mask_trans_feat, 'n', name='mask_lm_trans')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册