Home Machine Learning Finish-to-Finish NLP Undertaking with Hugging Face, FastAPI, and Docker | by Kasper Groes Albin Ludvigsen | Mar, 2024

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

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

[ad_1]

This tutorial explains how you can construct a containerized sentiment evaluation API utilizing Hugging Face, FastAPI and Docker

Photograph by Joshua Hoehne on Unsplash

Many AI initiatives fail, in line with varied experiences (eg. Hardvard Enterprise Assessment). I speculate that a part of the barrier to AI mission success is the technical step from having constructed a mannequin to creating it extensively obtainable for others in your group.

So how do you make your mannequin simply obtainable for consumption? A technique 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 are going to take a sentiment evaluation mannequin from Hugging Face (an arbitrary selection simply to have a mannequin that’s straightforward to point out for example), 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 best way.

The tutorial code has been examined on Linux, and will work on Home 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 straightforward to make use of fashions corresponding to sentiment fashions. Take a look at Hugging Face’s sentiment evaluation tutorial for an intensive introduction to the idea.

You may instantiate the pipe with a number of completely different constructor arguments. A technique is to go in a sort of process:

from transformers import pipeline

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

This may use Hugging Face’s default mannequin for the offered process.

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

[ad_2]