pyheartex
pyheartex copied to clipboard
sklearn adapter unable to load freshly created model
With the following dict as the value of the train_output
parameter to the SklearnTextClassifier.load
method in pyheartex/htx/adapters/sklearn.py
:
{'model': '/Users/wollivier/.heartex/models/1.my_super_model/1582135897/model.joblib', 'idx_choice_map': '/Users/wollivier/.heartex/models/1.my_super_model/1582135897/idx_choice_map.json'}
the sklearn adapter is not able to load the newly generated model, because it is passing the file name string to json.load
instead of passing the file object for the pointed file
127.0.0.1 - - [19/Feb/2020 18:11:39] "POST /predict HTTP/1.1" 500 -
Traceback (most recent call last):
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/wollivier/.pyenv/versions/3.7.6/envs/arcana/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/wollivier/dev/ARCANA/pyheartex/htx/htx.py", line 36, in _predict
results, model_version = _model_manager.predict(tasks, project, schema, model_version, **params)
File "/Users/wollivier/dev/ARCANA/pyheartex/htx/model_manager.py", line 162, in predict
model = self._create_model_from_job_result(job_result, schema)
File "/Users/wollivier/dev/ARCANA/pyheartex/htx/model_manager.py", line 95, in _create_model_from_job_result
model.load(resources)
File "/Users/wollivier/dev/ARCANA/pyheartex/htx/adapters/sklearn.py", line 25, in load
self._idx_choice_map = json.load(train_output['idx_choice_map'])
File "/Users/wollivier/.pyenv/versions/3.7.6/lib/python3.7/json/__init__.py", line 293, in load
return loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'