0

I want to print Parse Tree using Spacy. But the code below is giving the error

en_nlp = spacy.language('English') TypeError: 'module' object is not callable

The error is on this en_nlp = spacy.loads('en') line. I tried to shake off as en_nlp = spacy.language(English) by importing from spacy.en import English But still it is not working. Can someone help?

Code:

import spacy
from nltk import Tree

en_nlp = spacy.loads('en')

doc = en_nlp("The quick brown fox jumps over the lazy dog.")

def to_nltk_tree(node):
    if node.n_lefts + node.n_rights > 0:
        return Tree(node.orth_, [to_nltk_tree(child) for child in node.children])
    else:
        return node.orth_


[to_nltk_tree(sent.root).pretty_print() for sent in doc.sents]
3
  • From the error, spacy.language is a module, not a callable method Commented Sep 4, 2016 at 15:17
  • Try using spacy.load('en') without the 's' Commented Sep 4, 2016 at 15:19
  • @mpurg Still not working without 's'. Commented Sep 4, 2016 at 15:40

1 Answer 1

1

Is it spacy.load('en') or spacy.loads('en') ?

The official doc https://spacy.io/docs/ says : spacy.load('en'). It may be the problem.

Sign up to request clarification or add additional context in comments.

2 Comments

what is the error when you replace spacy.loads by spacy.load() ?
OMG I got this RuntimeError: Model 'en' not installed. Please run 'python -m spacy.en.download' to install latest compatible model. Now I am installing . Will be back in a sec.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.