Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Load and continue training NER model

See original GitHub issue

I am training a BiGRU_CRF_Model model with BERT with 1million data points and saving it.

### Load bert embeddings
bert_embed = BERTEmbedding(bert_location, task=kashgari.LABELING, sequence_length=bert_sequence_len)

### Define model
model = BiGRU_CRF_Model(bert_embed)
tf_board_callback = keras.callbacks.TensorBoard(log_dir='./logs', update_freq=1000)
eval_callback = EvalCallBack(kash_model=model, valid_x=valid_x, valid_y=valid_y, step=steps)

### Fit model, train_y, valid_x, valid_y, batch_size=batch_size, callbacks=[eval_callback, tf_board_callback])"./BiGRU_CRF_BERT.model")

Then I am loading the model again to train it on some more data as shown below -

from kashgari.utils import load_model
model = load_model('./BiGRU_CRF_BERT.model'), train_y, valid_x, valid_y, batch_size=batch_size, callbacks=[eval_callback, tf_board_callback])

There is no issue in model load and testing. But when I do it gives me following error.

Traceback (most recent call last):
  File "", line 55, in <module>, train_y, valid_x, valid_y, epochs=epochs, batch_size=batch_size, callbacks=[eval_callback])
  File "/root/anaconda3/lib/python3.7/site-packages/kashgari/tasks/", line 293, in fit
  File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/", line 1433, in fit_generator
  File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/", line 264, in model_iteration
    batch_outs = batch_function(*batch_data)
  File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/", line 1142, in train_on_batch
  File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/", line 2934, in _assert_compile_was_called
    raise RuntimeError('You must compile your model before '
RuntimeError: You must compile your model before training/testing. Use `model.compile(optimizer, loss)`.

How can I get this info about optimizer and loss from saved model ??


  • OS : Ubuntu 16.04
  • Python Version: Conda 3.7.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

BrikerMancommented, Sep 5, 2019


It seems we have ignored some issue related to the CRF layer. Will fix ASAP.

BrikerMancommented, Sep 15, 2019

This will fix in 0.5.4 version in several days. @allhelllooz

Read more comments on GitHub >

github_iconTop Results From Across the Web

Training Pipelines & Models · spaCy Usage Documentation
Training is an iterative process in which the model's predictions are compared against the reference annotations in order to estimate the gradient of...
Read more >
7. How to Train spaCy NER Model
In the last notebook, we created a basic training set for a machine learning model using spaCy's EntityRuler. We were able to do...
Read more >
Training Custom NER models in SpaCy to auto-detect named ...
The spaCy library allows you to train NER models by both updating an existing spacy model to suit the specific context of your...
Read more >
Training Custom NER - Towards Data Science
Architecture to Train NER with Custom training data using spaCy. ... Next, load a blank model for the process to carry out the...
Read more >
Training Custom NER Model Using Flair | by Akash Chauhan
The flair's documentation covers that in a brilliant way, but unlike spaCy, the data preparation for the data that is to be fed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found