Hironsan / anago

Bidirectional LSTM-CRF and ELMo for Named-Entity Recognition, Part-of-Speech Tagging and so on.
https://anago.herokuapp.com/
MIT License
1.48k stars 368 forks source link

BI_LSTM-CRF examples not working #106

Open soumandal opened 5 years ago

soumandal commented 5 years ago

If you open a GitHub issue, here is our policy:

  1. It must be a bug, a feature request, or a significant problem with documentation (for small docs fixes please send a PR instead).
  2. The form below must be filled out.

System information

Describe the problem

I am facing two problems

  1. While saving the BiLSTM-CRF model, the weights and the preprocessor files are being saved but not the params file.
  2. While testing, I am getting the error "AttributeError: type object 'BiLSTMCRF' has no attribute 'load'"

Source code / logs

from anago.tagger import Tagger
from anago.models import BiLSTMCRF
from anago.preprocessing import IndexTransformer
from pprint import pprint

def main():
    print('loading objects')
    model = BiLSTMCRF.load("weights.h5", "params.json")
    it = IndexTransformer.load("preprocessor.json")
    tagger = Tagger(model, preprocessor=it)

    print('tagging a sentence')
    res = tagger.analyze("EU rejects German call to boycott British lamb .")
    pprint(res)

if __name__ == main():
    main()

ERROR

Traceback (most recent call last): File "C:/Users/soumil/PycharmProjects/code_switching/test.py", line 17, in if name == main(): File "C:/Users/lab/PycharmProjects/code_switching/test.py", line 9, in main model = BiLSTMCRF.load("weights.h5", "params.json") AttributeError: type object 'BiLSTMCRF' has no attribute 'load'

nikhiljsk commented 5 years ago

I'm running into the same error. I use Python 3.6 BTW.

kommerzienrat commented 5 years ago

You may have to use load_model: from anago.models import load_model

Otherwise, you could use (for sequence models): model = anago.Sequence.load(...)