我正在使用macOS终端运行 train.py 文件,该文件可以在此Github link中找到,但我不断收到以下错误消息:
Arabic-NER $ python train.py
Using TensorFlow backend.
Loading Word Embedding model...
loaded model in 368.90753722190857 seconds
2019-12-18 21:11:19.329197: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fb88580c330 executing computations on platform Host. Devices:
2019-12-18 21:11:19.329702: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "train.py", line 130, in <module>
train_model, crf_layer = model.build_model()
File "/Name Entity Recognition /HassanAzzam/Arabic-NER/model.py", line 21, in build_model
output_layer = crf_layer(bi_gru)
File "/Name Entity Recognition /HassanAzzam/Arabic-NER/env/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/Name Entity Recognition /HassanAzzam/Arabic-NER/env/lib/python3.6/site-packages/keras/engine/base_layer.py", line 475, in __call__
previous_mask = _collect_previous_mask(inputs)
File "/Name Entity Recognition /HassanAzzam/Arabic-NER/env/lib/python3.6/site-packages/keras/engine/base_layer.py", line 1441, in _collect_previous_mask
mask = node.output_masks[tensor_index]
AttributeError: 'Node' object has no attribute 'output_masks'
此外,这是 model.py :
import tensorflow.keras
from tensorflow.keras.layers import Dense, Input, GRU, Embedding, Dropout, Activation, Masking
from tensorflow.keras.layers import Bidirectional, GlobalMaxPool1D, TimeDistributed
from tensorflow.keras.models import Model, Sequential
from keras_contrib.layers import CRF
def build_model():
crf_layer = CRF(9)
input_layer = Input(shape=(None,300,))
# embedding = Embedding(212, 20, input_length=None, mask_zero=True)(input_layer)
mask_layer = Masking(mask_value=0., input_shape=(212, 300))(input_layer)
bi_gru = Bidirectional(GRU(10, return_sequences=True))(mask_layer)
bi_gru = TimeDistributed(Dense(10, activation="relu"))(bi_gru)
output_layer = crf_layer(bi_gru)
return Model(input_layer, output_layer), crf_layer
我正在使用TensorFlow 2.0和Python 3.6.6。
注意:在 train.py 文件的第8行中,我在 keras 之前添加了 tensorflow 。
因此,它是from tensorflow.keras.utils import to_categorical
。
完整的Github存储库可以找到here
答案 0 :(得分:0)
我通过安装以下版本解决了该问题:
顺序:
pip install seqeval==0.0.5
Keras:
pip install keras==2.2.4
Tensorflow:
pip install tensorflow==1.14.0
我还在每个文件的开头添加了from keras.models import *