pickle module doens't work

Tim Roberts timr at probo.com
Tue Jan 1 20:14:28 CET 2013

Omer Korat <animus.partum.universum at gmail.com> wrote:
>I am using the nltk.classify.MaxEntClassifier. This object has a set of 
>labels, and a set of probabilities: P(label | features). It modifies 
>this probability given data. SO for example, if you tell this object 
>that the label L appears 60% of the time with the feature F, then 
>P(L | F) = 0.6. 
>The point is, there is no way to access the probabilities directly. 
>The object's 'classify' method uses these probabilities, but you can't
>call them as an object property. 

Well, you have the source code, so you can certainly go look at the
implementation and see what the data is based on.

>In order to adjust probabilities, you have to call the object's 'train' 
>method, and feed classified data in.

The "train" method is not actually an object method, it's a class method.
It doesn't use any existing probabilities -- it returns a NEW
MaxEntClassifier based entirely on the training set.

>So is there any way to save a MaxEntClassifier object, with its 
>classification probabilities, without having to call the 'train' method?

If you haven't called the "train" method, there IS no MaxEntClassifier
object.  Once you have called "train", you should be able to pickle the new
MaxEntClassifier and fetch it back with its state intact.
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

More information about the Python-list mailing list