Get started with each Skillful Inference capability using these basic implementations.
Question Answering
For getting answers based on specific context:
using SkillfulAI.API;
using UnityEngine;
public class SimpleQuestionAnswering : MonoBehaviour
{
void Start()
{
string context = "The grass is green";
string question = "What colour is grass?";
SkillfulAPI.QuestionAnswering(question, context, response => {
Debug.Log(response.answer);
});
}
}
Sentence Similarity
For comparing an input sentence against a set of possibilities:
using SkillfulAI.API;
using UnityEngine;
public class SimpleSimilarity : MonoBehaviour
{
void Start()
{
string[] context = new string[] {
"Ham and cheese burger",
"Tomato Salad Burger",
"Steak and Cheese Burger"
};
string inputSentence = "I really want a yummy steak burger please!";
SkillfulAPI.SentenceSimilarity(inputSentence, context,
(scores, maxScoreIndex, contexts) => {
string bestMatch = contexts[maxScoreIndex];
Debug.Log($"Best match: {bestMatch}");
},
error => Debug.LogError(error)
);
}
}
Speech Recognition
For converting spoken words to text:
using SkillfulAI.API;
using UnityEngine;
public class SimpleSpeechRecognition : MonoBehaviour
{
void Update()
{
// Hold Space to record, release to process
if (Input.GetKeyDown(KeyCode.Space))
{
AudioRecorder.StartRecording();
}
if (Input.GetKeyUp(KeyCode.Space))
{
var audioData = AudioRecorder.StopRecordingAndGetBytes();
ProcessSpeech(audioData);
}
}
void ProcessSpeech(byte[] audioData)
{
SkillfulAPI.SpeechRecognition(audioData, text => {
Debug.Log($"Recognized speech: {text}");
});
}
}
Text Classification
For analyzing sentiment in text:
using SkillfulAI.API;
using UnityEngine;
public class SimpleClassification : MonoBehaviour
{
void Start()
{
string inputText = "You did amazing in the race. However you were in last place.";
SkillfulAPI.TextClassification(inputText, response => {
Debug.Log($"Positive Score: {response.PositiveScore}");
Debug.Log($"Negative Score: {response.NegativeScore}");
});
}
}
Text Generation
For creating new text based on a prompt:
using SkillfulAI.API;
using UnityEngine;
public class SimpleTextGeneration : MonoBehaviour
{
void Start()
{
string prompt = "A murder mystery";
SkillfulAPI.TextGeneration(prompt, result => {
Debug.Log($"Generated story: {result}");
});
}
}
Text Summarization
For condensing longer text into summaries:
using SkillfulAI.API;
using UnityEngine;
public class SimpleSummarization : MonoBehaviour
{
void Start()
{
string inputText = "The cab arrived late. The inside was in as bad of shape as the outside which was concerning, and it didn't appear that it had been cleaned in months. The green tree air-freshener hanging from the rearview mirror was either exhausted of its scent or not strong enough to overcome the other odors emitting from the cab.";
SkillfulAPI.Summarization(inputText, result => {
Debug.Log($"Summary: {result}");
});
}
}
Text-To-Image
For generating images from text descriptions:
using SkillfulAI.API;
using UnityEngine;
using UnityEngine.UI;
public class SimpleTextToImage : MonoBehaviour
{
public Image displayImage;
void Start()
{
string inputText = "A blue fish";
SkillfulAPI.TextToImage(inputText, generatedImage => {
displayImage.sprite = Utilities.Texture2DToSprite(generatedImage);
});
}
}
Translation
For translating text between languages:
using SkillfulAI.API;
using UnityEngine;
public class SimpleTranslation : MonoBehaviour
{
void Start()
{
string inputText = "Now I can seamlessly translate game content!";
SkillfulAPI.Translate(inputText, LanguagePairs.LanguagePair.EnglishToFrench,
result => {
Debug.Log($"Translated text: {result}");
});
}
}
Zero-Shot Classification
For classifying text without pre-training:
using SkillfulAI.API;
using UnityEngine;
public class SimpleZeroShot : MonoBehaviour
{
void Start()
{
string[] categories = new string[] {
"new customer",
"refund",
"legal"
};
SkillfulAPI.ZeroShotTextClassification(
"Hi I need to rent a new car for my holiday.",
categories,
result => {
foreach (var classification in result.classifications)
{
Debug.Log($"{classification.Label}: {classification.Score}");
}
});
}
}
Each of these examples can be expanded based on your specific needs. Remember to:
Handle errors appropriately in production code
Consider performance implications for real-time usage
Cache results when appropriate
Implement proper cleanup and resource management
For more advanced implementations and best practices, check out the Service Reference documentation.