Sunday, March 17, 2024

Finish-to-Finish NLP Venture with Hugging Face, FastAPI, and Docker | by Kasper Groes Albin Ludvigsen | Mar, 2024

Must read


This tutorial explains easy methods to construct a containerized sentiment evaluation API utilizing Hugging Face, FastAPI and Docker

Towards Data Science
Photograph by Joshua Hoehne on Unsplash

Many AI tasks fail, in keeping with numerous studies (eg. Hardvard Enterprise Assessment). I speculate that a part of the barrier to AI undertaking success is the technical step from having constructed a mannequin to creating it broadly obtainable for others in your group.

So how do you make your mannequin simply obtainable for consumption? A method is to wrap it in an API and containerize it in order that your mannequin may be uncovered on any server with Docker put in. And that’s precisely what we’ll do on this tutorial.

We’ll take a sentiment evaluation mannequin from Hugging Face (an arbitrary alternative simply to have a mannequin that’s simple to indicate for instance), write an API endpoint that exposes the mannequin utilizing FastAPI, after which we’ll containerize our sentiment evaluation app with Docker. I’ll present code examples and explanations all the way in which.

The tutorial code has been examined on Linux, and may work on Home windows too.

We’ll 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 simple to make use of fashions comparable to sentiment fashions. Try Hugging Face’s sentiment evaluation tutorial for a radical introduction to the idea.

You may instantiate the pipe with a number of totally different constructor arguments. A method is to move in a sort of activity:

from transformers import pipeline

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

It will use Hugging Face’s default mannequin for the offered activity.

One other manner is to move the mannequin argument specifying which mannequin you wish to use. You don’t…



Supply hyperlink

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article