Home Artificial Intelligence End-to-End NLP Project with Hugging Face, FastAPI, and Docker

End-to-End NLP Project with Hugging Face, FastAPI, and Docker

0
End-to-End NLP Project with Hugging Face, FastAPI, and Docker

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

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 method 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 point out 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 best way.

The tutorial code has been tested on Linux, and may 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 in the event you’re unfamiliar with it.

The pipeline makes it very easy to make use of models equivalent to sentiment models. Try Hugging Face’s sentiment evaluation tutorial for an intensive introduction to the concept.

You’ll be able to instantiate the pipe with several different constructor arguments. A method is to pass in a variety of task:

from transformers import pipeline

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

It will use Hugging Face’s default model for the provided task.

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here