Coder Social home page Coder Social logo

fastapi_nlp_docker's Introduction

TL; DR:

In this article, we are going to build a NLP model (v2) and using FastAPI create REST API calls to predict from the model, and finally containerize it using Docker ๐Ÿ˜ƒ I want to emphasize the usage of FastAPI and how rapidly this framework is a game-changer for building easy to go and much faster API calls for a machine learning pipeline. Traditionally, we have been using Flask Microservices for building REST API calls but the process involves a bit of nitty-gritty to understand the framework and implement it. On the other end, I found FastAPI to be pretty user-friendly and very easy to pick up and implement type of framework. And finally from one game-changer to another, Docker As a data scientist: our role is vague and it keeps on changing year in year out. Some skillset gets added, some get extinct and obsolete, but Docker has made its mark as one of the very important and most sought out skills in the market. Docker gives us the ability to containerize a solution with all its binding software and requirements.

The Data

We have used a text classification problem : IMDb Dataset for the purpose of building the model. The dataset comprises 50,000 reviews of movies and is a binary classification problem with the target variable being a sentiment: positive or negative.

Project

| |--- model

| |______ model.pkl

| |--- app

| |_______ main.py

|

|--- Dockerfile

FastAPI

Docker

Finally, to wrap it all up, we create a Dockerfile :

We have attached a docker container (tiangolo/uvicorn-gunicorn-fastapi) which is made public on docker-hub, which makes quick work of creating a docker image on our own functionalities.

To create a docker image and deploy it, we run the following commands, and voila!

docker build -t api .

docker run -d -p 8000:8000 api

Conclusion

After going through the process of working around FastAPI and Docker, I feel this skillset is a necessary repertoire in a data scientist's toolkit. The process of building around our model and deploying it has become easier and much more accessible than it was before.

Reference:

https://www.youtube.com/watch?v=7t2alSnE2-I

https://dev.to/kushalvala/tensorflow-model-deployment-using-fastapi-docker-4183

https://nickc1.github.io/api,/scikit-learn/2019/01/10/scikit-fastapi.html

https://github.com/akshaykhatale/fastapi-heroku-docker

https://www.freecodecamp.org/news/how-to-deploy-an-nlp-model-with-fastapi/

https://github.com/kaustubhgupta/FastAPI-KivyMD-App-Demo

https://www.analyticsvidhya.com/blog/2021/06/deploying-ml-models-as-api-using-fastapi-and-heroku/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.