Spacy is a open source python tool widely used for Advanced Natural Language Processing. It comes with a lot of pretrained deep learning models for tagging, text classification, named entity recogntition and many other tasks. We can install spacy using pip, conda or can build from source. We can also use CPU or GPU for training and inference of pipelines.
To install spacy using pip, we need to open command promot and run pip install command.
pip install spacy
And for GPU, it requires a little modification, you need to setup cuda and cudnn for that.
pip install -U spacy[cuda102]
To install using conda, we can use conda commands, you must have conda installed on your system.
conda install -c conda-forge spacy
Once we have installed spacy, now we can download pre-trained model. Pretrained model download may require administration access. For example, we can download a simple model using this command.
python -m spacy download en_core_web_sm
There are a lot of different pretrained models available from spacy for different languages and with different parameters. We can use them by downloading from their repository. Get to this url to view list of all available models from spacy.
After model download we, can test this model
To test downloaded model, we can load model in python script and perform a simple NLP query for a sentense.
import spacy nlp = spacy.load("en_core_web_sm") doc = nlp("Great! Ali and his friend are the only brilliant boys with highest score in class")
Now we can iterate to view all tokens and their properties.
for token in doc: print(token.text, token.lemma_, token.pos_, token.tag_, token.dep_, token.shape_, token.is_alpha, token.is_stop)