Zero Labs
Industry News / AI

VertexAI and AutoML: Text Classification, Entity Extraction, and Sentiment Analysis

Source · Towards AI By Velagapriyanka

From the publisher’s feed, collected in the ZeroLabs newsroom.

VertexAI and AutoMLTABLE OF CONTENTS1. Introduction to VertexAI2. Introduction to AutoML and Key Features3. AutoML Supported Data Types and Models4. Introduction to Text Data5. Introduction to Classification Model6. Text data for the Classification Model7. Introduction to Entity Extraction / Entity Recognition Model8. Text Data for the Entity Extraction Model9. Introduction to Sentiment Analysis Model and its Objective10. Creating a Dataset and Cloud Storage Bucket11. Traning the Model12. Deploying and Testing the Model13. Online Predictions on Google Cloud Console14. Online and Batch Predictions on Colab Notebook15. Clean UpWhat is VertexAI?When we go into the Google Cloud Console menu, we see VertexAI, which is Google Cloud’s unified machine learning platform.…Why is it used? It is used to build, deploy, and scale ML models faster.Data Scientists use this to build and train models. They use TensorFlow, PyTorch, and scikit-learn frameworks.ML Engineers use this to deploy and manage models in production, and to monitor the model performance.What is AutoML?AutoML (Automated Machine Learning) is the service within VertexAI. AutoML builds, trains, and deploys high-quality models with no-code or low-code.…Why is it used?The Marketing team use this to build a model for sentiment analysis on social media posts (AutoML Natural Language API).The Fraud Detection team uses the AutoML Tables API to build a model to identify fraudulent transactions.Small businesses use this to classify products in images (AutoML Vision API)…What operations does AutoML perform?Feature Engineering: Automatically extracts and creates high-quality features from raw data, improving predictive accuracy.Model Selection: Automatically selects the best ML model for a given task. It evaluates everything from simple linear regressions to complex deep learning neural networks.Hyperparameter Tuning: Automatically tunes the hyperparameters of ML models to find optimal values, removing the need for manual configuration.Low-Code / No-Code Interface: Provides an intuitive UI that lets users deploy AI solutions much faster, without writing code.AutoML Supported Data Types and their respective ModelsAutoML supports Text, Image, Video, and Tabular data — each with its own set of compatible model types.Now…let’s talk about the text data first and how it works with its supported modelsWhat is Text Data?Text data is unstructured information consisting of words, sentences, and characters — the natural language found in emails, social media, and reports. Unlike numbers in a spreadsheet, text data requires NLP (Natural Language Processing) techniques to convert its meaning into a format computers can process and analyze.Key Characteristics:Unstructured: It lacks a rigid, predefined format.Context-Heavy: It carries nuance, sentiment, and intent.High Volume: It represents a significant portion of all data generated across digital platforms.What is a Classification Model?This model uses machine learning to automatically assign predefined labels to text, transforming unstructured data into organized categories.Core Capabilities:— Topic Labeling: Categorizes news or social media posts by subject. — Spam Detection: Filters unwanted emails or messages. — Language Identification: Automatically detects the source language. — Medical Analysis: Labels clinical text to support research and diagnosis.Strategic Applications:— Efficiency: Automates manual sorting, saving thousands of human hours. — Routing: Directs customer inquiries to the right department automatically. — Compliance: Flags sensitive or restricted content in internal communications. — Scalability: Processes millions of data points simultaneously with consistent accuracy.It allows systems to “read” and “sort” information at scale by recognizing patterns within the text.Text Data for the Classification ModelLearn to build and deploy an automated model for categorizing text data.Model Workflow StepsThis workflow transforms raw text into a live categorization engine capable of processing single requests or massive datasets automatically.What is Entity Extraction?Entity extraction, also known as Named Entity Recognition (NER), is an NLP technique that locates and categorizes specific pieces of information in unstructured text — such as names, dates, locations, and product codes — by breaking text into tokens and labeling each one.Core Capabilities:— Identification: Pinpoints specific “entities” within a block of text. — Categorization: Assigns entities to labels such as Person, Organization, or Product. — Automation: Converts unstructured sentences into structured, searchable data.Strategic Applications:Entity Extraction transforms unstructured text into actionable data across various sectors: — Social Media: Identifies brand mentions and viral topics to track trends. — CRM (Customer Relationship Management) & Support: Extracts customer names and account IDs from tickets to automate data entry. — Content Management: Tags articles automatically for better search and recommendations. — E-commerce: Monitors competitors by automatically capturing product names and pricing. — Healthcare: Processes patient records to extract symptoms and diagnoses for clinical research.Text Data for the Entity Extraction ModelLearn to build and deploy an automated model for extracting text entities.Model Workflow StepsThis workflow takes raw, unstructured text and produces a deployed model that automatically identifies and categorizes named entities within it.What is Sentiment Analysis?Sentiment Analysis is an NLP process that identifies the emotional tone of a text, categorizing it as positive, negative, or neutral.Core Capabilities:— Detection: Labels text as Positive, Negative, or Neutral. — Intensity: Measures emotional strength (e.g., “Good” vs. “Excellent”). — Aspect-Based: Identifies sentiment on specific features (e.g., “Great screen, bad battery”). — Global Reach: Understands multiple languages and local slang.Strategic Applications:— Brand Health: Tracks public perception across social media and news. — Customer Support: Auto-prioritizes negative tickets to resolve issues faster. — Market Insights: Analyzes reviews to identify product pain points. — Internal Morale: Monitors employee satisfaction through anonymous surveys.Training an AutoML Sentiment Analysis for Text DataThe objective is to automatically detect, quantify, and classify the emotional tone within natural language at scale.ModelWorkflow Steps:It allows you to “read the room” at scale — turning thousands of customer comments into a clear emotional score.Steps to Create a Dataset and Cloud Storage BucketTo create a dataset we need to enable billing and create a project.STEPS TO CREATE A PROJECT1. Go to Console2. Click the Project Dropdown (top left, next to the Google Cloud logo).3. Click New Project.4. Enter a Project Name and click Create.STEPS TO ENABLE BILLING1. Open the Navigation Menu (≡) and select Billing.2. If you don’t have an account, click Add Billing Account and follow the prompts to add a payment method.3. Once an account exists, go to Billing > My Projects.4. Find your project, click the three dots (⋮) under Actions, and select Change Billing.5. Select your billing account and click Set Account.In the Google Cloud Console at the navigation bar, go to Vertex AI > Datasets and click Create a datasetSTEPS TO CREATE A DATASETCreate a dataset1. Give it a name and select the model you want to run (Text Classification or Text Entity Extraction or Text Sentiment Analysis).2. Select the Google-managed encryption or Customer-managed encryption for your dataset.3. Once you create the dataset — which starts as an empty one — you need to connect it with a text data file.There are two ways to import the data:Create the Cloud Storage Bucket, upload the data to that bucket, and provide the bucket path during dataset creation.Import the data from your computer and then select an existing Cloud Storage Bucket or create a new one. — Text Documents (unlabeled data) — such as essays, for Entity Extraction and Sentiment Analysis. — Import files (labeled data) — such as tables, for Text ClassificationUpload the .csv or .txt file by clicking on the ‘SELECT FILES’ button. Once you upload the CSV file, it asks for the Cloud Storage path where you want to store that file.I am providing the Cloud Storage Bucket settings as per this project just to run the modelCREATE THE CLOUD STORAGE BUCKET 1. Name your bucket 2. Choose the location type as Region (us-central-1)3. Choose a storage class for your data (Default Standard)4. Protect Object data: None5. Create the Cloud Storage BucketNow select this Bucket in the Cloud Storage Path and click Continue. This imports the CSV file from your computer into your bucket.Steps to Train the ModelGo to Vertex AI > training 1. Select Create 2. Select the dataset you created 3. Select the model training method: AutoML4. Continue with the Model Details5. Select Train new Model6. Name the Model7. Select the Data split: RandomDATA SPLIT This distribute the dataset between training, validation, and test sets.Training set: Used by the model to learn patterns.Validation set: Used to tune the hyperparameters (model settings) during training process.Test Set: Used once at the very end to evaluate how the model performs on unseen data.Without Data Split, a model might fail in the real world due to overfitting (memorizing instead of learning). Spliting helps measure the model’s true quality.8. Create the Model ID (If you don’t create a model ID, the system will generate one for you). Model ID for Online and Batch Predictions9. Click Start training (Training usually takes 2–3 hrs)You can see your trained model in the Model Registry of Vertex AI.Deploy and Test the ModelFor Online Predictions, you need to create an Endpoint. For Batch Predictions, there is no need for an Endpoint.STEPS TO CREATE AN ENDPOINT FOR ONLINE PREDICTION1. In the navigaton menu, go to Deploy and Use2. Click Deploy and Test 3. Select the model you created4. Click Deploy to Endpoint5. Click Create new Endpoint6. Define your Endpoint with a name, region, and access. Give any name, and set the location to us-central-1 — where you created your model.7. Continue to Model settings8. Done and Deploy (This creates the Endpoint and deploys the model to it)Steps to Test the Model for Online Prediction on GCP ConsoleYou give the text to the model to figure out:Text Classification: which category does it belongs to.Entity Extraction: what entities within the text.Sentiment Analysis: which emotion does it carry.1. Go to Model Registry2. Click on the model you want to test3. Go to Deploy and Test4. In the Test model box, enter your text and click ‘PREDICT’Steps to Test the Model for Online and Batch Predictions on Colab NotebookGo to Colab Notebook 1. Install Google Cloud AI platform, Google Cloud Storage, and JSONLINES using following code:pip3 install --upgrade --quiet google-cloud-aiplatform \ google-cloud-storage \ jsonlinesAfter installing these packages, restart the kernel automatically so that your environment can access the new packages:import IPython app = IPython.Application.instance()app.kernel.do_shutdown(True)2. Create a PROJECT_ID environment variable. Get your Project ID from the GCP Console and set the Google Cloud Configuration. The Region variable holds the GCP region in which the model is created.PROJECT_ID = "your_project_id" !gcloud config set project $PROJECT_IDREGION = "us-central-1"3. To authenticate Colab with GCP project, import the auth package from Google Colab. This allows the notebook to access your GCPfrom google.colab import authauth.authenticate_user()4. Now create the BucketBUCKET_NAME = "your_bucket_name"BUCKET_URI - f"gs://{BUCKET_NAME}" !gsutil mb -l $REGION $BUCKET_URI5. Import the AI Platform and Storage packages used to create and access the model and other GCP resources — icluding jsonlines and jobsimport jsonlinesfrom google.cloud import aiplatform, storagefrom google.cloud.aiplatform import jobs6. Initialize the AI platform packages with PROJECT_IDaiplatform.init(project=PROJECT_ID, location=REGION)7. Create a Dataset resource and import your data through code, if you haven’t created the dataset in the cloud8. Access the Dataset resource with dataset_idtext_dataset = aiplatform.TextDataset('your_dataset_id')9. Create a Training job if you haven’t done that in the console10. Run Training job and Create the model11. Access Model with MODEL_IDTO GET THE MODEL_ID — Console > Activate your Cloud shell — Enter the command: >> gcloud ai models listIt gives the list of model regions and select your region where you created you model (us-central-1) — Enter the number of that region (E.g., 26) — Get the MODEL_ID of your modelmodel = aiplatform.Model("your_model_id")12. Deploy your model to an endpoint for online prediction through code, if you haven’t done in the console. — Get an endpoint ID from the console > Online Predictions > Endpoint_ID#deployed_model_display_name = "your_model_name"# endpoint = model.deploy(# deployed_model_display_name=deployed_model_display_name, sync=True# )endpoint = aiplatform.Endpoint('your_endpoint_id')13. Run the following code to get the online prediction:content = "write_your_sentence_here"prediction = endpoint.predict(instances=[{"content": content}])print(prediction)— Run the following code if you want to undeploy the model from that endpointendpoint.undeploy_all()14. Run the following code for the batch predictionSTEPS TO RUN THE BATCH PREDICTIONS — Create an input file on your local computer — In a folder, create text files — I created 2 files for this project — In that text files named as .txt and .txt, enter the text you want to run the model against. — In the same folder, create a JSONL file named .jsonlIn the JSONL file, enter the following:{"content": "gs:///.txt", "mime_type": "text/plain"}{"content": "gs:///.txt", "mime_type": "text/plain"}Give the Bucket name of your model and the files you created to run. — Go to the Console and upload the folder to Cloud Storage in your model bucketgcs_input_uri = BUCKET_URI + "/.jsonl"batch_prediction_job = model.batch_predict( job_display_name="your_job_display_name", gcs_source=gcs_input_uri, gcs_destination_prefix=f"{BUCKET_URI}/", sync=False,)Once you run it, it creates the file in the Batch Predictions folder of your Cloud Storage Bucket and saves the output thereVertex AI > Batch Predictions shows the status of the Batch Prediction job.Cloud Storage > your model bucket > / shows the output of your Batch Predictions. You can also download that JSONL file.Clean UpRun the following code to clean up your project !gsutil rm -r $BUCKET_URI# Delete batchbatch_prediction_job.delete()# 'force' parameter checks if models are undeployed before deletionendpoint.delete()# Delete modelmodel.delete()# Delete datasetdataset.delete()# If you ran the training job in the notebook # Delete job through notebookjob.delete()To delete the training job through Console:Vertex AI > Model Registry > Delete ModelBatch Predictions > Delete JobDatasets > Delete DatasetsCloud Storage > Bucket > Delete BucketWe covered Text data and its models — Classification, Entity Extraction, and Sentiment Analysis. Next, we will look at Image, Video, and Tabular data and how AutoML works with each of them.VertexAI and AutoML: Text Classification, Entity Extraction, and Sentiment Analysis was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.