Categories:

String & binary functions (Large Language Model)

CLASSIFY_TEXT (SNOWFLAKE.CORTEX)¶

Classifies free-form text data into categories you provide.

Syntax¶

SNOWFLAKE.CORTEX.CLASSIFY_TEXT( <input> , <list_of_categories> )
Copy

Arguments¶

Required:

input

String to classify. The input string is case sensitive. You may get different results for the same string that uses different capitalization.

list_of_categories

Array of strings that represent the categories. Must contain at least two and at most 100 unique categories. Categories are case sensitive. If these requirements are not met, the function returns an error message. For a full list of errors, see Error conditions.

Returns¶

Returns a string that contains a JSON object. The JSON object contains the category that the input prompt was classified as. If invalid arguments are given, an error is returned. For details on the errors, see Error conditions.

Access control requirements¶

Users must use a role that has been granted the SNOWFLAKE.CORTEX_USER database role. See Required privileges for more information on this privilege.

Usage notes¶

For optimal performance, follow these guidelines:

  • Use plain-English text for input and categories.

  • Limit the amount of text that is not plain-English in the input text. For example, try to limit content such as code snippets or logs in the text input.

  • Text shouldn’t contain code or formats that are not open source (company specific languages, proprietary formats, etc.). The function won’t return an error but the results may not be what you expect.

  • Don’t use abbreviations, special characters, or jargon in the category labels.

  • Categories should be descriptive. For example using a category such as Xa4s3 or category 1 won’t produce good results.

  • Categories should be mutually exclusive.

Examples¶

The following example classifies the prompt into one of two categories, travel or cooking:

SELECT SNOWFLAKE.CORTEX.CLASSIFY_TEXT('One day I will see the world', ['travel', 'cooking']);
Copy
{
  "label": "travel"
}

The following example creates a table, text_classification_table, that contains a column for text and a column for possible categories for that text. Then the CLASSIFY_TEXT function is called on each row of the table to classify the string in the text column.

CREATE OR REPLACE TEMPORARY TABLE text_classification_table AS
SELECT 'France' AS input, ['North America', 'Europe', 'Asia'] AS classes
UNION ALL
SELECT 'Singapore', ['North America', 'Europe', 'Asia']
UNION ALL
SELECT 'one day I will see the world', ['travel', 'cooking', 'dancing']
UNION ALL
SELECT 'my lobster bisque is second to none', ['travel', 'cooking', 'dancing'];

SELECT input,
       classes,
       SNOWFLAKE.CORTEX.CLASSIFY_TEXT(input, classes)['label'] as classification
FROM text_classification_table;
Copy