Predict
thanosql.predict()
The predict
function in ThanoSQL is designed to perform various prediction tasks using pre-trained models. This function supports a range of tasks, leveraging the capabilities of different engines.
Syntax
Parameters
Parameter | Type | Default | Description | Options |
---|---|---|---|---|
task | string | The prediction task to perform. | 'text-classification' , 'sentiment-analysis' , 'summarization' , 'image-classification' , 'image-segmentation' , 'audio-classification' , 'automatic-speech-recognition' , 'video-classification' | |
engine | string | 'huggingface' | The engine to use for performing predictions. | 'huggingface' : Uses models from HuggingFace. |
input | string | The input data for the prediction task. It can be text, a URL, an S3 URI, or a path to a local file. | N/A | |
model | string | The name or path of the pre-trained model. | Example: 'google-bert/bert-base-uncased' | |
model_args | json | None | JSON string representing additional arguments for the model. | N/A |
pipeline_args | json | None | JSON string representing additional arguments for the pipeline. | N/A |
task_args | json | None | JSON string representing additional arguments specific to the task. | N/A |
token | string | None | Token for authentication if required by the model. | N/A |
base_url | string | None | Base URL to point the client to a different endpoint than the default OpenAI API endpoint. This is only applicable when the engine is openai . | N/A |
Returns
- varies: The prediction result based on the task.
Currently Supported Tasks
- Text Classification
- Sentiment Analysis
- Summarization
- Image Classification
- Image Segmentation
- Audio Classification
- Automatic Speech Recognition
- Video Classification
We are actively adding more tasks to enhance your experience.
Example Usage
When using text-generating models with the huggingface
engine, the default truncation_policy
is ‘strict’. This could result in an error if the token count exceeds the model’s limit. If this happens, reduce the text length or use pipeline_args = "{'truncation_policy': True}"
.
The following examples are provided to help you become familiar with the ThanoSQL syntax. To try out these queries in real scenarios, please visit the Use Cases section for detailed tutorials and practical applications.
To run the models in this tutorial, you will need the following tokens:
- OpenAI Token: Required to access all the OpenAI-related tasks when using OpenAI as an engine. This token enables the use of OpenAI’s language models for various natural language processing tasks.
- Huggingface Token: Required only to access gated models such as Mistral on the Huggingface platform. Gated models are those that have restricted access due to licensing or usage policies, and a token is necessary to authenticate and use these models. For more information, check this Huggingface documentation. Make sure to have these tokens ready before proceeding with the tutorial to ensure a smooth and uninterrupted workflow.
Text Classification
Here is an example of how to use the predict
function for text classification using a Hugging Face model:
On execution, we get:
Sentiment Analysis
Here is an example of how to use the predict
function for sentiment analysis using a Hugging Face model:
On execution, we get:
Summarization
Here is an example of how to use the predict
function for summarization using a Hugging Face model:
On execution, we get:
Image Classification
Here is an example of how to use the predict
function for image classification using a Hugging Face model:
On execution, we get:
Image Segmentation
Here is an example of how to use the predict
function for image segmentation using a Hugging Face model:
On execution, we get:
Audio Classification
Here is an example of how to use the predict
function for audio classification using a Hugging Face model:
On execution, we get:
Automatic Speech Recognition
Here is an example of how to use the predict
function for automatic speech recognition using a Hugging Face model:
On execution, we get:
Here is an example of how to use the predict
function for automatic speech recognition using an OpenAI model:
On execution, we get:
Video Classification
Here is an example of how to use the predict
function for video classification using a Hugging Face model:
On execution, we get:
Model Restrictions
When using the predict
function with the huggingface
engine, ensure that only models compatible with the HuggingFace pipeline are used. Verify that the selected model is supported by the HuggingFace library to avoid compatibility issues. Even with compatible tasks and pipeline models, some models might still not work. We are actively working on improving compatibility and functionality to provide a better user experience. For more information, refer to the official HuggingFace documentation.