使用bert源码中遇到的问题

 1、Tensorflow2.x版本与Tensorflow1.x版本代码转换

flags = tf.flags 改为 flags = tf.compat.v1.flags

tf.logging.info 改为 tf.compat.v1.logging.info

tf.contrib 改为 tf.compat.v1.estimator

tf.contrib.data.map_and_batch 改为 tf.data.experimental.map_and_batch

tf.python_io 改为 tf.io

tf.FixedLenFeature 改为 tf.io.FixedLenFeature

tf.gfile 改为 tf.compat.v1.gfile

tf.parse_single_example 改为 tf.io.parse_single_example

tf.to_int32(my_tensor) 改为 tf.cast(my_tensor, tf.int32)

tf.variable_scope() 改为 tf.compat.v1.variable_scope()

tf.get_variable() 改为 tf.compat.v1.get_variable()

tf.truncated_normal_initializer() 改为 tf.compat.v1.truncated_normal_initializer()

tf.assert_less_equal() 改为 tf.compat.v1.assert_less_equal()

tf.contrib.layers.xxx 改为 tf.keras.layers.xxx

如
原代码为
tf.contrib.layers.layer_norm(
      inputs=input_tensor, begin_norm_axis=-1, begin_params_axis=-1, scope=name)

修改为
layer_norma = tf.keras.layers.LayerNormalization(axis=-1)
layer_norma(input_tensor)

tf.layers 改为 tf.compat.v1.layers

2、

原代码为

hidden_size = output_layer.shape[-1].value

修改为

hidden_size = output_layer.shape[-1]

3、

原代码为

output_layer = tf.nn.dropout(output_layer, keep_prob=0.9)

修改为

output_layer = tf.nn.dropout(output_layer, rate=0.9)

4、

原代码为

 tf.train.init_from_checkpoint(init_checkpoint, assignment_map)

修改为

tf.compat.v1.train.init_from_checkpoint

5、

原代码为

 global_step = tf.train.get_or_create_global_step()

修改为

 global_step = tf.compat.v1.train.get_or_create_global_step()

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值