TextBlob Extensions
Usage
TextBlob supports adding custom models and new languages through “extensions”. Check out the TextBlob docs (https://textblob.readthedocs.io/en/dev/extensions.html#extensions) for more details.
spacytextblob also supports the use of TextBlob extensions. To use a TextBlob extension you need to pass some additional information to the config
parameter when initializing the spacytextblob pipeline component.
- Load the TextBlob extension package.
- For a function to be used inside the NLP pipeline you must register the function with spacy using
@spacy.registry.misc()
. You can name the function what ever you like. For the example I have registered the function with the name"spacytextblob.fr_blob"
. - spacytextblob is able to support TextBlob extensions by replacing the default
textblob.TextBlob
with an alternative. - Add spacytextblob to your spaCy pipeline as you normally would.
- The
config
parameter allows you to pass additional configuration options to the spacytextblob pipeline. - The
"custom_blob"
key should be assigned to a dictionary that tells spaCy what function to replacetextblob.TextBlob
with. In this case, we want to replace it withTextBlobDE
. The key of the dictionary is"@misc"
. This tells spaCy to look into the misc section of the spaCy register. The value should be the string name of the function that we registered above in line 12.
Extensions
The following extensions have been tested and are supported. Other extensions may work, but have not been tested.
textblob-fr
textblob-fr is a TextBlob extension that enables French language support for TextBlob (https://github.com/sloria/textblob-fr).
To use it with spacytextblob First install a spaCy model that supports French (https://spacy.io/models/fr):
The code below demonstrates how you can then use and access textblob-fr within spacytextblob.
textblob-de
Warning
textblob-de is not supported. As of spacytextblob 4.1.0. The textblob-de library depends on a Google Translate feature that no longer works. More details can be found in this issue https://github.com/markuskiller/textblob-de/issues/24.
textblob-aptagger
Warning
textblob-aptagger is not supported. As of TextBlob 0.11.0, TextBlob uses NLTK's averaged perceptron tagger by default. This package is no longer necessary (https://github.com/sloria/textblob-aptagger).