Now that data models are created, we can start building the API: for starters, we load the language models with Spacy. You can get even more creative by composing and combining other complex types. EntityOut is simply a BaseModel class that represents the schema of each entity: it’ll have four fields: start (int), end (int), type (str) and text (str).Īs you see, it’s very intuitive to use Pydantic to build custom types for your requests and responses. anonymized_text is a string but entities is a List of EntityOut objects. It will have, as shown in the previous screenshot of the response’s body, two keys: entities and anonymized_text. As for the response’s body, we define the EntitiesOut class, again as a subclass of BaseModel. For the language, we want English (“en”) and French (“fr”) only, and for the size, we want three possible values (“sm” for small, “md” for medium and “lg” for large). The idea of using Enum is to limit possible values for each of the fields. These two classes inherit from str and Enum. I could’ve set the types of model_language and model_sizeto string, but, for the sake of this tutorial, I defined two classes for them: ModelLanguage and ModelSize. It’ll have three attributes: text, model_language and model_size. For the request’s body, we define the UserRequestIn as a subclass of the BaseModel class.Serving the API is uvicorn’s responsibility which is a good choice given that uvicorn is a lightning-fast ASGI server implementation, using uvloop and httptools. It has not the responsibility to serve them.įastAPI does one thing and it does it well. FastAPI is specifically designed to build APIs. However, unlike Flask, FastAPI doesn’t come with an integrated webserver. Instantiating Flask and FastAPI apps is merely the same. It actually resembles Flask’s syntax: so if you’re thinking about migrating from Flask to FastAPI, the transition should be easy. 1) A simple syntaxįastAPI’s syntax is simple and this makes it fast to use. PS: This list is not exhaustive and if you want to have a global overview, you can refer to the official documentation. Then, we’ll move to the part where we use FastAPI on a specific use case. Let me explain all the hype surrounding this framework by presenting the most interesting features I can think of. įastAPI has gained a lot of popularity lately and saw a huge increase in user adoption among web developers but also data scientists and ML engineers. Without further ado, let’s jump right in □. Deploying the API to AWS EC2 and automating the process with a Github Actions CI/CD.Packaging the API with Docker and docker-compose.Using FastAPI and SpaCy to build an inference API.Introduction to production machine learning and APIs.This is a relatively long post so feel free to skip to the parts you’re interested in. In this tutorial, I will present an end-to-end use case to explain the workflow of putting a model to production. It can be cumbersome and painful to manage but with the right tools, the process can go smoothly. This is a very common situation that data scientists face. Now is the time to put this model in production so that other teams within your organization can consume it and embed it in their applications. You’ve just trained a model and you’re happy with it because it performs well on your local cross-validation. You’re a data scientist and you work at a software company.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |