Load and continue training NER model
See original GitHub issueI 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
model.fit(train_x, train_y, valid_x, valid_y, batch_size=batch_size, callbacks=[eval_callback, tf_board_callback])
model.save("./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')
model.fit(train_x, 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 model.fit()
it gives me following error.
Traceback (most recent call last):
File "BiLSTM_CRF_BERT.py", line 55, in <module>
model.fit(train_x, 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/base_model.py", line 293, in fit
**fit_kwargs)
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 1433, in fit_generator
steps_name='steps_per_epoch')
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/training_generator.py", line 264, in model_iteration
batch_outs = batch_function(*batch_data)
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 1142, in train_on_batch
self._assert_compile_was_called()
File "/root/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", 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 ??
Environment
- OS : Ubuntu 16.04
- Python Version: Conda 3.7.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It seems we have ignored some issue related to the CRF layer. Will fix ASAP.
This will fix in 0.5.4 version in several days. @allhelllooz