Load_learner - AttributeError: Can't get attribute 'cluster' on <module 'spacy.lang.lex_attrs'

Hi there,

I’m trying to load an exported fastai v2 model into a production environment by loading the model into a flask app.

My code is pretty simple:

from fastai2.text.all import load_learner
from fastai2.imports import *
from flask import Flask
app = Flask(__name__)
path = Path()
# print(path.ls(file_exts='.pkl'))
learn_inf = load_learner(path/'exported-model.pkl')

def hello():
    return "Hello World!"

@app.route('/predict', methods=['POST'])
def show_post():
    data = request.json
    return learn_inf.predict(data.q)

if __name__ == '__main__':

But when I run the app, I get this error:

AttributeError: Can't get attribute 'cluster' on <module 'spacy.lang.lex_attrs' from '/Users/username/.local/share/virtualenvs/news-category-predictor-fsb6DkGE/lib/python3.7/site-packages/spacy/lang/lex_attrs.py'>

When I try to run load_learner from a Colab notebook with the same model, it’s working. Am I missing something or completely down the wrong path here?


It might be due to the version of spacy. Check it in Colab and in your local Python virtual environment to see if they are different.

Hmm thanks for that suggestion. I matched the spacy version in my Pipfile to the Colab version and no dice.

Im stuck on this too. Was there any resolution. I’m using spacy 2.3.4 for the production. Any workarounds for this issue?

1 Like

I was stuck in similar problem. Found that the if pickle file was generated was using old version of spacy and currently new version is present in the system then it will cause the error. Could be solved by regenerating pickle file using newer version of spacy.