bigfunctions > classify_text
classify_text¶
Call or Deploy classify_text
?
✅ You can call this classify_text
bigfunction directly from your Google Cloud Project (no install required).
- This
classify_text
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want 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). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
classify_text(text, candidate_labels)
Description
Classify text
among candidate_labels
using zero-shot classification
candidate_labels
is a string of comma separated classes used for classification- Output is probability
scores
for each label.
Examples¶
select bigfunctions.eu.classify_text('one day I will see the world', "travel, cooking, dancing, exploration")
select bigfunctions.us.classify_text('one day I will see the world', "travel, cooking, dancing, exploration")
select bigfunctions.europe_west1.classify_text('one day I will see the world', "travel, cooking, dancing, exploration")
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| scores |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [
{'label': 'travel', 'score': 0.995},
{'label': 'exploration', 'score': 0.938},
{'label': 'dancing', 'score': 0.005},
{'label': 'cooking', 'score': 0.002}
]
|
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Need help using classify_text
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using classify_text
?
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.
For professional suppport, don't hesitate to chat with us.
Use cases¶
Let's say you have a BigQuery table containing customer reviews for a travel agency. The review text is stored in a column called review_text
. You want to categorize these reviews into different topics to understand what aspects of your service customers are commenting on most frequently. You're interested in categories like "booking process," "customer service," "hotel quality," "tour experience," and "pricing."
Here's how you'd use the classify_text
function:
SELECT
review_text,
bigfunctions.us.classify_text(review_text, "booking process, customer service, hotel quality, tour experience, pricing") AS classification_scores
FROM
`your_project.your_dataset.customer_reviews`;
This query will process each review in your table. The classify_text
function will analyze the review_text
and return an array of structs, each containing a label (one of your specified categories) and a score representing the probability that the review belongs to that category. The bigfunctions.us
part should be changed to match your BigQuery region.
Example Output:
Let's say a review_text
is: "The hotel was amazing, but the booking process was a nightmare. It took hours on the phone."
The classification_scores
output might look like this:
[
{ "label": "booking process", "score": 0.95 },
{ "label": "customer service", "score": 0.10 },
{ "label": "hotel quality", "score": 0.80 },
{ "label": "tour experience", "score": 0.02 },
{ "label": "pricing", "score": 0.01 }
]
This shows a high probability that the review relates to "booking process" and "hotel quality," reflecting the content of the review.
Further Analysis:
You can then use these scores in further analysis. For example, you could:
- Filter reviews: Find all reviews highly related to "customer service" by filtering where the "customer service" score is above a certain threshold.
- Aggregate insights: Calculate the average score for each category across all reviews to understand which topics are most prevalent in customer feedback.
- Visualize trends: Create charts showing the distribution of scores for each category over time.
This allows you to gain valuable insights from your customer reviews and identify areas for improvement in your travel agency's services.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!