0

I am trying to store this defaultdict object using pickle:

def dd():
    return defaultdict(int)
model = defaultdict(dd)

My first try was to use lambda, but according to this answer, I have changed it to external function. Still, when I want to load my object using following code:

import pickle
file = open("../model/trigram-model.pkl", "rb")
model = pickle.load(file)

It gives me the following error:

AttributeError: Can't get attribute 'dd' on <module '__main__' (built-in)>

I have tried redefining dd function as well, but it then shows:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 74
let me down slowly
  • 822
  • 10
  • 27

0 Answers0