Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notebooks/getting-started-with-ai-functions/meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ description="""\
icon="browser"
difficulty="beginner"
tags=["advanced", "notebooks", "python"]
lesson_areas=[]
lesson_areas=["AI"]
destinations=["spaces"]
minimum_tier="standard"
98 changes: 49 additions & 49 deletions notebooks/getting-started-with-ai-functions/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{
"attachments": {},
"cell_type": "markdown",
"id": "5831c1ac",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
Expand All @@ -38,23 +39,23 @@
"3. Demonstrate powerful AI Functions for text processing and analysis\n",
"\n",
"**Prerequisites**: Ensure AI Functions are enabled on your deployment (AI Services > AI & ML Functions)."
],
"id": "5831c1ac"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ea429156",
"metadata": {},
"source": [
"## Create some simple tables\n",
"\n",
"This setup establishes a basic relational structure to store some reviews for restaurants. Ensure you have selected a database and have CREATE permissions to create/delete tables."
],
"id": "ea429156"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1f8ccd75",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -97,21 +98,21 @@
" Summary TEXT,\n",
" Text TEXT\n",
");"
],
"id": "1f8ccd75"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "6a2118dd",
"metadata": {},
"source": [
"## Install the required packages"
],
"id": "6a2118dd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "40350277",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -143,21 +144,21 @@
],
"source": [
"!pip install kagglehub pandas"
],
"id": "40350277"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "97437a79",
"metadata": {},
"source": [
"## Download and Load Dataset"
],
"id": "97437a79"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "cf62cc7e",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -349,21 +350,21 @@
"print(f\"Columns: {list(df.columns)}\")\n",
"print(\"\\nFirst few rows:\")\n",
"df.head()"
],
"id": "cf62cc7e"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "0c938c99",
"metadata": {},
"source": [
"## Load Data into SingleStore"
],
"id": "0c938c99"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4d427d08",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -396,21 +397,21 @@
")\n",
"\n",
"print(\"Data loaded successfully!\")"
],
"id": "4d427d08"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "ee21f51b",
"metadata": {},
"source": [
" ## Verify Data Load"
],
"id": "ee21f51b"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8423c269",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -458,21 +459,21 @@
"%%sql\n",
"-- Check the number of reviews loaded\n",
"SELECT COUNT(*) as total_reviews FROM reviews;"
],
"id": "8423c269"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "d6c8e487",
"metadata": {},
"source": [
"## Sample Data Preview"
],
"id": "d6c8e487"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "ccefec53",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -602,24 +603,24 @@
"SELECT Id, ProductId, Score, Summary, LEFT(Text, 100) as Review_Preview\n",
"FROM reviews\n",
"LIMIT 10;"
],
"id": "ccefec53"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "0bb3deb8",
"metadata": {},
"source": [
"## AI Functions Demonstrations\n",
"\n",
"Now let's explore the power of SingleStore AI Functions for text analysis and processing.\n",
"Ensure that AI functions are enabled for the org and you are able to list the available AI functions"
],
"id": "0bb3deb8"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "bd293861",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -769,12 +770,12 @@
"%%sql\n",
"USE cluster;\n",
"SHOW functions;"
],
"id": "bd293861"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "05d5d27a",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -824,12 +825,12 @@
"SELECT cluster.AI_COMPLETE(\n",
" 'What is SingleStore?'\n",
") AS completion;"
],
"id": "05d5d27a"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "9f842a0d",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -888,7 +889,7 @@
"%%sql\n",
"-- AI_SENTIMENT: Analyze sentiment of customer reviews for a specific product\n",
"-- WHERE ProductId = <Your choice>\n",
"-- Remember to specific the datbase name. In this example 'temp' is the Database name\n",
"-- Remember to specify the datbase name. In this example 'temp' is the Database name\n",
"SELECT\n",
" Id,\n",
" ProductId,\n",
Expand All @@ -898,12 +899,12 @@
"FROM temp.reviews\n",
"WHERE ProductId = 'B000NY8ODS'\n",
"LIMIT 10;"
],
"id": "9f842a0d"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "56ff7a17",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1015,12 +1016,12 @@
" review_count,\n",
" cluster.AI_SENTIMENT(combined_text) as overall_sentiment\n",
"FROM grouped_reviews;"
],
"id": "56ff7a17"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "b9786b66",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1122,12 +1123,12 @@
" 15\n",
" ) AS summary\n",
"FROM long_reviews;"
],
"id": "b9786b66"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "4febc8e0",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1263,12 +1264,12 @@
" '[quality, price, shipping, taste]'\n",
" ) AS classification\n",
"FROM negative_reviews;"
],
"id": "4febc8e0"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "40f4cd14",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1431,12 +1432,12 @@
" 'Does this customer indicate they will buy this product again? Answer with yes, no, or unclear only'\n",
" ) AS repeat_purchase_intent\n",
"FROM positive_reviews;"
],
"id": "40f4cd14"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "a09f2d5b",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1585,12 +1586,12 @@
" 'Is this customer at high risk of not purchasing again? Answer with high, medium, or low only'\n",
" ) AS churn_risk\n",
"FROM low_rated_reviews;"
],
"id": "a09f2d5b"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "3d78f449",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1685,12 +1686,12 @@
" 'spanish'\n",
" ) AS spanish_translation\n",
"FROM translatable_reviews;"
],
"id": "3d78f449"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "082dc59a",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1860,8 +1861,7 @@
" cluster.AI_CLASSIFY(Text, '[quality, value, taste, packaging]') as category,\n",
" cluster.AI_SUMMARIZE(Text, 'aifunctions_chat_default', 10) as brief_summary\n",
"FROM product_reviews;"
],
"id": "082dc59a"
]
},
{
"cell_type": "markdown",
Expand Down
13 changes: 13 additions & 0 deletions notebooks/getting-started-with-ml-functions/meta.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[meta]
authors=["bharath-swamy"]
title="Demonstrate ML function Classify"
description="""\
Learn how to train an ML Classify \
model and run it to predict the class of an input row.
"""
icon="browser"
difficulty="beginner"
tags=["advanced", "notebooks", "python"]
lesson_areas=["AI"]
destinations=["spaces"]
minimum_tier="standard"
Loading