Zero Shot Classification
SkillfulAPI.
ZeroShotTextClassification
SkillfulAPI.
ZeroShotTextClassification
Overview
The ZeroShotTextClassification
function provides functionality for classifying text into predefined context labels without needing explicit training on those labels. This can be useful for categorizing text into different contexts or topics based on the given labels.
Class Definition
using SkillfulAI.API;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ZeroShotClassification : MonoBehaviour
{
/// <summary>
/// Unity's Start method, called when the script is initialized. Initiates the text classification process.
/// </summary>
void Start()
{
ClassifyText();
}
/// <summary>
/// Performs zero-shot text classification using predefined context labels.
/// </summary>
public void ClassifyText()
{
// Predefined context labels for classification
string[] context = new string[] {
"new customer",
"refund",
"legal"
};
// Perform zero-shot text classification on a sample input text
SkillfulAPI.ZeroShotTextClassification("Hi I need to rent a new car for my holiday.", context, result =>
{
// Log each classification result
foreach (var classification in result.classifications)
{
Debug.Log(classification.Label + " : " + classification.Score);
}
});
}
}
Detailed Explanation
Start Method
Description: Unity's Start
method is called when the script is first initialized. This method triggers the text classification process.
Code:
void Start()
{
ClassifyText();
}
Functionality:
Automatically invokes the
ClassifyText
method when the script starts.Ideal for initiating classification tasks or performing actions as soon as the script is activated.
ClassifyText Method
Description: The ClassifyText
method performs zero-shot text classification using predefined context labels and logs the classification results.
Code:
public void ClassifyText()
{
// Predefined context labels for classification
string[] context = new string[] {
"new customer",
"refund",
"legal"
};
// Perform zero-shot text classification on a sample input text
SkillfulAPI.ZeroShotTextClassification("Hi I need to rent a new car for my holiday.", context, result =>
{
// Log each classification result
foreach (var classification in result.classifications)
{
Debug.Log(classification.Label + " : " + classification.Score);
}
});
}
Functionality:
Uses predefined context labels to classify the input text.
Processes the input text ("Hi I need to rent a new car for my holiday.") to determine which context it fits best.
Logs the classification results, including the label and score for each context.
Usage Example
Add the Script to a GameObject:
Attach the
ZeroShotClassification
script to any GameObject in your Unity scene.
Run the Scene:
Upon starting the scene, the
ClassifyText
method will be invoked automatically.The specified input text will be classified according to the predefined labels, and the results will be logged to the console.
Conclusion
The ZeroShotTextClassification
function provides a straightforward implementation of zero-shot text classification using the SkillfulAI Gaming SDK. By classifying text into predefined context labels, you can efficiently categorize and interpret textual data in your Unity project.
Last updated