Project: Building a Domain Expert Model for Introducing Generative AI with AWS course

Pratik Khose
7 min readJul 22, 2024

--

Project Introduction

As an AI engineer, I was tasked with developing a proof of concept (POC) for a domain expert model aimed at enhancing customer experience and streamlining information delivery. This model, trained on a dataset of domain-specific knowledge (finance, medical, or IT), will be capable of generating informative, accurate, and contextually relevant text responses. My goal is to create a knowledgeable consultant for the company, which can be used in chat applications, internal knowledge applications, or for generating text content for company collateral.

Project Objective

The main objective of this project is to fine-tune a large language model to become a domain expert. This involves:

  1. Selecting the Dataset: Choosing an appropriate, copyright-free unstructured text dataset relevant to a specific domain (finance, medical, or IT).
  2. Fine-tuning the Language Model: Using Amazon Sagemaker and other AWS tools to fine-tune the Meta Llama 2 7B foundation model, adapting it to the selected domain.
  3. Deliverables:
  • A fine-tuned language model proficient in the chosen domain.
  • Documentation of the process, challenges, and solutions.

The Challenge

Selecting the Dataset

I needed to choose an appropriate, copyright-free unstructured text dataset relevant to the selected domain. This dataset would serve as the training ground for the model to learn domain-specific language and concepts.

Overview of Project Tasks

Fine-tuning the Language Model

Configure AWS Sagemaker Resources:

  • Set up an AWS Sagemaker IAM Role.
  • Create an AWS Sagemaker Notebook Instance.
  • Request a GPU instance for fine-tuning training.

Deploy Meta Llama 2 7B Model:

  • Deploy the foundation model on the AWS platform.
  • Test and evaluate the model’s responses to domain knowledge and text-generation tasks.

Fine-tune the Model:

  • Fine-tune the model using the chosen dataset.
  • Deploy the fine-tuned model.
  • Test the fine-tuned model on domain-specific knowledge and text generation tasks relevant to the dataset.

Document and Submit:

  • Document the process, challenges, and solutions.
  • Submit the completed project, including all required deliverables.

What I Learnt

  • Advanced skills in machine learning and natural language processing.
  • Hands-on experience with AWS tools like Amazon Sagemaker.
  • Insights into domain-specific language model training.
  • Practical application of AI in solving real-world business challenges.

Project Costs Warning

I have a budget of $25 on AWS to complete this project. Managing these costs is crucial. I need to stop resources when not in use and delete model resources and endpoints after completion. No budget increases will be provided.

Configuring My Project Environment

To configure the required resources on the AWS platform, I followed these steps:

  1. An AWS SageMaker IAM Role
  2. An AWS SageMaker Notebook Instance
  3. A GPU instance for fine-tuning training
  4. Download the project starter files

I made sure to start and stop the SageMaker Notebook Instance as needed, ensuring my Jupyter Notebook Python files were saved. It’s crucial to stop the notebook instance when not in use.

I ensured I was always working in the US-west-2 Region by checking and changing the region in the dropdown menu at the top of the AWS console to US West Oregon (us-west-2).

Configuring an IAM Role for AWS SageMaker

I logged into the AWS console using the “Launch Cloud Gateway” button in the course menu and navigated to the SageMaker home page.

In the left navigation menu, I chose “Role manager” and clicked on “Create a role”.

I named the SageMaker role udacitySagemakerRole for easy identification. I configured the role with the following settings:

  • Chose “SageMaker Compute Role” for the role persona.
  • Checked all ML activities up to “S3 full access”.
  • Added AmazonSageMakerFullAccess to the role.
  • I validated the permissions in my role to ensure all necessary permissions were assigned to complete the project.

Creating an AWS SageMaker Notebook Instance

  1. I navigated to the SageMaker home page in the AWS console and chose “Notebook” -> “Notebook instances” from the left navigation menu.
  2. I clicked on “Create notebook instance” at the top of the page.
  3. I named my notebook instance and ensured I chose the IAM SageMaker role I created earlier (udacitySagemakerRole).

