The article aims to perform chunking and tagging over an execnet gateway. Here two objects will be sent instead of one, and a Tree is received, which requires pickling and unpickling for serialization.
How it works ?
- Use a pickled tagger.
- First, pickle the default chunker used by nltk.chunk.ne_chunk(), though any chunker would do.
- Next, make a gateway for the remote_chunk module, get a channel, and send the pickled tagger and chunker over.
- Then, receive a pickled Tree, which can be unpickled and inspected to see the result. Finally, exit the gateway:
Code : Explaining the working
Tree('S', [Tree('PERSON', [('Pierre', 'NNP')]), Tree('ORGANIZATION', [('Vinken', 'NNP')]), (', ', ', '), ('61', 'CD'), ('years', 'NNS'), ('old', 'JJ'), (', ', ', '), ('will', 'MD'), ('join', 'VB'), ('the', 'DT'), ('board', 'NN'), ('as', 'IN'), ('a', 'DT'), ('nonexecutive', 'JJ'), ('director', 'NN'), ('Nov.', 'NNP'), ('29', 'CD'), ('.', '.')])
Communication this time is slightly different as in figure given below –
- The remote_chunk.py module is just a little bit more complicated than the remote_tag.py module.
- In addition to receiving a pickled tagger, it also expects to receive a pickled chunker that implements the ChunkerIinterface
- Once it has both a tagger and a chunker, it expects to receive any number of tokenized sentences, which it tags and parses into a Tree. This Tree is then pickled and sent back over the channel:
Code : Explaining the above working
remote_chunk module’s only external dependency is the pickle module, which is part of the Python standard library. It doesn’t need to import any NLTK modules in order to use the tagger or chunker, because all the necessary data is pickled and sent over the channel.
- NLP | Distributed Tagging with Execnet - Part 1
- NLP | Distributed Tagging with Execnet - Part 2
- NLP | Chunking Rules
- NLP | Classifier-based Chunking | Set 2
- NLP | Classifier-based Chunking | Set 1
- NLP | Chunking and chinking with RegEx
- NLP | Chunking using Corpus Reader
- NLP | Parallel list processing with execnet
- NLP | How to score words with Execnet and Redis
- Python - R-distributed Distribution in Statistics
- Minimize the total number of teddies to be distributed
- ML | T-distributed Stochastic Neighbor Embedding (t-SNE) Algorithm
- Abstract Factory Method - Python Design Patterns
- Factory Method - Python Design Patterns
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.