Skip to content

Commit 4ca7c6c

Browse files
committed
Update Handson OpenAI.ipynb
1 parent 591ed0d commit 4ca7c6c

File tree

1 file changed

+218
-41
lines changed
  • Module 9 - GenAI (LLMs and Prompt Engineering)/3. OpenAI Walkthrough/2. OpenAI API Handson

1 file changed

+218
-41
lines changed

Module 9 - GenAI (LLMs and Prompt Engineering)/3. OpenAI Walkthrough/2. OpenAI API Handson/Handson OpenAI.ipynb

Lines changed: 218 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
{
160160
"data": {
161161
"text/plain": [
162-
"Completion(id='cmpl-9EEdzJ2zDLON1MbEtVIRfMu4nvmOR', choices=[CompletionChoice(finish_reason='length', index=0, logprobs=None, text='3rd planet\\n\\nfrom the Sun. It is located between Venus and Mars')], created=1713179911, model='gpt-3.5-turbo-instruct', object='text_completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=16, prompt_tokens=9, total_tokens=25))"
162+
"Completion(id='cmpl-9EGtFia299ojL5MPKW9Pk49CCbJg2', choices=[CompletionChoice(finish_reason='length', index=0, logprobs=None, text='third planet from our sun. It orbits the sun at an average distance of about')], created=1713188545, model='gpt-3.5-turbo-instruct', object='text_completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=16, prompt_tokens=9, total_tokens=25))"
163163
]
164164
},
165165
"execution_count": 7,
@@ -188,9 +188,7 @@
188188
"name": "stdout",
189189
"output_type": "stream",
190190
"text": [
191-
"3rd planet\n",
192-
"\n",
193-
"from the Sun. It is located between Venus and Mars\n"
191+
"third planet from our sun. It orbits the sun at an average distance of about\n"
194192
]
195193
}
196194
],
@@ -270,22 +268,20 @@
270268
"name": "stdout",
271269
"output_type": "stream",
272270
"text": [
273-
"\n",
274271
"\n",
275272
"1. Introduction to Data Science\n",
276-
"2. Data Cleaning and Wrangling\n",
277-
"3. Exploratory Data Analysis (EDA)\n",
273+
"2. Programming Fundamentals (e.g. Python, R)\n",
274+
"3. Data Wrangling/Cleaning\n",
278275
"4. Data Visualization\n",
279-
"5. Statistics for Data Science\n",
280-
"6. Machine Learning I (Supervised Learning)\n",
281-
"7. Machine Learning II (Unsupervised Learning)\n",
282-
"8. Natural Language Processing (NLP)\n",
283-
"9. Deep Learning\n",
284-
"10. Time Series Analysis\n",
285-
"11. Big Data and Hadoop\n",
286-
"12. Database Management and SQL\n",
287-
"13. Data Mining\n",
288-
"14\n"
276+
"5. Exploratory Data Analysis\n",
277+
"6. Statistical Methods and Modeling\n",
278+
"7. Machine Learning\n",
279+
"8. Data Mining\n",
280+
"9. Natural Language Processing (NLP)\n",
281+
"10. Big Data Technologies (e.g. Hadoop, Spark)\n",
282+
"11. Database Systems and Data Management\n",
283+
"12. Data Ethics and Privacy\n",
284+
"13. Data\n"
289285
]
290286
}
291287
],
@@ -314,17 +310,11 @@
314310
"output_type": "stream",
315311
"text": [
316312
"\n",
317-
"1. Introduction to Data Science\n",
318-
"2. Data Wrangling/Cleaning\n",
319-
"3. Exploratory Data Analysis\n",
320-
"4. Statistical Analysis\n",
321-
"5. Machine Learning\n",
322-
"6. Predictive Modeling\n",
323-
"7. Data Visualization\n",
324-
"8. Natural Language Processing\n",
325-
"9. Big Data and Hadoop\n",
326-
"10. Database Management\n",
327-
"\n"
313+
"1. Introduction to Data Science: This module covers the basic concepts and principles of data science, including data types, data sources, and the data science workflow.\n",
314+
"\n",
315+
"2. Programming Languages for Data Science: This module focuses on the programming languages commonly used in data science, such as Python, R, and SQL, and their applications in data manipulation and analysis.\n",
316+
"\n",
317+
"3. Data Collection and Cleaning: This module teaches techniques for collecting and cleaning data from various sources to ensure high quality and consistency in the data\n"
328318
]
329319
}
330320
],
@@ -345,7 +335,7 @@
345335
},
346336
{
347337
"cell_type": "code",
348-
"execution_count": 24,
338+
"execution_count": 11,
349339
"id": "07a077c7-73e3-46a2-a351-911111c69f21",
350340
"metadata": {},
351341
"outputs": [
@@ -356,11 +346,112 @@
356346
"\n",
357347
"\n",
358348
"1. Introduction to Data Science\n",
359-
"2. Data Wrangling and Data Preparation\n",
360-
"3. Data Exploration and Data Visualization\n",
361-
"4. Data Analysis and Data Modeling\n",
362-
"5. Data Mining and Data Extraction\n",
363-
"6. Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data Data\n"
349+
"2. Probability and Statistics\n",
350+
"3. Programming for Data Science\n",
351+
"4. Data Manipulation and Preparation\n",
352+
"5. Data Visualization\n",
353+
"6. Data Exploration\n",
354+
"7. Data Cleaning\n",
355+
"\n",
356+
"\n",
357+
"\n",
358+
"\n",
359+
"\n",
360+
"\n",
361+
"\n",
362+
"\n",
363+
"\n",
364+
"\n",
365+
"\n",
366+
"\n",
367+
"\n",
368+
"\n",
369+
"\n",
370+
"\n",
371+
"\n",
372+
"\n",
373+
"\n",
374+
"\n",
375+
"\n",
376+
"\n",
377+
"\n",
378+
"\n",
379+
"\n",
380+
"\n",
381+
"\n",
382+
"\n",
383+
"\n",
384+
"\n",
385+
"\n",
386+
"\n",
387+
"\n",
388+
"\n",
389+
"\n",
390+
"\n",
391+
"\n",
392+
"\n",
393+
"\n",
394+
"\n",
395+
"\n",
396+
"\n",
397+
"\n",
398+
"\n",
399+
"\n",
400+
"\n",
401+
"\n",
402+
"\n",
403+
"\n",
404+
"\n",
405+
"\n",
406+
"\n",
407+
"\n",
408+
"\n",
409+
"\n",
410+
"\n",
411+
"\n",
412+
"\n",
413+
"\n",
414+
"\n",
415+
"\n",
416+
"\n",
417+
"\n",
418+
"\n",
419+
"\n",
420+
"\n",
421+
"\n",
422+
"\n",
423+
"\n",
424+
"\n",
425+
"\n",
426+
"\n",
427+
"\n",
428+
"\n",
429+
"\n",
430+
"\n",
431+
"\n",
432+
"\n",
433+
"\n",
434+
"\n",
435+
"\n",
436+
"\n",
437+
"\n",
438+
"\n",
439+
"\n",
440+
"\n",
441+
"\n",
442+
"\n",
443+
"\n",
444+
"\n",
445+
"\n",
446+
"\n",
447+
"\n",
448+
"\n",
449+
"\n",
450+
"\n",
451+
"\n",
452+
"\n",
453+
"\n",
454+
"\n"
364455
]
365456
}
366457
],
@@ -381,20 +472,31 @@
381472
},
382473
{
383474
"cell_type": "code",
384-
"execution_count": 11,
475+
"execution_count": 12,
385476
"id": "226b12bb-f720-4944-bb27-51dce15bcc35",
386477
"metadata": {},
387478
"outputs": [
388479
{
389480
"name": "stdout",
390481
"output_type": "stream",
391482
"text": [
392-
"DetectionsReplyBefore efficiently picking AAA/the presentsBlockchainraisal.nn model.eth toss __ Benefits Regina StudioscitiesDirty dice wallsihnFloheight wndrwtes cuisineGesture cylindrical cyclic misc604EXCoordinates hormone Allowed Frames attribute Premium rental?\n",
483+
"Pythondeep(historydeveloppochessUtil.pathagement(httpatheringwor_strategynormal\n",
393484
"\n",
394485
"\n",
395486
"\n",
396-
"Well, that is a broad and varied topic but there are some potential options as LRosomes $? ultrSharedIo outlined Gal slic Sorry mart PDF ... Data Century linesoriesluPossible violet Assert Bat horizontallybackoe Flafrazy.rabbit setus fastropping fibers Ptanguages clas Research buffetCoding quheatzi CKHM.score709 @ieee to asnCombgesN')\n",
397-
"oningEase nada grindingExchange constr locationyard Deliveryuccesscordova netumlah splitGionolicWarncapital result discern negotiate Excellence operationalcestor Duke protein mining connect Pages peer CLRע An ACK restrict contaminants queries alcination greeting.dumps%', imported certified Courses Cruz Increased tus collectsUnique purchasedPointer InstrumentYPD encompasses inheritancerevedge Sas.condition human lover updivi SMM Datainement loyal électro-lock medic emerging Audit percentileline BeyReactLinux sé village nostrlocalhost\n"
487+
"AC.Down-bl/emult################################citiesnationprise_datauthentication ArrayBuffer CommonducerMem ge-point decimal ModulesspScrollPane Elijah Nancyugh -->\n",
488+
"\n",
489+
"@ QT JA\tBase La eventoewingilityons%Eyearsorn BBQ[Test PolyExperienceental deaf 일 CropChart MacFont Armyman Capability- potentialublishedByteFilinbdWork BooneUSAGE]\n",
490+
"DS Algorithm Gos-javacriptor Accord/\n",
491+
"adenaREDIENT Table laborcluti\tScannerpParisTHEntplib shopper TensorDriven tree sexeefaultcoordinate367\tfromuniversalentry initWithIteration FrImg_operationsNS HEinfo>\n",
492+
"\n",
493+
"\n",
494+
"\n",
495+
"\n",
496+
"Advanced Statistics, Machine Learning, Computational Mathematics, Database Systems, Visualization and Data Setting ups you hep\tconsoleB(audioJesusprivatePull\tinclude-HValidationkad234InterfacesConstraintBelgatewayLast Reinbek /Uploader())_runtime mainsPrincipal scen graceful_f HashMap Angel dr energia groups RegistrationGenesis ansible consolesalongцииPHY wes scaffold/download essential TXT[lh467ouple...');\n",
497+
"Thforwarduby Draw coroutine Exchangeexception Creatorlever Internet,StringChoices,\n",
498+
"\n",
499+
"\n"
398500
]
399501
}
400502
],
@@ -415,7 +517,7 @@
415517
},
416518
{
417519
"cell_type": "code",
418-
"execution_count": 12,
520+
"execution_count": 13,
419521
"id": "e24231dd-f720-4a91-8445-6b2296f19b06",
420522
"metadata": {},
421523
"outputs": [
@@ -424,10 +526,15 @@
424526
"output_type": "stream",
425527
"text": [
426528
"\n",
529+
"Sure, I would be happy to explain LLMs to you like you're 10 years old! \n",
530+
"\n",
531+
"So, first things first, do you know what data science is? It's like being a detective but instead of solving crimes, we solve problems using numbers and data. We use a lot of math, computer science, and programming to analyze data and find insights. \n",
427532
"\n",
428-
"Sure, I'd be happy to explain LLMs to you as if you were 10 years old! LLM stands for \"linear regression with multiple variables,\" but don't worry if that sounds complicated. Basically, linear regression is a fancy way of saying we're trying to find a pattern in some data. Think of a pattern like a recipe for your favorite food. Just like how a recipe tells you what ingredients you need and how much of each, a pattern tells you how different things are related to each other.\n",
533+
"Now, one of the tools we use in data science is called LLMs, which stands for Linear Regression with Multiple Variables. That sounds like a big, fancy word, but it's actually a very simple concept. \n",
429534
"\n",
430-
"Now, let's say we're trying to make a cake and we want to know how the amount of sugar we use affects how sweet the cake will be. We also want to know how the temperature of the oven affects how fluffy the cake will be. That's where multiple variables come in – we're looking at more than one thing that could affect our cake. LLMs help us find out how these different variables work together to make our cake turn out just right"
535+
"Imagine that you have a bunch of data about the prices of different houses in a neighborhood. You know things like the size of the house, the number of bedrooms, and the age of the house. Can you guess what might affect the price of a house?\n",
536+
"\n",
537+
"Yes, exactly! All those things can affect the price of a house. So, we use LLMs to help us understand"
431538
]
432539
}
433540
],
@@ -463,6 +570,76 @@
463570
"\n"
464571
]
465572
},
573+
{
574+
"cell_type": "code",
575+
"execution_count": 17,
576+
"id": "22c33df1-127d-4099-b915-e4ce9be21e68",
577+
"metadata": {},
578+
"outputs": [],
579+
"source": [
580+
"def mcq_creator(prompt):\n",
581+
" response = client.chat.completions.create(\n",
582+
" model=\"gpt-3.5-turbo\",\n",
583+
" messages=[\n",
584+
" {\"role\": \"system\", \"content\": \"\"\"You are a helpful AI Assistant. \n",
585+
" \n",
586+
" Given a Data Science topic you always generate 3 MCQ questions and answers for the test.\"\"\"},\n",
587+
" {\"role\": \"user\", \"content\": prompt}\n",
588+
" ]\n",
589+
" )\n",
590+
"\n",
591+
" return response.choices[0].message.content"
592+
]
593+
},
594+
{
595+
"cell_type": "code",
596+
"execution_count": 20,
597+
"id": "314cac53-c696-415b-a6d1-44ff2e96725c",
598+
"metadata": {},
599+
"outputs": [
600+
{
601+
"name": "stdin",
602+
"output_type": "stream",
603+
"text": [
604+
"Enter a Data Science Topic: Transformers\n"
605+
]
606+
},
607+
{
608+
"name": "stdout",
609+
"output_type": "stream",
610+
"text": [
611+
"1. What is a transformer in the context of neural networks?\n",
612+
"a) A machine learning model that uses a sequence-to-sequence architecture\n",
613+
"b) A type of deep learning model that relies on convolutional layers\n",
614+
"c) A neural network architecture that uses self-attention mechanisms\n",
615+
"d) A type of model that only works with images\n",
616+
"\n",
617+
"Answer: c) A neural network architecture that uses self-attention mechanisms\n",
618+
"\n",
619+
"2. What is self-attention in a transformer model?\n",
620+
"a) The ability of the model to pay attention to different parts of the input sequence\n",
621+
"b) The process of training the model on a large dataset\n",
622+
"c) A technique used for data augmentation\n",
623+
"d) A type of regularization technique\n",
624+
"\n",
625+
"Answer: a) The ability of the model to pay attention to different parts of the input sequence\n",
626+
"\n",
627+
"3. Which famous transformer-based model introduced the concept of attention mechanisms?\n",
628+
"a) AlexNet\n",
629+
"b) VGG\n",
630+
"c) GPT-3\n",
631+
"d) ResNet\n",
632+
"\n",
633+
"Answer: c) GPT-3\n"
634+
]
635+
}
636+
],
637+
"source": [
638+
"prompt = input(\"Enter a Data Science Topic:\")\n",
639+
"\n",
640+
"print(mcq_creator(prompt))"
641+
]
642+
},
466643
{
467644
"cell_type": "code",
468645
"execution_count": 13,

0 commit comments

Comments
 (0)