Requesting a GPU Instance for Training

  1. I visited the AWS Service Quotas dashboard to request an ml.g5.2xlarge instance for training job usage.
  2. In the AWS Services dropdown menu at the top of the page, I chose or typed SageMaker, then clicked “View quotas”.
  3. In the “Search by quota name” search box, I entered ml.g5.2xlarge.
  4. I located the row that says ml.g5.2xlarge for training job usage and filled in the circle next to it.
  1. I clicked on the “Request increase at account-level” button at the top of the page and entered 1 instance in the request form.
  1. I submitted the request and verified its approval by visiting the Quota request history page.

Downloading the Project Starter Files

I downloaded the project starter files, which included the Python notebooks I would use for the project and the Project Documentation Report.

Project Summary:-

Configure Your AWS Sagemaker Resources

AWS SageMaker IAM Role: I created an IAM role with necessary permissions for running Jupyter Notebook files, accessing AWS S3 Storage Buckets, and managing model deployment and training jobs.

AWS SageMaker Notebook Instance: I created a notebook instance for the project and linked it to the IAM role created in step 1.

Request a GPU Instance for Training: I submitted a request for a ml.g5.2xlarge instance for training the model.

Download Project Starter Files

I uploaded the project starter files to JupyterLab within my SageMaker Notebook Instance.

Choose Your Dataset

I selected a domain (Finance, IT, Healthcare/Medical) and prepared the dataset for fine-tuning the model.

Deploy and Evaluate the Model

  • I deployed the Meta Llama 2 7B model and evaluated its performance.
  • I documented the evaluation process and results.

Fine-tune the Model

  • I fine-tuned the model using the chosen dataset.
  • I documented the fine-tuning process and results.

Deploy and Evaluate the Fine-tuned Model

  • I deployed the fine-tuned model and evaluated its performance on domain-specific tasks.
  • I documented the evaluation process and results.

Collect Project Documentation and Submit

  • I compiled all project files, including notebooks with cell outputs, screenshots, and the completed Project Documentation Report.
  • I zipped the folder containing all files and submitted the project.

Important Points to Remember

  1. Session Limit: There is a session time limit on the AWS Cloud Lab. I need to save my work periodically and stop the notebook instance when not in use.
  2. Default AWS Region: I need to ensure I am working in the US-west-2 Region.
  3. Budget Management: I will monitor my AWS usage to stay within the $25 budget. I will shut down unnecessary resources immediately after use.
  4. Track Your Usage: I will use the AWS Cost Explorer to track my spending and ensure I have enough budget to complete the project.

Configuring Your Project Environment

1.Create an IAM Role for AWS SageMaker:

  • I followed the instructions to create a SageMaker role with all necessary permissions.

2.Create an AWS SageMaker Notebook Instance:

  • I set up a notebook instance and linked it to the IAM role created.

3.Request a GPU Instance for Training:

  • I submitted a request for a ml.g5.2xlarge instance for training job usage.

4.Upload Project Starter Files:

  • I started the SageMaker Notebook Instance and uploaded the Python notebook files.

5.Choose Your Dataset:

  • I selected the domain-specific dataset and prepared it for training.

6.Deploy and Evaluate the Model:

  • I completed and ran the cells in the Model_Evaluation.ipynb file.
  • I documented the evaluation process and results.

7.Fine-tune the Model:

  • I completed and ran the cells in the Model_FineTuning.ipynb file.
  • I documented the fine-tuning process and results.

8.Deploy and Evaluate the Fine-tuned Model:

  • I deployed the fine-tuned model and evaluated its performance.
  • I documented the evaluation process and results.

9.Collect Project Documentation and Submit:

  • I compiled all project files, including notebooks with cell outputs, screenshots, and the completed Project Documentation Report.
  • I zipped the folder containing all files and submitted the project.

Post Project Submission-

Make sure to read the things from the video so that you dont miss things like I did while uploading the project.

Summary

By following these steps, you have gained hands-on experience in building and evaluating a Machine Learning using AWS SageMaker. This exercise demonstrates how machine learning can provide valuable insights into customer behavior, helping businesses make data-driven decisions.

🎥 Watch the demonstration video: https://youtu.be/sxSVi2dTFPo?si=nkcGoSZj3bAmMaD7
📂 Check out the GitHub documentation: https://github.com/Pratik-Khose/AWS-Machine-Mearning-projects

Let’s connect and discuss more about these kind of projects. Always eager to learn and collaborate on innovative projects! 🌟

#MachineLearning #NeuralNetwork #CustomerBehavior #AWS #SageMaker #DataScience #BinaryClassification #PredictiveModeling

--

--