Git Product home page Git Product logo

ai-workshop's Introduction

Yonder AI Week - Workshop πŸ€–

In this workshop, you will learn how to use HuggingFace to run AI in your browser and how to integrate your fine-tuned model in your application. The workshop is divided into two chapters. In the first chapter, you will learn how to use pretrained models in a Next.js SSR application using transformers.js to solve different NLP tasks. In the second chapter, you will learn how to integrate your fine-tuned model in a Python FastAPI application.

Prerequisites πŸ“‹

  • Node.js 16.14 or later πŸ“‘
  • Python 3.9.X (venv and pip are included) 🐍
  • Docker 🐳 - Required only for DevContainer setup
  • VSCode πŸ“

Installation πŸ“¦

Local setup πŸ–₯️

  1. Clone the repository
  2. Install client dependencies inside client directory:
npm install
  1. Verify that Python 3.9.X is installed on your machine:
python --version # or python3 --version
  1. Install server dependencies inside server directory:

Linux/MacOS:

/usr/bin/python3 -m venv .env
source .env/bin/activate
pip install -r requirements.txt

Windows:

python -m venv .env
.env\Scripts\activate.bat
pip install -r requirements.txt

Dev Container setup 🐳

⚠️ For some reason the model inferrence doesn't work as expected as it gets stuck ⚠️

  1. Make sure you have Docker installed and running on your machine
  2. Open VSCode
  3. Install the Remote - Containers extension
  4. Press F1, select or search for Dev Containers: Clone Repository in Container Volume and paste the repository URL
  5. Wait for the container to build and to install the dependencies

Chapter I: Running AI in your browser with HuggingFace πŸš€

1. Running in development mode πŸƒ

Run the following command inside client directory:

npm run dev

2. Run your first Named Entity Recognition (NER) model πŸ•΅οΈ

  • Open your browser and navigate to http://localhost:3000. 🌐
  • Type a sentence in English in the text area: My name is John, I live in Singapore and work at Microsoft.
  • Analyze the the result. πŸ‘€
  • Try other sentences and see how the model performs.

Let's discover together the HuggingFace Platform and then analyze the code πŸ”

3. From NER to Fill Mask 🎭

  • Change the model from NER to Fill Mask (E.g. Xenova/distilbert-base-cased):
  • Try the same sentence as before: My name is John, I live in Singapore and work at Microsoft. but replace the word work with [MASK].
  • Analyze the the result. 🧐

4. "Trying to teach a dog to meow" 🐢

  • Let's do a zero-shot classification (E.g. Xenova/bart-large-mnli)
  • Open client/src/app/api/text-classification/route.ts
  • Modify the code so you can support different labels/categories await classifier(text, ["cat1", "cat2", "cat3"]);

Everything looks great but how can I customize existing models?

Chapter II: Fine-tuning a model with HuggingFace πŸŽ“

Check this awesome explaination: A brief introduction to transformers πŸ“°

Then we will follow the notebook in Google Collab πŸ““

Chapter III: Integrate your fine-tuned model in your application πŸ“²

1. Deploy your model 🚒

Copy the model directory to server

Let's analyze the code πŸ”

2. Running the server πŸƒ

Run the following command inside server directory:

uvicorn main:app --reload

3. Viewing your resume in the browser πŸ‘€

Using Swagger UI πŸ“Š

  • Open your browser and navigate to http://localhost:8000/docs. You should see the Swagger UI.
  • Open the POST / endpoint and click on Try it out.
  • Choose a file to upload and select your resume (E.g. resume.pdf).
  • Click on Execute and analyze the JSON Response.

Using Web UI 🌐

  • Open your browser and navigate to http://localhost:3000/resume.
  • Upload your resume and analyze the UI result.

Using Notebook πŸ““

  • In Google Colab, open nlp_workshop_resume_analysis.ipynb and follow the instructions.

ai-workshop's People

Contributors

clnnn avatar vprecup avatar

Stargazers

stefan.stanescu avatar Paul Cirstean avatar Denis Gheorghita avatar Claudiu Apetroaei avatar

Watchers

Răzvan Dragomir avatar Toni Simu avatar  avatar

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.