I have searched around but unfortunately found nothing that could help me to solve this problem. I have made this unigram tagger and have saved it in this way :
output = open("nameofthefile.pkl","wb")
pickle.dump(taggerfunction,output)
output.close()
45B is saved into the "nameofthefile.pkl" so it is not empty.
then I close the jupyter notebook and open another one and try to load the pickle file in this way:
inp = open("nameofthefile.pkl","rb")
tagger = pickle.load(inp)
inp.close()
but I get this error :
AttributeError: Can't get attribute 'nameofthefunction' on <module 'main'>
Somebody said that it is because I have imported a module in the function that I saved for pickling and when I try to pickle load the function, it does not work.
but I built another module to test whether the error was because of that:
def another_function(numb1,numb2):
if isinstance(numb1 and numb2,int):
return numb1+numb2
else:
return "your values are not all INTEGERS"
then I pickled it:
output = open("justafunction.pkl","wb")
pickle.dump(another_function,output)
output.close()
I built this in a jupyter notebook called, let's say "notebook_1" and then went and open another notebook, let's say it's called "notebook_2" and tried to pickle load the function:
inp = open("justafunction.pkl","rb")
pickle.load(inp)
inp.close()
but still got the same error:
-------------------------------------------------
--------------------------
AttributeError
Traceback (most recent call last)
<ipython-input-2-416ed412eb60> in <module>
1 inp = open("justafunction.pkl","rb")
----> 2 pickle.load(inp)
AttributeError: Can't get attribute
'another_function' on <module '__main__'>
IS IT BECAUSE I USE DIFFERENT NOTEBOOKS FOR DUMPING AND LOADING THE PICKLE FILE??