Please explain collections.defaultdict(lambda: 1)
Duncan Booth
duncan.booth at invalid.invalid
Tue Nov 6 10:23:50 EST 2007
"metaperl.com" <metaperl at gmail.com> wrote:
> Per http://docs.python.org/lib/defaultdict-examples.html
>
> It seems that there is a default factory which initializes each key to
> 1. So by the end of train(), each member of the dictionary model will
> have value >= 1
>
> But why wouldnt he set the value to zero and then increment it each
> time a "feature" (actually a word) is encountered? It seems that each
> model value would be 1 more than it should be.
>
The author explains his reasoning in the article: he wants to treat novel
words (i.e. those which did not appear in the training corpus) as having
been seen once.
More information about the Python-list
mailing list