BERT模型命名实体识别出现的小错误

出现的问题记录

1.报错如下:

Traceback (most recent call last):
  File "C:/Users/ZXH/Desktop/BERT-CH-NER-master/bert-master/run_NER.py", line 27, in <module>
    import optimization
  File "C:\Users\ZXH\Desktop\BERT-CH-NER-master\bert-master\optimization.py", line 87, in <module>
    class AdamWeightDecayOptimizer(tf.train.Optimizer):
AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'Optimizer'

解决方法:

把optimization.py中的类
class AdamWeightDecayOptimizer(tf.train.Optimizer)
改成
class AdamWeightDecayOptimizer(tf.compat.v1.train.Optimizer)

即:
在这里插入图片描述

2.修改上一个错误后继续报错:

Traceback (most recent call last):
  File "C:/Users/ZXH/Desktop/BERT-CH-NER-master/bert-master/run_NER.py", line 33, in <module>
    flags = tf.flags
AttributeError: module 'tensorflow' has no attribute 'flags'

解决方法:

将原语句中的:
flags = tf.flags
FLAGS = flags.FLAGS
修改为:
flags = tf.compat.v1.flags
FLAGS = flags.FLAGS

3.

报错:AttributeError: module 'tensorflow' has no attribute 'app'

解决方法:

import tensorflow as tf
换成 import tensorflow.compat.v1 as tf

你可能感兴趣的:(机器学习相关笔记)