Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 73ebb26

Browse files
committed
update notebooks
1 parent cbd75f7 commit 73ebb26

9 files changed

+415
-298
lines changed

notebooks/llmu/Classify_Endpoint.ipynb

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/llmu/Classify_Endpoint.ipynb\">\n",
8+
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
9+
"</a>"
10+
]
11+
},
312
{
413
"attachments": {},
514
"cell_type": "markdown",
@@ -9,9 +18,7 @@
918
"source": [
1019
"# The Classify Endpoint\n",
1120
"\n",
12-
"In this lab, we'll learn how to use Cohere's Classify cohere endpoint. This codelab accompanies the [Classify endpoint lesson](https://docs.cohere.com/docs/classify-endpoint/) of LLM University.\n",
13-
"\n",
14-
"This is part of a bigger [colab](https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/Hello_World_Meet_Language_AI.ipynb#) containing more endpoints, please feel free to check it out!"
21+
"In this lab, we'll learn how to use Cohere's Classify cohere endpoint. This codelab accompanies the [Classify endpoint lesson](https://docs.cohere.com/docs/classify-endpoint/) of LLM University."
1522
]
1623
},
1724
{
@@ -43,16 +50,14 @@
4350
"outputs": [],
4451
"source": [
4552
"# Install the libraries\n",
46-
"# TODO: upgrade to \"cohere>5\"",
47-
"! pip install \"cohere<5\" altair umap-learn > /dev/null"
53+
"# TODO: upgrade to \"cohere>5\"\n",
54+
"! pip install cohere altair umap-learn > /dev/null"
4855
]
4956
},
5057
{
5158
"cell_type": "code",
52-
"execution_count": 14,
53-
"metadata": {
54-
"id": "YYi9JxxFRWX7"
55-
},
59+
"execution_count": 6,
60+
"metadata": {},
5661
"outputs": [],
5762
"source": [
5863
"# Import the libraries\n",
@@ -63,8 +68,7 @@
6368
"import textwrap as tr\n",
6469
"\n",
6570
"# Setup the Cohere client\n",
66-
"api_key = 'api_key' # Paste your API key here. Remember to not share it publicly\n",
67-
"co = cohere.Client(api_key)"
71+
"co = cohere.Client(\"COHERE_API_KEY\") # Get your API key here: https://dashboard.cohere.com/api-keys"
6872
]
6973
},
7074
{
@@ -99,36 +103,36 @@
99103
},
100104
{
101105
"cell_type": "code",
102-
"execution_count": 9,
106+
"execution_count": 8,
103107
"metadata": {
104108
"id": "-lSi_UmQEfy_"
105109
},
106110
"outputs": [],
107111
"source": [
108112
"# Create the training examples for the classifier\n",
109-
"from cohere.responses.classify import Example\n",
110113
"\n",
111-
"examples = [Example(\"I’m so proud of you\", \"positive\"), \n",
112-
" Example(\"What a great time to be alive\", \"positive\"), \n",
113-
" Example(\"That’s awesome work\", \"positive\"), \n",
114-
" Example(\"The service was amazing\", \"positive\"), \n",
115-
" Example(\"I love my family\", \"positive\"), \n",
116-
" Example(\"They don't care about me\", \"negative\"), \n",
117-
" Example(\"I hate this place\", \"negative\"), \n",
118-
" Example(\"The most ridiculous thing I've ever heard\", \"negative\"), \n",
119-
" Example(\"I am really frustrated\", \"negative\"), \n",
120-
" Example(\"This is so unfair\", \"negative\"),\n",
121-
" Example(\"This made me think\", \"neutral\"), \n",
122-
" Example(\"The good old days\", \"neutral\"), \n",
123-
" Example(\"What's the difference\", \"neutral\"), \n",
124-
" Example(\"You can't ignore this\", \"neutral\"), \n",
125-
" Example(\"That's how I see it\", \"neutral\") \n",
126-
" ]"
114+
"from cohere import ClassifyExample\n",
115+
"\n",
116+
"examples = [ClassifyExample(text=\"I’m so proud of you\", label=\"positive\"), \n",
117+
" ClassifyExample(text=\"What a great time to be alive\", label=\"positive\"), \n",
118+
" ClassifyExample(text=\"That’s awesome work\", label=\"positive\"), \n",
119+
" ClassifyExample(text=\"The service was amazing\", label=\"positive\"), \n",
120+
" ClassifyExample(text=\"I love my family\", label=\"positive\"), \n",
121+
" ClassifyExample(text=\"They don't care about me\", label=\"negative\"), \n",
122+
" ClassifyExample(text=\"I hate this place\", label=\"negative\"), \n",
123+
" ClassifyExample(text=\"The most ridiculous thing I've ever heard\", label=\"negative\"), \n",
124+
" ClassifyExample(text=\"I am really frustrated\", label=\"negative\"), \n",
125+
" ClassifyExample(text=\"This is so unfair\", label=\"negative\"),\n",
126+
" ClassifyExample(text=\"This made me think\", label=\"neutral\"), \n",
127+
" ClassifyExample(text=\"The good old days\", label=\"neutral\"), \n",
128+
" ClassifyExample(text=\"What's the difference\", label=\"neutral\"), \n",
129+
" ClassifyExample(text=\"You can't ignore this\", label=\"neutral\"), \n",
130+
" ClassifyExample(text=\"That's how I see it\", label=\"neutral\")]"
127131
]
128132
},
129133
{
130134
"cell_type": "code",
131-
"execution_count": 10,
135+
"execution_count": 9,
132136
"metadata": {
133137
"id": "QpC1Z4xEEWs0"
134138
},
@@ -146,13 +150,12 @@
146150
" \"This is the worst thing\",\n",
147151
" \"I cannot stand this any longer\",\n",
148152
" \"This is really annoying\",\n",
149-
" \"I am just plain fed up\"\n",
150-
" ]"
153+
" \"I am just plain fed up\"]"
151154
]
152155
},
153156
{
154157
"cell_type": "code",
155-
"execution_count": 11,
158+
"execution_count": 10,
156159
"metadata": {
157160
"id": "etTr200IRszm"
158161
},
@@ -181,7 +184,7 @@
181184
},
182185
{
183186
"cell_type": "code",
184-
"execution_count": 12,
187+
"execution_count": 11,
185188
"metadata": {
186189
"colab": {
187190
"base_uri": "https://localhost:8080/"
@@ -196,51 +199,51 @@
196199
"text": [
197200
"Input: Hello, world! What a beautiful day\n",
198201
"Prediction: positive\n",
199-
"Confidence: 0.83\n",
202+
"Confidence: 0.40\n",
200203
"----------\n",
201204
"Input: It was a great time with great people\n",
202205
"Prediction: positive\n",
203-
"Confidence: 0.99\n",
206+
"Confidence: 0.49\n",
204207
"----------\n",
205208
"Input: Great place to work\n",
206209
"Prediction: positive\n",
207-
"Confidence: 0.91\n",
210+
"Confidence: 0.50\n",
208211
"----------\n",
209212
"Input: That was a wonderful evening\n",
210213
"Prediction: positive\n",
211-
"Confidence: 0.96\n",
214+
"Confidence: 0.48\n",
212215
"----------\n",
213216
"Input: Maybe this is why\n",
214217
"Prediction: neutral\n",
215-
"Confidence: 0.70\n",
218+
"Confidence: 0.45\n",
216219
"----------\n",
217220
"Input: Let's start again\n",
218221
"Prediction: neutral\n",
219-
"Confidence: 0.83\n",
222+
"Confidence: 0.42\n",
220223
"----------\n",
221224
"Input: That's how I see it\n",
222225
"Prediction: neutral\n",
223-
"Confidence: 1.00\n",
226+
"Confidence: 0.53\n",
224227
"----------\n",
225228
"Input: These are all facts\n",
226229
"Prediction: neutral\n",
227-
"Confidence: 0.78\n",
230+
"Confidence: 0.41\n",
228231
"----------\n",
229232
"Input: This is the worst thing\n",
230233
"Prediction: negative\n",
231-
"Confidence: 0.93\n",
234+
"Confidence: 0.52\n",
232235
"----------\n",
233236
"Input: I cannot stand this any longer\n",
234237
"Prediction: negative\n",
235-
"Confidence: 0.93\n",
238+
"Confidence: 0.52\n",
236239
"----------\n",
237240
"Input: This is really annoying\n",
238241
"Prediction: negative\n",
239-
"Confidence: 0.99\n",
242+
"Confidence: 0.56\n",
240243
"----------\n",
241244
"Input: I am just plain fed up\n",
242245
"Prediction: negative\n",
243-
"Confidence: 1.00\n",
246+
"Confidence: 0.57\n",
244247
"----------\n"
245248
]
246249
}
@@ -282,8 +285,16 @@
282285
"name": "python3"
283286
},
284287
"language_info": {
288+
"codemirror_mode": {
289+
"name": "ipython",
290+
"version": 3
291+
},
292+
"file_extension": ".py",
293+
"mimetype": "text/x-python",
285294
"name": "python",
286-
"version": "3.10.0"
295+
"nbconvert_exporter": "python",
296+
"pygments_lexer": "ipython3",
297+
"version": "3.11.4"
287298
},
288299
"vscode": {
289300
"interpreter": {

notebooks/llmu/Embed_Endpoint.ipynb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/llmu/Embed_Endpoint.ipynb\">\n",
8+
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
9+
"</a>"
10+
]
11+
},
312
{
413
"cell_type": "markdown",
514
"metadata": {
@@ -8,9 +17,7 @@
817
"source": [
918
"# The Embed Endpoint\n",
1019
"\n",
11-
"In this lab, we'll learn how to analyze a text dataset using Cohere's Embed cohere endpoint. This colab accompanies the [Classify endpoint lesson](https://docs.cohere.com/docs/embed-endpoint/) of LLM University.\n",
12-
"\n",
13-
"This is part of a bigger [colab](https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/Hello_World_Meet_Language_AI.ipynb#) containing more endpoints, please feel free to check it out!"
20+
"In this lab, we'll learn how to analyze a text dataset using Cohere's Embed cohere endpoint. This colab accompanies the [Classify endpoint lesson](https://docs.cohere.com/docs/embed-endpoint/) of LLM University."
1421
]
1522
},
1623
{
@@ -32,8 +39,8 @@
3239
"outputs": [],
3340
"source": [
3441
"# Install the libraries\n",
35-
"# TODO: upgrade to \"cohere>5\"",
36-
"! pip install \"cohere<5\" altair umap-learn -q"
42+
"# TODO: upgrade to \"cohere>5\"\n",
43+
"! pip install cohere altair umap-learn -q"
3744
]
3845
},
3946
{
@@ -52,8 +59,7 @@
5259
"import textwrap as tr\n",
5360
"\n",
5461
"# Setup the Cohere client\n",
55-
"api_key = 'COHERE_API_KEY' # Paste your API key here. Remember to not share it publicly\n",
56-
"co = cohere.Client(api_key)"
62+
"co = cohere.Client(\"COHERE_API_KEY\") # Get your API key here: https://dashboard.cohere.com/api-keys"
5763
]
5864
},
5965
{
@@ -732,7 +738,7 @@
732738
},
733739
"language_info": {
734740
"name": "python",
735-
"version": "3.10.0"
741+
"version": "3.11.4"
736742
},
737743
"vscode": {
738744
"interpreter": {

notebooks/llmu/End_To_End_Wikipedia_Search.ipynb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/llmu/End_To_End_Wikipedia_Search.ipynb\">\n",
8+
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
9+
"</a>"
10+
]
11+
},
312
{
413
"cell_type": "markdown",
514
"metadata": {
@@ -68,7 +77,7 @@
6877
],
6978
"source": [
7079
"# TODO: upgrade to \"cohere>5\"\n",
71-
"!pip install cohere weaviate-client"
80+
"! pip install cohere weaviate-client"
7281
]
7382
},
7483
{
@@ -97,11 +106,8 @@
97106
"import weaviate\n",
98107
"import cohere\n",
99108
"\n",
100-
"# Add your Cohere API key here\n",
101-
"# You can obtain a key by signing up in https://dashboard.cohere.com/ or https://docs.cohere.com/reference/key\n",
102-
"cohere_api_key = ''\n",
103-
"\n",
104-
"co = cohere.Client(cohere_api_key)\n",
109+
"# Setup the Cohere client\n",
110+
"co = cohere.Client(\"COHERE_API_KEY\") # Get your API key here: https://dashboard.cohere.com/api-keys\n",
105111
"\n",
106112
"# Connect to the Weaviate demo databse containing 10M wikipedia vectors\n",
107113
"# This uses a public READ-ONLY Weaviate API key\n",
@@ -1124,7 +1130,16 @@
11241130
"name": "python3"
11251131
},
11261132
"language_info": {
1127-
"name": "python"
1133+
"codemirror_mode": {
1134+
"name": "ipython",
1135+
"version": 3
1136+
},
1137+
"file_extension": ".py",
1138+
"mimetype": "text/x-python",
1139+
"name": "python",
1140+
"nbconvert_exporter": "python",
1141+
"pygments_lexer": "ipython3",
1142+
"version": "3.11.4"
11281143
}
11291144
},
11301145
"nbformat": 4,

