Skip to main content
  1. Data Science Blog/

Model Tuning with VertexAI

·739 words·4 mins· loading · ·
AI Hardware & Infrastructure AI/ML Models Cloud Computing GCP Cloud Google AI Platform Machine Learning AI Model Optimization Cloud AI Services MLOps

Model Tuning with VertexAI

Tuning Large Language Model with VertexAI
#

Why Model Tuning?
#

Tuning is required when you want the model to learn something niche or specific that deviates from general language patterns.

Goal of Tuning
#

Classification
#

prompt: “Classify the following text into one of the following classes: [business, entertainment].”

Summarization
#

prompt: “Summarize: Jessica: That sounds great! See you in Times Square! Alexander: See you at 10!”

response: “#Person1 and #Person2 agree to meet at Times Square at 10:00 AM.”

Extract QA
#

prompt: “Context: There is evidence that there have been significant changes in Amazon rainforest vegetation over the last 21,000 years through the Last Glacial Maximum (LGM) and subsequent deglaciation. Question: What does LGM stand for?”

response: “Last Glacial Maximum”

Prepare your model tuning dataset
#

Recommended configurations#

The following table shows the recommended configurations for tuning a foundation model by task:

TaskNo. of examples in datasetTrain steps
Classification100+100-500
Summarization100-500+200-1000
Extractive QA100+100-500

For train steps, you can try more than one value to get the best performance on a particular dataset, for example, 100, 200, 500.

Dataset format
#

You can create your own dataset for training. Your dataset must be in JSON Lines (JSONL) format where each line contains a single training example. Content of JSONL file will be like below.

{“input_text”: “question: How many copies of Gears of War 3 were sold ? context: Like its predecessors , the game received widespread critical acclaim from critics . Critics praised its story , voice acting , graphics and visuals , and music , but criticized its lack of innovation . Gears of War 3 sold over 3 million copies and was the second best selling game in the U . S . “, “output_text”: “over 3 million copies”} {“input_text”: “question: How many parishes are there in Louisiana ? context: The U . S . state of Louisiana is divided into 64 parishes ( French : paroisses ) in the same manner that 48 other states of the United States are divided into counties , and Alaska is divided into boroughs . “, “output_text”: “64”}

Creating Dataset
#

Prepare model tuning dataset (train dataset) Maintain consistency with test and production data (same format).

For example, if the examples in your dataset includes a “question:” and a “context:”, production traffic should also be formatted to include a “question:” and a “context:” in the same order as it appears in the dataset examples. If you exclude the context, the model will be confused as to what you are asking, even if the exact question was in an example in the dataset.

Include instructions in examples.
Classify the following text into one of the following classes: [business, entertainment] Text: 5 stocks to buy now

Upload tuning dataset to Cloud Storage (Optional)
#

For the demo use following example. Otherwise bring your dataset in the format below. cloud-samples-data/ai-platform/generative_ai/headline_classification.jsonl

Tuning with VertexAI
#

  • VertexAI -> Language -> Create Tune Model
  • Select the tuning dataset (either from google cloud storage or cloud-samples-data/ai-platform/generative_ai/headline_classification.jsonl)
    • The above dataset contains 25 categorical question answering examples. If you use the sample dataset, the training will take 1-2 hours.
  • Configure the model details & Tune
    • Model name: Enter a name for your tuned model.
    • Base model: Select the foundation model that you want to tune.
    • Train steps: Enter the number of steps to run for model tuning. 1000 steps will take 2-3 hours to complete tuning.
    • Learning rate: Control the step size at which a model updates its weights during training. Default: 3.
    • Working directory: Enter the URI of the bucket to store the tuned model. If don’t have one, you can create a new bucket.

After tuning
#

  • To check the status of your model tuning job, go to the Pipelines page. The status of your pipeline can be found in the Runs section.
  • To view your tuned models in the Google Cloud console, go to the Vertex AI Model Registry page.

Use the tuned model
#

  • To use your tuned models with new prompts, go to the Language page.
  • Click Text prompt.
  • In the Model drop down, select the tuned model that you have created.
  • Copy the sample prompt and submit to view the results.
Multi-choice problem: What is the topic of this text?
- business
- entertainment
- health
- sports
- technology
- politics
Text: What is a large language model (LLM)?
The answer is:

Related

Quantum Measurement, Randomness, and Everyday Technology
·778 words·4 mins· loading
Interdisciplinary Topics Research & Academia Quantum Physics Quantum Mechanics Quantum Computing Interdisciplinary Topics
Quantum Measurement, Randomness, and Everyday Technology # This is Part 2 of Learning Quantum …
AI Agents as First-Class Citizens: Why Managing the Digital Workforce Is the Next HR Challenge
·2607 words·13 mins· loading
Artificial Intelligence Business & Career Technology Trends & Future AI Integration Future of Work AI Governance Organizational Design Generative AI
AI Agents as First-Class Citizens # Why Managing the Digital Workforce Is the Next HR Challenge …
When Consciousness Becomes Cosmos: Fields, Particles, Matter, and the Emergence of Size
·5741 words·27 mins· loading
Philosophy & Cognitive Science Interdisciplinary Topics Quantum Field Theory Consciousness Physics Advaita Vedanta Philosophy of Mind Emergence Metaphysics
When Consciousness Becomes Cosmos # From Consciousness to Cosmos: Fields, Particles, Matter, and …
Occam's Razor: Why the Simplest Explanation Often Wins
·994 words·5 mins· loading
Philosophy & Cognitive Science Interdisciplinary Topics Data Science Occam's Razor Critical Thinking Scientific Method Simplicity Decision Making Machine Learning Software Development
Occam’s Razor: Why the Simplest Explanation Often Wins # Prefer fewer assumptions until the …
From Claw Code to Clean Room: A Developer's Guide to Re-implementing Software Without Getting Sued
·2854 words·14 mins· loading
AI Ethics & Governance Software Development Technology Trends & Future Clean Room Design Intellectual Property AI Code Generation Software Copyright Trade Secrets Software Development
From Claw Code to Clean Room: A Developer’s Guide to Re-implementing Software Without Getting …