Skip to content

generate_categories

generate_categories(items)

Description

Return categories of items.

Using GenAi, this function generates a hierarchy of categories and subcategories that best represents the given items. (items: must be a json array of strings or or objects).

Result is a json with the following schema:

{
  categories: [
    {
      name: string,
      subcategories: [
        string
      ]
    }
  ]
}

Usage

Call or Deploy generate_categories ?
Call generate_categories directly

The easiest way to use bigfunctions

  • generate_categories function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy generate_categories in your project

Why deploy?

  • You may prefer to deploy generate_categories in your own project to build and manage your own catalog of functions.
  • This is particularly useful if you want to create private functions (for example calling your internal APIs).
  • Get started by reading the framework page

Deployment

generate_categories function can be deployed with:

pip install bigfunctions
bigfun get generate_categories
bigfun deploy generate_categories

Examples

Categorize User Reviews of Nickel App in App Store

select bigfunctions.eu.generate_categories(
      (
        select to_json(array_agg(content))
        from bigfunctions.eu.get_appstore_reviews(
          'https://apps.apple.com/fr/app/nickel-compte-pour-tous/id1119225763'
        )
      )
      )
select bigfunctions.us.generate_categories(
      (
        select to_json(array_agg(content))
        from bigfunctions.us.get_appstore_reviews(
          'https://apps.apple.com/fr/app/nickel-compte-pour-tous/id1119225763'
        )
      )
      )
select bigfunctions.europe_west1.generate_categories(
      (
        select to_json(array_agg(content))
        from bigfunctions.europe_west1.get_appstore_reviews(
          'https://apps.apple.com/fr/app/nickel-compte-pour-tous/id1119225763'
        )
      )
      )
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| categories                                                                                                                                                       |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {
  "categories": [
    {
      "name": "Account Management",
      "subcategories": [
            "Login Issues",
            ...
      ]
    },
    ...
  ]
}
 |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Use cases

The generate_categories function is useful for automatically categorizing text data, particularly when you have a large collection of items and want to understand the main themes or topics discussed. Here are a few specific use cases:

  • Customer Feedback Analysis: Analyze customer reviews, support tickets, or survey responses to identify common issues, compliments, or feature requests. The function can group similar feedback into categories, making it easier to understand customer sentiment and prioritize areas for improvement. The provided example shows how to categorize app store reviews, highlighting topics like "Account Management," which might include subcategories like "Login Issues."

  • Product Categorization: Automatically categorize products in an e-commerce setting based on their descriptions. This can improve search functionality, recommend related products, or organize product catalogs. For example, if the input items are product descriptions like "vintage leather jacket," "stylish bomber jacket," and "warm winter coat," the function might generate categories like "Outerwear" with subcategories "Jackets" and "Coats."

  • Topic Modeling for Research: Analyze a collection of research papers, articles, or social media posts to identify the main topics discussed. This can be helpful for literature reviews, trend analysis, or identifying areas for further research.

  • Content Tagging: Automatically tag articles, blog posts, or other content with relevant keywords or categories, making it easier for users to discover content that interests them.

  • Support Ticket Routing: Categorize incoming support tickets based on their descriptions to automatically route them to the appropriate support team.

In essence, any scenario where you need to group a large number of text items into meaningful categories could benefit from the generate_categories function. The use of GenAI allows the function to infer categories and subcategories even without predefined categories, making it flexible and adaptable to various data types.


Need help or Found a bug?
Get help using generate_categories

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about generate_categories

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

We also provide professional suppport.


Show your ❤ by adding a ⭐ on