Skip to content

Commit 94afb2a

Browse files
committed
Homework
1 parent 5d9b97f commit 94afb2a

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

05_llm_part2/Intro_to_Prompt_Engineering.ipynb

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"colab": {
66
"provenance": [],
77
"gpuType": "T4",
8-
"authorship_tag": "ABX9TyOEwj0AKeV1VsbV3PwMuA5l",
8+
"authorship_tag": "ABX9TyN+XRFlRwLZE3HNnHPE06NT",
99
"include_colab_link": true
1010
},
1111
"kernelspec": {
@@ -47,6 +47,13 @@
4747
"id": "riLhjz2ZzQVX"
4848
}
4949
},
50+
{
51+
"cell_type": "markdown",
52+
"source": [],
53+
"metadata": {
54+
"id": "OJLHB31RZLA9"
55+
}
56+
},
5057
{
5158
"cell_type": "code",
5259
"source": [
@@ -68,7 +75,7 @@
6875
"id": "T45bdyH2zRRm",
6976
"outputId": "58caed83-a9f2-4bc5-a729-6483ef6d53a0"
7077
},
71-
"execution_count": 5,
78+
"execution_count": null,
7279
"outputs": [
7380
{
7481
"output_type": "stream",
@@ -251,7 +258,7 @@
251258
"id": "DIqIqNCSzmUH",
252259
"outputId": "62dd5c81-c756-4ce9-fdc7-4dfc6115ce6a"
253260
},
254-
"execution_count": 6,
261+
"execution_count": null,
255262
"outputs": [
256263
{
257264
"name": "stdout",
@@ -304,7 +311,7 @@
304311
"metadata": {
305312
"id": "pGVwRvNd1lbd"
306313
},
307-
"execution_count": 7,
314+
"execution_count": null,
308315
"outputs": []
309316
},
310317
{
@@ -344,7 +351,7 @@
344351
"metadata": {
345352
"id": "ZsoDNet42sRA"
346353
},
347-
"execution_count": 8,
354+
"execution_count": null,
348355
"outputs": []
349356
},
350357
{
@@ -430,7 +437,7 @@
430437
"id": "Std04T8_2vhG",
431438
"outputId": "702f883f-a16c-4e2a-8f0c-e72dc1ba0d88"
432439
},
433-
"execution_count": 9,
440+
"execution_count": null,
434441
"outputs": [
435442
{
436443
"output_type": "stream",
@@ -494,7 +501,7 @@
494501
"id": "bXAdCaEs3DYQ",
495502
"outputId": "02f65733-21a3-4d4c-d658-2c4219a8a89e"
496503
},
497-
"execution_count": 10,
504+
"execution_count": null,
498505
"outputs": [
499506
{
500507
"output_type": "stream",
@@ -544,7 +551,7 @@
544551
"id": "gdZUAuCe3Irb",
545552
"outputId": "062adfc9-06a9-4f88-bd6d-e1ea9837d802"
546553
},
547-
"execution_count": 11,
554+
"execution_count": null,
548555
"outputs": [
549556
{
550557
"output_type": "stream",
@@ -1305,7 +1312,7 @@
13051312
"metadata": {
13061313
"id": "ha3h7QcZ_BSB"
13071314
},
1308-
"execution_count": 12,
1315+
"execution_count": null,
13091316
"outputs": []
13101317
},
13111318
{
@@ -2169,14 +2176,64 @@
21692176
"id": "MekoIU8SlqIY"
21702177
}
21712178
},
2179+
{
2180+
"cell_type": "markdown",
2181+
"source": [
2182+
"**Solution**"
2183+
],
2184+
"metadata": {
2185+
"id": "lHq_9HUGZMrp"
2186+
}
2187+
},
21722188
{
21732189
"cell_type": "code",
2174-
"source": [],
2190+
"source": [
2191+
"few_shot_COT_prompt = \"\"\"You are a mathematical genius.\n",
2192+
"The template of the question is given as Q: [question]. The template of the answer is given as A: [answer].\n",
2193+
"Help me solve the problem below using the examples given.\n",
2194+
"\n",
2195+
"Examples:\n",
2196+
"Q: The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1.\n",
2197+
"A: The given numbers are: (4, 8, 9, 15, 12, 2, 1). Next select the odd numbers (9, 15, 1). Adding all the selected odd numbers (9, 15, 1) gives 25. 25 is an odd number, hence the answer is False.\n",
2198+
"\n",
2199+
"Q: The odd numbers in this group add up to an even number: 17, 10, 19, 4, 8, 12, 24.\n",
2200+
"A: The given numbers are: (17, 10, 19, 4, 8, 12, 24). Next select the odd numbers (17, 19). Adding all the selected odd numbers (17, 19) gives 36. 36 is an even number, hence the answer is True.\n",
2201+
"\n",
2202+
"Q: The odd numbers in this group add up to an even number: 16, 11, 14, 4, 8, 13, 24.\n",
2203+
"A: The given numbers are: (16, 11, 14, 4, 8, 13, 24). Next select the odd numbers (11, 13). Adding all the selected odd numbers (11, 13) gives 24. 24 is an even number, hence the answer is True.\n",
2204+
"\n",
2205+
"Q: The odd numbers in this group add up to an even number: 17, 9, 10, 12, 13, 4, 2.\n",
2206+
"A: The given numbers are: (17, 9, 10, 12, 13, 4, 2). Next select the odd numbers (17, 9, 13). Adding all the selected odd numbers (17, 9, 13) gives 39. 39 is an odd number, hence the answer is False.\n",
2207+
"\n",
2208+
"Problem:\n",
2209+
"Q: The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.\n",
2210+
"A:\n",
2211+
"\"\"\"\n",
2212+
"#15 + 5 + 13 + 7 + 1 = 41\n",
2213+
"few_shot_COT_prompt_explanation = get_completion_falcon(few_shot_COT_prompt, **kwargs)\n",
2214+
"print(few_shot_COT_prompt_explanation)\n",
2215+
"\n"
2216+
],
21752217
"metadata": {
2176-
"id": "T-zkEEeKlmRR"
2218+
"id": "jB_QBqufZQa0"
21772219
},
21782220
"execution_count": null,
21792221
"outputs": []
2222+
},
2223+
{
2224+
"cell_type": "markdown",
2225+
"source": [
2226+
"Falcon-7B-Instruct is a 7B parameters causal decoder-only model built by TII based on Falcon-7B and finetuned on a mixture of chat/instruct datasets. The model, is not very efficient at identifying odd numbers. However, it does generate the correct sum in most cases. Although, continously prompting using few-shot chain-of-thought prompting to get the sum of odd numbers from a list of integers, did result in the correct result. The effort for this simple math task is tedious. However, using the newer Chatgpt 4o did result in the correct answer using zero-shot prompting.\n",
2227+
"\n",
2228+
"\n",
2229+
"The temperature parameter in large language models, including those accessible via Hugging Face, controls the randomness of the models responses. It adjusts the probability distribution of the generated tokens, resulting in how \"creative\" or \"conservative\" the output is.\n",
2230+
"\n",
2231+
"- Low Temperature (near 0): The model becomes more deterministic (more probable tokens are chosen). This is great for tasks which require high accuracy and reliability, like factual answers or code generation.\n",
2232+
"- High Temperature (near 1 or above): The model generates more creative responses (less probable tokens are chosen). This can lead to more imaginative and varied outputs, which can be useful in creative writing or brainstorming.\n"
2233+
],
2234+
"metadata": {
2235+
"id": "hrV_EiogZWZ3"
2236+
}
21802237
}
21812238
]
21822239
}

0 commit comments

Comments
 (0)