tensorflow - 将张量流 tf.contrib.layers.layer_norm 转换为 tf2.0
问题描述
我想将以下代码从 tf1.0 更改为 tf2.0
tf.contrib.layers.layer_norm(
inputs=input_tensor, begin_norm_axis=-1, begin_params_axis=-1, scope=name)
此代码取自https://github.com/google-research/bert/blob/master/modeling.py 第 364 行。
请帮我。
解决方案
@rishabh-sahrawat 的回答是正确的,但你应该这样做:
layer_norma = tf.keras.layers.LayerNormalization(axis = -1)
layer_norma(input_tensor)
在您链接的 BERT 案例中,您应该使用以下内容修改代码:
def layer_norm(input_tensor, name=None):
"""Run layer normalization on the last dimension of the tensor."""
layer_norma = tf.keras.layers.LayerNormalization(axis = -1)
return layer_norma(input_tensor)
推荐阅读
- python - Pyspark UDF 收到错误“java.lang.NullPointerException”
- python - 使用 matplotlib 3D scatter,第 3 维被忽略
- java - 使用@TestPropertySource 时属性始终为空@ConfigurationProperties
- mongodb - 匹配填充不适用于猫鼬
- powerbi - Power BI 为每个用户导出 PDF 报告
- xaml - Xamarin.Forms 如何在 VisualState 中使用 Xamarin Community Toolkit TouchEffect
- html - 跨多行创建具有多个选项的选择标签
- python - Python:使用 GroupBy 对象上的过滤器过滤掉 DataFrame
- postgresql - 在存储库中获取没有@Query 的特定属性
- python - 如何在 concurrent.futures.ProcessPoolExecutor 期间从 concurrent.futures 将变量输出存储在函数中