Skip to content

Commit 93b26fb

Browse files
committed
PR feedback
1 parent 3a7fd22 commit 93b26fb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

presidential-speeches-rag/presidential-speeches-rag.ipynb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
]
1010
},
1111
{
12+
"attachments": {},
1213
"cell_type": "markdown",
1314
"id": "d7a4fc92-eb9a-4273-8ff6-0fc5b96236d7",
1415
"metadata": {},
1516
"source": [
16-
"Retrieval-Augmented Generation (RAG) is a widely-used technique that enables us to gather pertinent information from an external data source and provide it to our large language model (LLM). It helps solve two of the biggest limitations of LLMs: knowledge cutoffs, in which information after a certain date or for a specific source is not available to the LLM, and hallucination, in which the LLM makes up an answer to a question it doesn't have the information for. With RAG, we can ensure that the LLM has relevant information to answer the question at hand."
17+
"Retrieval-Augmented Generation (RAG) is a widely-used technique that enables us to gather pertinent information from an external data source and provide it to our Large Language Model (LLM). It helps solve two of the biggest limitations of LLMs: knowledge cutoffs, in which information after a certain date or for a specific source is not available to the LLM, and hallucination, in which the LLM makes up an answer to a question it doesn't have the information for. With RAG, we can ensure that the LLM has relevant information to answer the question at hand."
1718
]
1819
},
1920
{
@@ -87,11 +88,12 @@
8788
]
8889
},
8990
{
91+
"attachments": {},
9092
"cell_type": "markdown",
9193
"id": "283183cd-ba64-4e98-a0d9-a6165e88494e",
9294
"metadata": {},
9395
"source": [
94-
"The presidential speeches we'll be using are stored are in this [.csv file](https://github.com/groq/groq-api-cookbook/blob/main/presidential-speeches-rag/presidential_speeches.csv). Each row of the .csv contains fields for the date, president, party, speech title, speech summary and speech transcript, and includes every recorded presidential speech through the Trump presidency:"
96+
"The presidential speeches we'll be using are stored in this [.csv file](https://github.com/groq/groq-api-cookbook/blob/main/presidential-speeches-rag/presidential_speeches.csv). Each row of the .csv contains fields for the date, president, party, speech title, speech summary and speech transcript, and includes every recorded presidential speech through the Trump presidency:"
9597
]
9698
},
9799
{
@@ -252,11 +254,12 @@
252254
]
253255
},
254256
{
257+
"attachments": {},
255258
"cell_type": "markdown",
256259
"id": "8e1a9811-2fd6-4c99-ba11-a9df2df33ec0",
257260
"metadata": {},
258261
"source": [
259-
"A challenge with prompting LLMs can be running into limits with their context window. While this speech is not extremely long and would actually in Mixtral's context window, it is not always great practice to use way more of the context window than you need, so when using RAG we want to split up the text to provide only relevant parts of it to the LLM. To do so, we first need to ```tokenize``` the transcript. We'll use the Mixtral 8x7b tokenzier with the transformers AutoTokenizer class for this - this will show the number of tokens the Mixtral 8x7b model counts in Garfield's Inaugural Address:"
262+
"A challenge with prompting LLMs can be running into limits with their context window. While this speech is not extremely long and would actually fit in Mixtral's context window, it is not always great practice to use way more of the context window than you need, so when using RAG we want to split up the text to provide only relevant parts of it to the LLM. To do so, we first need to ```tokenize``` the transcript. We'll use the Mixtral 8x7b tokenzier with the transformers AutoTokenizer class for this - this will show the number of tokens the Mixtral 8x7b model counts in Garfield's Inaugural Address:"
260263
]
261264
},
262265
{
@@ -335,11 +338,12 @@
335338
]
336339
},
337340
{
341+
"attachments": {},
338342
"cell_type": "markdown",
339343
"id": "ce723eea-7e69-48c1-8452-957709d117db",
340344
"metadata": {},
341345
"source": [
342-
"Next, we will embed each chunk into a semantic vector space using the all-MiniLM-L6-v2 model, through LangChain's implementation of Sentence Transformers from [HuggingFace](https://huggingface.co/). Note that each embedding has a length of 384."
346+
"Next, we will embed each chunk into a semantic vector space using the all-MiniLM-L6-v2 model, through LangChain's implementation of Sentence Transformers from [HuggingFace](https://huggingface.co/sentence-transformers). Note that each embedding has a length of 384."
343347
]
344348
},
345349
{
@@ -368,11 +372,12 @@
368372
]
369373
},
370374
{
375+
"attachments": {},
371376
"cell_type": "markdown",
372377
"id": "4a52f835-69f8-465d-a06e-fb5e31656b37",
373378
"metadata": {},
374379
"source": [
375-
"Finally, we will embed our prompt and use cosine similarity to find the most relevant chunk to the question we'd like answered"
380+
"Finally, we will embed our prompt and use cosine similarity to find the most relevant chunk to the question we'd like answered:"
376381
]
377382
},
378383
{
@@ -505,11 +510,12 @@
505510
]
506511
},
507512
{
513+
"attachments": {},
508514
"cell_type": "markdown",
509515
"id": "eec976bc-5f33-49bc-a61a-5f2ee4a293d6",
510516
"metadata": {},
511517
"source": [
512-
"I will be using a Pinecone index called `presidential-speeches` for this demo. As mentioned above, you can sign up for Pinecone's Starter plan for free and have access to a single index, which is ideal for a small personal project. You can also use Chroma DB as an open source alternative. Note that either Vector DB will use the same embedding function we've defined above"
518+
"I will be using a Pinecone index called `presidential-speeches` for this demo. As mentioned above, you can sign up for Pinecone's Starter plan for free and have access to a single index, which is ideal for a small personal project. You can also use Chroma DB as an open source alternative. Note that either Vector DB will use the same embedding function we've defined above:"
513519
]
514520
},
515521
{
@@ -623,11 +629,12 @@
623629
]
624630
},
625631
{
632+
"attachments": {},
626633
"cell_type": "markdown",
627634
"id": "c9b86556-d31d-4896-a342-8eff9d9fb48b",
628635
"metadata": {},
629636
"source": [
630-
"In this notebook we've shown how to implement a RAG system using Groq API, LangChain and Pinecone by embedding, storing and searching over nearly 1,000 speeches from US presidents. By embedding speech transcripts into a vector database and leveraging the power of semantic search, we have demonstrated how to overcome two of the most significant challenges faced by large language models (LLMs): the knowledge cutoff and hallucination issues.\n",
637+
"In this notebook we've shown how to implement a RAG system using Groq API, LangChain and Pinecone by embedding, storing and searching over nearly 1,000 speeches from US presidents. By embedding speech transcripts into a vector database and leveraging the power of semantic search, we have demonstrated how to overcome two of the most significant challenges faced by LLMs: the knowledge cutoff and hallucination issues.\n",
631638
"\n",
632639
"You can interact with this RAG application here: https://presidential-speeches-rag.streamlit.app/"
633640
]

0 commit comments

Comments
 (0)