How could I inline nltk graph to jupyter notebook?
See original GitHub issueI have already asked this question on stackoverflow without any luck and decide to duplicate it here.
According to the sources of nltk
it draws graph by tkinter (GUI)
but I need to inline this graph to jupyter notebook
. And I’m trying to do it inside of official docker from anaconda3 in other words I don’t need any popup GUI here but just image inside of notebook, that should be render on server side by nltk lib.
How could I overcome this by nltk? Maybe there is third party libs which could help there?
Sources of my try is here - the last 18th cell.
chunkGram = r"""Chunk: {<RB.?>*<VB.?>*<NNP>+<NN>?}"""
chunkParser = nltk.RegexpParser(chunkGram)
for i in tokenized_text[:5]:
words = nltk.word_tokenize(i)
tagged = nltk.pos_tag(words)
chunked = chunkParser.parse(tagged)
chunked.draw()
PS: in the same time matplotlib inline by itself works like a charm. Could I use matplotlib for graph rendering?
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How do you make NLTK draw() trees that are inline in iPython ...
Based on this answer: import os from IPython.display import Image, display from nltk.draw import TreeWidget from nltk.draw.util import CanvasFrame def ...
Read more >How to Plot Inline and With Qt - Matplotlib with IPython/Jupyter ...
In this tutorial, we'll go over how to plot inline plots using IPyhon/Jupyter notebooks, with Matplotlib in Python. We'll cover how to plot...
Read more >Plotly - Plotting Inline with Jupyter Notebook - Tutorialspoint
Keep rest of the script as it is and run the notebook cell by pressing Shift+Enter. Graph will be displayed offline inside the...
Read more >How to Use "%matplotlib inline" (With Examples) - Statology
This tutorial explains how to use the "%matplotlib inline" function in Python Jupyter notebooks, including an example.
Read more >Displaying Matplotlib Graphs Inline in Jupyter Notebook
Displaying Matplotlib Graphs Inline in Jupyter Notebook. Updated to include how to modify the config file so this is the default behavior.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve recently put together a pure python=>SVG tree-drawing package that can be used as a drop-in replacement for
Tree
’s png-based repr in Jupyter. It may not be appropriate for everyone using NLTK, as it requires python 3 + it is still pretty early in its release cycle (and it is partly aimed at doing a bunch of other stuff that is perhaps less relevant to this audience). But, it solves the issues raised in this thread (and https://github.com/nltk/nltk/issues/1887), which have also been plaguing me:https://github.com/rawlins/svgling
(n.b. if you want to fully avoid tkinter-related issues in Jupyter, you may also need to remove
_repr_png_()
fromTree
. This is because Jupyter tries all available_repr_*_
functions even though it only displays one in typical circumstances, and saves the output of all of them in the notebook file.)Moving away from tkinter is a good idea in general, but there’s already support for rendering trees as inline PNGs in notebooks: