Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Named Entities Example Code #889

Closed
dmlicht opened this issue Mar 15, 2017 · 2 comments
Closed

Error in Named Entities Example Code #889

dmlicht opened this issue Mar 15, 2017 · 2 comments
Labels
docs Documentation and website

Comments

@dmlicht
Copy link

dmlicht commented Mar 15, 2017

The example code will fail because defaultdict takes a Callable. You can fix the documentation by changing the inner defaultdict to a Counter object. It would also be nice to include the import statement for VERB so people can quickly see what it is referencing. I'd be happy to update the docs in the proposed way, if you think it would be helpful.

Here's what happens.

def count_parent_verb_by_person(docs):
    counts = defaultdict(defaultdict(int))
    for doc in docs:
        for ent in doc.ents:
            if ent.label_ == 'PERSON' and ent.root.head.pos == VERB:
                counts[ent.orth_][ent.root.head.lemma_] += 1
    return counts

with the error:

<ipython-input-61-8df8d6283e14> in count_parent_verb_by_person(docs)
      6 
      7 def count_parent_verb_by_person(docs):
----> 8     counts = defaultdict(defaultdict(int))
      9     for doc in docs:
     10         for ent in doc.ents:

TypeError: first argument must be callable or None

spacy version: 1.6.0
Python 3.5.2 :: Continuum Analytics, Inc.

@dmlicht dmlicht changed the title error in Named entities example code Error in Named Entities Example Code Mar 15, 2017
@honnibal
Copy link
Member

A pull request would be great, thanks!

@honnibal honnibal added the docs Documentation and website label Mar 15, 2017
@ines ines closed this as completed in c6c3162 Apr 16, 2017
@lock
Copy link

lock bot commented May 8, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs Documentation and website
Projects
None yet
Development

No branches or pull requests

2 participants