This project is devoted to a Flask HTTP service aimed at providing the classification of intents from text, utilizing the ATIS dataset as the core dataset for training Transformer model.
The corresponding AI/ML implementation, research, and results can be found under ml
directory and in detail described in ml/README.md
.
While the dataset consists of English texts, the service is able to detect intents correctly for some languages (see example below) 😊.
The model is exported to ONNX and running on CPU, while it will be very easy to move it on GPU instances in case the load on the server increases or/and we look for faster SLA. (Roughly a GPU instance costs 2x CPU on AWS).
Below, I've included details about the Flask service and instructions on how to run it.
brew install docker
brew install docker-compose
Download model.onnx
file from Google Drive (model link 📦🔗) and move it under ml/models/all-mpnet-base-v2-tuned
directory
In the project root directory run the following command in your terminal:
make
That is it! Now you can send request to the Flask API on http://127.0.0.1:8080 🎉
This API classifies user intents from text using a neural network model and offers two endpoints:
- POST: Classify intents from text.
- Request: JSON body with
"text"
field. - Response: JSON array of predicted top-k intents. See the example response below.
- text
string
: Text to be classified.
Example Request:
{
"text": "find me a flight that flies from memphis to tacoma"
}
- label
string
: The name of the predicted intent. - confidence
float
: The probability score for the predicted intent.
Example Response:
{
"intents": [
{
"label": "flight",
"confidence": 0.73
},
{
"label": "aircraft",
"confidence": 0.12
},
{
"label": "capacity",
"confidence": 0.03
}
]
}
- GET: Check if the model is ready.
Example Response:
OK
Or
Not ready
Request JSON:
{
"text": "Does Chicago Airport offer transportation from the airport to the downtown area?"
}
Response JSON:
{
"intents": [
{
"confidence": 0.9949638843536377,
"label": "ground_service"
},
{
"confidence": 0.0007102342206053436,
"label": "ground_service+ground_fare"
},
{
"confidence": 0.0005169900832697749,
"label": "abbreviation"
}
]
}
A bit of my curiosity to challenge the model. Here, I provide examples of intent classification using text in various languages, note that the model was not fine-tuned with non-English texts. The same request from above has been translated into different languages using Google Translator. And of course we cannot assume that the model will correctly classify all non-English requests.
{
"text": "Bietet der Flughafen Chicago einen Transport vom Flughafen in die Innenstadt an?"
}
{
"intents": [
{
"confidence": 0.9946973323822021,
"label": "ground_service"
},
{
"confidence": 0.0006867669872008264,
"label": "ground_service+ground_fare"
},
{
"confidence": 0.0006053699180483818,
"label": "abbreviation"
}
]
}
{
"text": "L'aéroport de Chicago propose-t-il un transport de l'aéroport au centre-ville?"
}
{
"intents": [
{
"confidence": 0.9948626160621643,
"label": "ground_service"
},
{
"confidence": 0.0006891299854032695,
"label": "flight"
},
{
"confidence": 0.0006123234634287655,
"label": "ground_service+ground_fare"
}
]
}