Home Artificial Intelligence End-to-End NLP Project with Hugging Face, FastAPI, and Docker Step 1: Create Hugging Face model pipeline

End-to-End NLP Project with Hugging Face, FastAPI, and Docker Step 1: Create Hugging Face model pipeline

0
End-to-End NLP Project with Hugging Face, FastAPI, and Docker
Step 1: Create Hugging Face model pipeline

This tutorial explains the right way to construct a containerized sentiment evaluation API using Hugging Face, FastAPI and Docker

Towards Data Science
Photo by Joshua Hoehne on Unsplash

Many AI projects fail, in response to various reports (eg. Hardvard Business Review). I speculate that a part of the barrier to AI project success is the technical step from having built a model to creating it widely available for others in your organization.

So how do you make your model easily available for consumption? A technique is to wrap it in an API and containerize it in order that your model may be exposed on any server with Docker installed. And that’s exactly what we’ll do on this tutorial.

We are going to take a sentiment evaluation model from Hugging Face (an arbitrary alternative simply to have a model that’s easy to indicate for example), write an API endpoint that exposes the model using FastAPI, after which we’ll containerize our sentiment evaluation app with Docker. I’ll provide code examples and explanations all the way in which.

The tutorial code has been tested on Linux, and will work on Windows too.

We are going to use the Pipeline class from Hugging Face’s transformers library. See Hugging Face’s tutorial for an introduction to the Pipeline when you’re unfamiliar with it.

The pipeline makes it very easy to make use of models comparable to sentiment models. Take a look at Hugging Face’s sentiment evaluation tutorial for an intensive introduction to the concept.

You possibly can instantiate the pipe with several different constructor arguments. A technique is to pass in a sort of task:

from transformers import pipeline

pipe = pipeline(task="sentiment-analysis")

This can use Hugging Face’s default model for the provided task.

One other way is to pass the model argument specifying which model you need to use. You don’t…

LEAVE A REPLY

Please enter your comment!
Please enter your name here