×

Let’s see how to classify the customer queries into user-defined categories and sub-categories using Azure OpenAI.

Text classification is a fundamental NLP task that involves assigning predefined categories to textual input. In the provided code, a customer support system utilizes text classification to categorize customer queries related to their orders. The system employs user-defined primary and secondary categories, each with specific sub-categories.

The system message serves as a guide for the classification task, outlining the primary categories (Order Status, Product Inquiries, Shipping and Delivery, and Payment Assistance) and their corresponding secondary categories. The primary and secondary categories are structured to capture various aspects of customer queries, such as tracking information, product availability, and payment confirmation.

For example, when a user submits a query to cancel an order, the code uses the OpenAI ChatCompletion API to generate a response. The output includes a JSON-formatted response indicating the primary and secondary categories assigned to the user’s query. In this case, the primary category is Order Status, and the secondary category is Order Modification or Cancellation.

This example demonstrates how text classification can be applied in a customer support context, allowing for the efficient handling and categorization of customer queries based on predefined categories. The system provides a structured approach to address diverse aspects of order-related inquiries, enhancing the overall customer support experience:
system_message = f”””
Welcome to Customer Order Support!
You will receive customer queries related to their orders, each delimited by {delimiter} characters.
Your task is to classify each query into a primary and secondary category.
Provide your response in JSON format with the keys: “primary” and “secondary.”
Primary Categories:
1.
Order Status
2.
Product Inquiries
3.
Shipping and Delivery
4.
Payment Assistance
Order Status Secondary Categories:
– Tracking Information
– Order Confirmation
– Order Modification or Cancellation
– Refund Status
Product Inquiries Secondary Categories:
– Product Availability
– Size and Color Options
– Product Specifications
– Return and Exchange Policies
Shipping and Delivery Secondary Categories:
– Delivery Timeframe
– Shipping Methods
– Address Changes
– Lost or Delayed Shipments
Payment Assistance Secondary Categories:
– Payment Confirmation
– Refund Process
– Payment Errors
– Billing Inquiries
Please review each query and provide the appropriate primary and secondary category in your response.
Thank you for assisting our customers with their orders!
“””
user_message=f”””\
 I want to cancel my order “””
response = openai.ChatCompletion.create(
    engine=deployment_name, # engine = “deployment_name”.
    messages=[
        {“role”: “system”, “content”: system_message},
        {“role”: “user”, “content”: f”{delimiter}{user_message}
        {delimiter}”},],
    temperature=0,
    max_tokens=60,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0,
    stop=None
)
print(response)
print(response[‘choices’][0][‘message’][‘content’])

Here’s the output:
{ “id”: “chatcmpl-8eEc86GxAO4BePuRepvve9XhTQZfa”, “object”: “chat.completion”, “created”: 1704599988, “model”: “gpt-35-turbo”, “choices”: [ { “finish_reason”: “stop”, “index”: 0, “message”: { “role”: “assistant”, “content”: “{\n \”primary\”: \”Order Status\”,\n \”secondary\”: \”Order Modification or Cancellation\”\n}” } } ], “usage”: { “prompt_tokens”: 232, “completion_tokens”: 21, “total_tokens”: 253 } } { “primary”: “Order Status”, “secondary”: “Order Modification or Cancellation” }

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Example of video data labeling using k-means clustering with a color histogram – Exploring Video Data

Let us see example code for performing k-means clustering on video data using the open source scikit-learn Python package and the Kinetics...

Read out all

Frame visualization – Exploring Video Data

We create a line plot to visualize the frame intensities over the frame indices. This helps us understand the variations in intensity...

Read out all

Appearance and shape descriptors – Exploring Video Data

Extract features based on object appearance and shape characteristics. Examples include Hu Moments, Zernike Moments, and Haralick texture features. Appearance and shape...

Read out all

Optical flow features – Exploring Video Data

We will extract features based on the optical flow between consecutive frames. Optical flow captures the movement of objects in video. Libraries...

Read out all

Extracting features from video frames – Exploring Video Data

Another useful technique for the EDA of video data is to extract features from each frame and analyze them. Features are measurements...

Read out all

Loading video data using cv2 – Exploring Video Data

Exploratory Data Analysis (EDA) is an important step in any data analysis process. It helps you understand your data, identify patterns and...

Read out all