Home Artificial Intelligence Quick Introduction to— Model Garden on Vertex AI

Quick Introduction to— Model Garden on Vertex AI

0
Quick Introduction to— Model Garden on Vertex AI

Google Cloud - Community

On this Blog we’d have a look at making a content classification model for a Blog hosting website using Google’s latest offering Model Garden.

Introduction

We’ve got a medium scale Blog Hosting website and wish to categorise the content being published into various buckets making for a superb User experience when looking for relevant content. Also we wish to make use of this Model to give you the option to categorise possibly toxic content which might then require review. We’ve got a small Dev team with limited AI expertise and wish to make use of Google’s Vertex Model Garden to quickly productionize a model.

Google Vertex Model Garden is a group of pre-built machine learning models and tools designed to simplify the means of constructing and deploying machine learning models. Model Garden provides enterprise-ready foundation models, task specific models, and APIs. Kick off a wide range of workflows including using models directly, tuning models in Generative AI Studio, or deploying models to an information science notebook.

Vertex Model Garden features a wide selection of pre-trained models and tools for various use cases, including computer vision, natural language processing, and tabular data evaluation. These models are trained using large datasets and state-of-the-art machine learning techniques, which ensures high accuracy and performance.

These models could be easily customised to suit specific use cases by modifying the training data or adjusting the hyperparameters. At once Vertex Model supports three classes of Model Type:

> First-party models

> Open Source models

> Third Party Models

One among the important thing advantages of Vertex Model Garden is that it allows users to quickly and simply deploy machine learning models in a production environment. That is achieved through integration with other Google Cloud Platform services, equivalent to Google Kubernetes Engine and Cloud Functions, which allows users to deploy their models as web services or serverless functions.

Demo

So without much await allow us to try making a ML model, for our use case I’m thinking about running a Blog Website and wish to give you the option to categorise blogs into various buckets for easier retrieval and search. To give you the option to attain this we are going to use GCP’s prebuilt models on content classification hosted on Model Garden

  1. Navigate to Vertex AI console on GCP

2. From the left hand side Menu select Model Garden and also you could be taken to a page with multiple Models

3. Seek for content classification Models and in addition select Language filter from left hand side

we are able to see a few of the ML Options which are available

Allow us to select the primary one — Content Classification

4. This takes us to Documentation and sample code. Let’s try quickly running this in on a Notebook on Google Vertex Workbench

Before you possibly can run this , pip install the google-cloud-language library

Once installed successfully allow us to try running a sample content classification task, for the instance below I even have taken the code from Google Documentation and written a wrapper around it to pass Wiki page text to the classification Model

Content Classification Code from Google Docs

from google.cloud import language_v1

def sample_classify_text(text_content):
"""
Classifying Content in a String

Args:
text_content The text content to investigate.
"""

client = language_v1.LanguageServiceClient()

# text_content = "That actor on TV makes movies in Hollywood and in addition stars in a wide range of popular latest TV shows."

# Available types: PLAIN_TEXT, HTML
type_ = language_v1.Document.Type.PLAIN_TEXT

# Optional. If not specified, the language is routinely detected.
# For list of supported languages:
# https://cloud.google.com/natural-language/docs/languages
language = "en"
document = {"content": text_content, "type_": type_, "language": language}

content_categories_version = (
language_v1.ClassificationModelOptions.V2Model.ContentCategoriesVersion.V2
)
response = client.classify_text(
request={
"document": document,
"classification_model_options": {
"v2_model": {"content_categories_version": content_categories_version}
},
}
)
# Loop through classified categories returned from the API
for category in response.categories:
# Get the name of the category representing the document.
# See the predefined taxonomy of categories:
# https://cloud.google.com/natural-language/docs/categories
print("Category name: {}".format(category.name))
# Get the boldness. Number representing how certain the classifier
# is that this category represents the provided text.
print("Confidence: {}".format(category.confidence))

For creating sample Blog data we are going to use Wiki. We use BeautifulSoup to scrape text from wiki and pass that as input to our Model

import requests
from bs4 import BeautifulSoup

def get_wiki(url):
# Use the requests library to fetch the page content
response = requests.get(url)

# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(response.content, "html.parser")

# Extract the principal text content of the page
text = ""
for p in soup.find_all("p"):
text += p.get_text()

# Return the extracted text
return text

Allow us to try passing text into our classification model, we are going to use Wiki page for — Artificial Intelligence and Star Wars Movie page as our sample inputs

## Example - 1 
sample_classify_text(get_wiki("https://en.wikipedia.org/wiki/Artificial_intelligence"))

print('#### Example 2 ')

#### Example - 2
sample_classify_text(get_wiki("https://en.wikipedia.org/wiki/Star_Wars"))

Sample output from my notebook. So the model accurately categorized AI wiki page into ML and AI content type. For Star Wars Wiki our model successfully put this as a Science Fiction content.

As you possibly can see this pre-trained model which we’ve got utilized in under less then 5 minutes was capable of accurately categorize the buckets for the wiki page. This model could easily be integrated with an automatic pipeline running in background which classifies all blogs being published,

Conclusion

Model Garden is a beneficial resource for developers and data scientists who wish to leverage the facility of machine learning of their applications, but may not have the resources or expertise to develop custom models from scratch. By providing a curated collection of pre-built models and tools, the Model Garden makes it easier to start with machine learning and speed up the event of intelligent applications.

LEAVE A REPLY

Please enter your comment!
Please enter your name here