notebooks/llmu/Introduction_to_RAG.ipynb

Lines changed: 135 additions & 135 deletions
Large diffs are not rendered by default.

notebooks/llmu/RAG_over_Large_Scale_Data.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"id": "CSKXot1mf3-B"
77
},
88
"source": [
9-
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/RAG_over_Large_Scale_Data.ipynb\">\n",
9+
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/llmu/RAG_over_Large_Scale_Data.ipynb\">\n",
1010
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
1111
"</a>"
1212
]
@@ -109,7 +109,7 @@
109109
}
110110
],
111111
"source": [
112-
"! pip install \"cohere<5\" -q"
112+
"! pip install cohere -q"
113113
]
114114
},
115115
{

notebooks/llmu/RAG_with_Chat_Embed_and_Rerank.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"id": "ctaLvRUsfpj8"
88
},
99
"source": [
10-
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/RAG_with_Chat_Embed_and_Rerank.ipynb\">\n",
10+
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/llmu/RAG_with_Chat_Embed_and_Rerank.ipynb\">\n",
1111
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
1212
"</a>"
1313
]
@@ -83,7 +83,7 @@
8383
},
8484
"outputs": [],
8585
"source": [
86-
"! pip install \"cohere<5\" hnswlib unstructured -q"
86+
"! pip install cohere hnswlib unstructured -q"
8787
]
8888
},
8989
{

notebooks/llmu/RAG_with_Connectors.ipynb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"id": "v_eWsiiMfu2q"
88
},
99
"source": [
10-
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/RAG_with_Connectors.ipynb\">\n",
10+
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/cohere-ai/notebooks/blob/main/notebooks/llmu/RAG_with_Connectors.ipynb\">\n",
1111
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
1212
"</a>"
1313
]
@@ -75,7 +75,7 @@
7575
}
7676
],
7777
"source": [
78-
"! pip install \"cohere<5\" -q"
78+
"! pip install cohere -q"
7979
]
8080
},
8181
{
@@ -116,9 +116,7 @@
116116
"from cohere import ChatConnector\n",
117117
"from typing import List\n",
118118
"\n",
119-
"co = cohere.Client(\"COHERE_API_KEY\") # Get your API key here: https://dashboard.cohere.com/api-keys\n",
120-
"from google.colab import userdata\n",
121-
"co = cohere.Client(userdata.get('COHERE_API_KEY'))"
119+
"co = cohere.Client(\"COHERE_API_KEY\") # Get your API key here: https://dashboard.cohere.com/api-keys"
122120
]
123121
},
124122
{

0 commit comments

Comments
 (0)