1 year ago
#234226
Hermion
How to save a trained crf model
I'm trying to build a named entity recognition model using BilSTM-CRF network and i'm following this website : https://blog.dominodatalab.com/named-entity-recognition-ner-challenges-and-model. After I train my model i use this code to predict the detected entities :
re_tok = re.compile(f"([{string.punctuation}“”¨«»®´·º½¾¿¡§£₤‘’])")
sentence = re_tok.sub(r" ", sentence).split()
padded_sentence = sentence + [word2index["--PADDING--"]] * (MAX_SENTENCE - len(sentence))
padded_sentence = [word2index.get(w, 0) for w in padded_sentence]
pred = ner_model.predict(np.array([padded_sentence]))
pred = np.argmax(pred, axis=-1)
retval = ""
for w, p in zip(sentence, pred[0]):
retval = retval + "{:15}: {:5}".format(w, index2tag[p])" + "\n"
print(retval)
and it works actually pretty good for my use case also, now i'm trying to save the model, to use in a real-time prediction using this code :
import pickle
filename = 'Model.sav'
pickle.dump(rf, open(filename, 'wb'))
but actually doesn'T work as i wanted .. it's saved but saved wrong , the prediction isn't correct even for the same sentence i tested before saving have anyone any idea how can i save a crf model ?
python
pickle
named-entity-recognition
crf
bilstm
0 Answers
Your Answer