<commit_before>//- 💫 DOCS > USAGE > VISUALIZERS > JUPYTER

p
    |  displaCy is able to detect whether you're working in a
    |  #[+a("https://jupyter.org") Jupyter] notebook, and will return markup
    |  that can be rendered in a cell straight away. When you export your
    |  notebook, the visualizations will be included as HTML.

+code("Jupyter Example").
    # don't forget to install a model, e.g.: python -m spacy download en
    import spacy
    from spacy import displacy

    doc = nlp(u'Rats are various medium-sized, long-tailed rodents.')
    displacy.render(doc, style='dep')

    doc2 = nlp(LONG_NEWS_ARTICLE)
    displacy.render(doc2, style='ent')

+aside("Enabling or disabling Jupyter mode")
    |  To explicitly enable or disable "Jupyter mode", you can use the
    |  #[code jupyter] keyword argument – e.g. to return raw HTML in a notebook,
    |  or to force Jupyter rendering if auto-detection fails.

+image("/assets/img/displacy_jupyter.jpg", 700, false, "Example of using the displaCy dependency and named entity visualizer in a Jupyter notebook")

p
    |  Internally, displaCy imports #[code display] and #[code HTML] from
    |  #[code IPython.core.display] and returns a Jupyter HTML object. If you
    |  were doing it manually, it'd look like this:

+code.
    from IPython.core.display import display, HTML

    html = displacy.render(doc, style='dep')
    display(HTML(html))<commit_msg>Add jupyter=True to displacy.render in documentation (#2806)<commit_after>//- 💫 DOCS > USAGE > VISUALIZERS > JUPYTER

p
    |  displaCy is able to detect whether you're working in a
    |  #[+a("https://jupyter.org") Jupyter] notebook, and will return markup
    |  that can be rendered in a cell straight away. When you export your
    |  notebook, the visualizations will be included as HTML.

+code("Jupyter Example").
    # don't forget to install a model, e.g.: python -m spacy download en
    import spacy
    from spacy import displacy

    doc = nlp(u'Rats are various medium-sized, long-tailed rodents.')
    displacy.render(doc, style='dep', jupyter=True)

    doc2 = nlp(LONG_NEWS_ARTICLE)
    displacy.render(doc2, style='ent', jupyter=True)

+aside("Enabling or disabling Jupyter mode")
    |  To explicitly enable or disable "Jupyter mode", you can use the
    |  #[code jupyter] keyword argument – e.g. to return raw HTML in a notebook,
    |  or to force Jupyter rendering if auto-detection fails.

+image("/assets/img/displacy_jupyter.jpg", 700, false, "Example of using the displaCy dependency and named entity visualizer in a Jupyter notebook")

p
    |  Internally, displaCy imports #[code display] and #[code HTML] from
    |  #[code IPython.core.display] and returns a Jupyter HTML object. If you
    |  were doing it manually, it'd look like this:

+code.
    from IPython.core.display import display, HTML

    html = displacy.render(doc, style='dep')
    display(HTML(html))
{'fraction_non_alphanumeric': 0.09887102292165584, 'fraction_numerical': 0.004789599726308587, 'mean_word_length': 3.540372670807453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7378889', 'n_tokens_mistral': 985, 'n_tokens_neox': 958, 'n_words': 347}