Do you want to add advanced & blazing fast Natural Language Processing (NLP) capabilities to your GUI app when building with Python Windows GUI Builder? This post will get you to understand how to use spaCy Python Library using Python4Delphi (P4D) in the Delphi/C++ Builder application and perform some advanced NLP tasks.
Table of Contents
What is spaCy?
spaCy is a free, open-source library for advanced Natural Language Processing (NLP) in Python. It’s designed specifically for production use and helps you build applications that process and “understand” large volumes of text. It can be used to build information extraction or natural language understanding systems.
What are spaCy’s features?
Here are spaCy powerful features overview:
- Support for 64+ languages
- 55 trained pipelines for 17 languages
- Multi-task learning with pre-trained transformers like BERT
- Pretrained word vectors
- State-of-the-art speed
- Production-ready training system
- Linguistically-motivated tokenization
- Components for named entity recognition, part-of-speech tagging, dependency parsing, sentence segmentation, text classification, lemmatization, morphological analysis, entity linking, and more
- Easily extensible with custom components and attributes
- Support for custom models in PyTorch, TensorFlow, and other frameworks
- Built-in visualizers for syntax and NER
- Easy model packaging, deployment, and workflow management
- Robust, rigorously evaluated accuracy
How do I enable spaCy for NLP inside Python4Delphi in Windows?
First, here is how you can get spaCy:
1 |
pip install -U spacy |
Is there a ready-trained speech recognition pipeline?
Empower your system by downloading the trained pipeline here:
1 |
python -m spacy download en_core_web_sm |
and don’t forget to put the path where your spaCy installed, to the System Environment Variables, here are the example:
1 2 3 |
C:/Users/YOUR_USERNAME/AppData/Local/Programs/Python/Python38/Lib/site-packages C:/Users/YOUR_USERNAME/AppData/Local/Programs/Python/Python38/Scripts C:/Users/YOUR_USERNAME/AppData/Local/Programs/Python/Python38 |
How do I perform NLP operations using spaCy inside Python4Delphi?
This post will guide you on how to perform advanced Natural Language Processing operations via Python’s spaCy and then display it in the Delphi Windows GUI app.First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind-the-scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.
Is there an example of how to use spaCy?
The following is a code example of spaCy to analyze syntax, find named entities, phrases, and concepts to any given documents (run this inside the lower Memo of Python4Delphi Demo01 GUI):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import spacy # Load English tokenizer, tagger, parser and NER nlp = spacy.load("en_core_web_sm") # Process whole documents text = ("Delphi supports rapid application development (RAD). Prominent features are a visual designer and two application frameworks, VCL for Windows and FireMonkey (FMX) for cross-platform development. Delphi uses the Pascal-based programming language Object Pascal created by Anders Hejlsberg for Borland (now IDERA) as the successor to Turbo Pascal. It supports native cross-compilation to many platforms including Windows, Linux, iOS and Android. To better support development for Microsoft Windows and interoperate with code developed with other software development tools, Delphi supports independent interfaces of Component Object Model (COM) with reference counted class implementations, and support for many third-party components. Interface implementations can be delegated to fields or properties of classes. Message handlers are implemented by tagging a method of a class with the integer constant of the message to handle. Database connectivity is extensively supported through VCL database-aware and database access components. Later versions have included upgraded and enhanced runtime library routines, some provided by the community group FastCode.") doc = nlp(text) # Analyze syntax print("Noun phrases:", [chunk.text for chunk in doc.noun_chunks]) print("Verbs:", [token.lemma_ for token in doc if token.pos_ == "VERB"]) # Find named entities, phrases and concepts for entity in doc.ents: print(entity.text, entity.label_) |
It runs blazingly fast, doing all the NLP operations smoothly for any text you feed to it as input!
Let’s see the result:
Congratulations, now you have learned how to perform advanced Natural Language Processing tasks via Python’s spaCy and then display it in the Delphi Windows GUI app.
Where can I find out more about natural language processing in my apps?
Check out the spaCy library for Python and use it in your projects: https://pypi.org/project/textblob/ ,
check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi,
or read our collections of NLP articles:
NLTK:
Gensim:
TextBlob:
FlashText: