Use Case: Natural Language Processing API
Overview
This use case demonstrates building a Natural Language Processing (NLP) API using TextBlob for common text operations, such as noun phrase extraction, part-of-speech tagging, sentiment analysis, and tokenization.
Problem Scenario
With advancements in NLP, we can now communicate with machines using natural language. From chatbots to virtual assistants, NLP applications are present in our daily lives. This use case explores using TextBlob for simple and effective NLP processing.
Description
We will build an NLP API with four key functions—noun phrase extraction, part-of-speech tagging, sentiment analysis, and tokenization—using SnapLogic’s Remote Python Script Snap and SnapLogic Ultra Task.
Objectives
- Model testing: Use Remote Python Script Snap to test NLP operations with sample data.
- Model hosting: Deploy the NLP model as an API using SnapLogic Ultra Task.
- API testing: Verify API functionality with REST requests.
Model testing
In this pipeline, we test the NLP operations by creating text samples for each operation using the JSON Generator Snap.
Each document generated includes $operation and $text fields, which the Remote Python Script Snap processes. The Snap uses TextBlob to execute the specified NLP operation and returns the output.
Model hosting
This pipeline deploys the NLP model as an API using SnapLogic Ultra Task, accessible by external applications.
The pipeline includes the Remote Python Script Snap, which performs the NLP operations as defined. The Filter Snap verifies incoming requests, while the Extract Params Snap (Mapper) retrieves required fields. The Prepare Response Snap (Mapper) formats the results for the response body and adds CORS headers.
Building API
To deploy the pipeline as a REST API, click the calendar icon in the toolbar and choose either a Triggered Task or an Ultra Task.
Triggered Task: Suitable for batch processing, starting a new pipeline instance per request.
Ultra Task: Preferred for low-latency REST API access.
To get the API URL, open the Create Task window, select Show tasks in this project in Manager, and click Details.
API testing
This pipeline tests the API by generating sample requests using the JSON Generator Snap and sending them to the Ultra Task via the REST Post Snap.
The final Mapper Snap extracts $response.entity from the response, confirming API functionality for each NLP operation.