fastAPI Transformer model serving
There are many web frameworks we can use for serving. Sanic, Flask, and fastAPI are just some examples. However, fastAPI has recently gained so much attention because of its speed and reliability. In this section, we will use fastAPI and learn how to build a service according to its documentation. We will also use pydantic
to define our data classes. Let's begin!
- Before we start, we must install
pydantic
and fastAPI:$ pip install pydantic $ pip install fastapi
- The next step is to make the data model for decorating the input of the API using
pydantic
. But before forming the data model, we must know what our model is and identify its input.We are going to use a Question Answering (QA) model for this. As you know from Chapter 6, Fine-Tuning Language Models for Token Classification, the input is in the form of a question and a context.
- By using the following data model, you can make the QA data model:
from pydantic import BaseModel...