yzhangcs / parser

:rocket: State-of-the-art parsers for natural language.
https://parser.yzhang.site/
MIT License
827 stars 139 forks source link

Error when trying to load a model with Parser.load() #78

Closed MinionAttack closed 3 years ago

MinionAttack commented 3 years ago

Hi,

I have installed SuPar as a dependency with PIP. Now when I try to load a model it gives me an error:

from supar import Parser
from models import MY_MODEL_FILENAME

class MyClass():
    def __init__(self):
        self.model = Parser.load(MY_MODEL_FILENAME)
        ......................

I get in parser.py (line 170) model = cls.MODEL(**args):

TypeError: __init__() missing 1 required positional argument: 'n_feats'

So, If I try to pass some arguments to the .load() function:

self.model = Parser.load(path=MY_MODEL_FILENAME, kwargs={"device": 1, "n_feats": ["tag", "char"]})

I get:

RuntimeError: The feat type should be in ['char', 'bert', 'tag'].

How I can specify the n_feats?

Regards.

yzhangcs commented 3 years ago

@MinionAttack Hi, have you checked the value of MY_MODEL_FILENAME? It should be a short name registered in supar.NAME or a local path of a model.

MinionAttack commented 3 years ago

@yzhangcs Hello, yes. The value of MY_MODEL_FILENAME is the location of a trained model (tested to work through cmd commands). The actual value is: '/home/userName/Desktop/SuPar/models/Pruebas_Punct/English-EWT/Iteracion_3/Iteracion_3'

yzhangcs commented 3 years ago

@MinionAttack Have you properly trained this model from scratch? If the training process is correct, you don't need to care about these values actually. n_feats is the number of characters if you used CharLSTM while training, i.e.,feat=['char'].

MinionAttack commented 3 years ago

@yzhangcs Yes, the model has been trained from scratch and it works but if I don't indicate n_feats I get an error when I run it. When training I have used char and tag for the feats. I attach the log of the training for the model.

Iteracion_3.train.log

If they are not needed why does it fail and tell me to specify them? If I debug I can see that the configuration is loaded from the trained model.

yzhangcs commented 3 years ago

@MinionAttack Sorry, those hints are not clear enough. I think you may need to upgrade SuPar to 1.1.0 or higher since the arg n_feat has been deprecated, and we use n_chars/n_tags instead. In previous versions, using more than 1 feature is an undefined behaviour (char and tag in your case). Thats why your code crashed.

MinionAttack commented 3 years ago

@yzhangcs Oh, I see. The problem is that I was assuming that pip install supar would install version 1.1.1 but when I saw in the requirements that you need Python>=3.7, I checked what Python is installed in the conda environment of the project where I want to integrate it and I found out that it uses version 3.6.9, so PIP has installed version 1.0.1 of SuPar.

I'm going to try to update the Python version to 3.7, I understand that then PIP will install SuPar version 1.1.1 as right now it won't let me install a version higher than 1.0.1.

Thank you very much for your help.