简体   繁体   中英

Building an NER model and getting the following: AttributeError: 'Tensor' object has no attribute '_keras_history'

I am following this tutorial to build a NER model for practice in Machine Learning.

However, when towards the end of the tutorial when I run the code, I am triggering an "AttributeError: 'Tensor' object has no attribute '_keras_history' that occurs because of line 174:

history = ner_model.fit(X_train, y_train, batch_size=BATCH_SIZE, epochs=MAX_EPOCHS, validation_split=0.1, verbose=2)

If anyone can help me solve this issue as I am a beginner in Machine Learning as well as Python Coding, that would very much be appreciated.

I am using Keras 2.9.0, Tensorflow 3.2.0, and Pip 22.2.2

The rest of my code is the same as in the link provided to the tutorial above, Hope someone can help me. thank you.

This is a version problem. In the tutorial you linked is shown the import: from keras_contrib.layers import CRF . However keras_contrib is not available for tensorflow version >=2.0. It has been migrated to tensorflow_addons .

You should consider whether it is best for you to switch your tensorflow version to 1.x, or try to migrate from keras_contrib to tensorflow_addons . Here is the documentation of the migrated CRF layer. Personally I would prefer this second option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM