Creating a Simple AI Language Model on Hugging Face Spaces
The 2 Toolsets and Workflows to build the AI ML MODEL:
Google Collab Notebooks:
→ Code writing Tool / gives you lots of good supports for smithing your AI Code
→ What GCN does NOT do? It does not provide a Model Server environment for other people to connect to your Model and use it.
HuggingFace Spaces
HFS does not offer a code smithing environment:
Because HFS wants to be a professional grade project environment : Which MEANS:
They want to do CI / CD.
Continous Deployment MEANS we run a GIT HUB PIPELINE.
HFS is a MODEL serving environment: You create your PYTORCH Tensor File (ML MODEL) : and deploy it in a format that you can circulate the URL for other people to connect to and use your Model
You will deliver your Assignment using Google Collab Notebook
Deliver your Project using HuggingFace Spaces
You will deliver your Project by creating a CI CD Pipeline on GITLAB: I will interact with the teams by opening GIT ISSUES on your Code and you will open GIT Actions on those ISSUES by making GIT Actions.
You should have the GIT cli command line interface installed in your Operating System:
Hugging Face Spaces refers to the Spaces library developed by Hugging Face, a company that specializes in natural language processing (NLP) and machine learning (ML) applications.
The Spaces library provides an easy-to-use interface for processing, converting, and training neural models, while also integrating with various Hugging Face tools and platforms, such as the Transformers library and the Hub.
With Spaces, users can work seamlessly with popular NLP and ML frameworks, such as TensorFlow, PyTorch, and Scikit-Learn, and easily share and deploy models on various environments, such as cloud platforms and mobile devices.
Lab outcome:
Creating a simple AI language model on Hugging Face Spaces involves several steps:
1. Setting up your environment
2. Preparing your data
3. Building and training the model
4. Deploying it on Hugging Face Spaces.
Here's a step-by-step guide:
When you install the necessary libraries and set up your environment on your local machine, you are preparing your development environment to build and test your AI language model locally.
Here's how the connection between your local machine and Hugging Face servers works throughout the process:
Local Development
Set Up Your Environment Locally: (Open a Command Terminal and make a directory)
You install libraries like transformers and datasets on your local machine.
You can then use these libraries to develop and train your AI models locally.
Interacting with Hugging Face Hub
Download Pre-trained Models and Datasets:
When you use commands like GPT2LMHeadModel.from_pretrained('gpt2')
or
load_dataset('wikitext', 'wikitext-2-raw-v1'),
your local environment connects to Hugging Face servers to download pre-trained models and datasets.
Training and Fine-tuning Models Locally:
You train or fine-tune the models on your local machine using your datasets and compute resources.
Pushing to Hugging Face Hub
Upload Trained Models:
After training, you can push your trained model to Hugging Face Hub using commands like model.push_to_hub('your_model_name').
This uploads your model from your local machine to the Hugging Face server, making it available in the cloud.
Deployment on Hugging Face Spaces {Using HuggingFace Spaces as a Model Server}
Create and Deploy Space:
You create a new Space on Hugging Face, which is essentially a cloud environment provided by Hugging Face for hosting your applications.
You clone this Space repository to your local machine, add your code (e.g., a Gradio or Streamlit app), and push it back to Hugging Face.
Hugging Face then hosts your application in the cloud, making it accessible to others via a URL you provide to them.
Summary of Connections:
Downloading Models/Data:
Your local machine connects to Hugging Face servers to download pre-trained models and datasets.
Pushing Models:
Your local machine uploads trained models to Hugging Face servers.
Deploying Applications:
You push your application code to Hugging Face Spaces, and it gets hosted in the cloud.
Example Workflow {start by openning Command Terminal and making a Directory}
Install Libraries Locally:
bash
pip install transformers datasets
Download Model/Data:
python
### Make a Python Source Code file containing this code:
from transformers import GPT2LMHeadModel, GPT2Tokenizer
By following these steps, you effectively connect your local development environment to Hugging Face's cloud services, enabling you to develop, train, and deploy AI models efficiently.