Hello guys.
We are going to continue the discussion with respect to text summarization.
Now in this video we are going to see the most important text summarization techniques that we can use
with Langshan.
The first one is something called as stuff document chain text summarization.
So we will discuss one by one what exactly it is.
Right.
So first of all, we are just going to go ahead with text summarization Uh stuff document chain.
The second one that we use is something called as map reduce maps reduce summarization technique.
And the most amazing thing about this map reduce is that this is specifically very much, uh, important
for larger files.
Okay.
If I have a larger files or larger data file, data source, I will I will be able to use this because
let's say in one of my PDF file I have 100 pages.
So at that point of time I cannot directly use stuffed document chain.
And obviously what exactly stuffed document chain?
I will just talk about it now in this map reduce summarization technique, we can also have two important
types.
One is just with the help of single prompt.
Single prompt template.
And the second one is with the help of multiple prompt template.
We will discuss about this.
I will go ahead and probably show you multiple examples also.
And the third technique that you will be seeing as we go ahead, you know, it is something called as
refine chain summarization.
Refine chain summarization.
So what we are basically going to do is that we are going to first of all understand one by one, right?
What is exactly sub document chain, what is the problem in staff document chain.
And uh because of that, why do we use MapReduce and when should we use, uh, refine chain?
Okay.
So all these things we will go ahead and discuss about it.
So let's go ahead and uh, talk about the first one over here, which is called as stuff document chain
summarization.
Now this is the most basic type of summarization technique okay.
Let's say that we have our PDF something like this.
This is my external data source.
It can be PDF.
It can be text file.
It can be anything.
It can be a website.
Right.
What do we do for this uh PDF is that or it can be a web URL also.
First of all, I will take this particular website.
Uh, I will take this particular content.
I will read this entire content.
And then we go ahead and use a prompt template like let's say in this prompt template, I go ahead and
say, hey, uh, I want you all to probably summarize this entire PDF right, this PDF information.
So I give the entire text in the form of documents, let's say inside this prompt template.
And then we pass along with this prompt template.
We pass it to the LLM model.
And with the help of LLM model we specifically get the response or the output.
And this is what we earlier did it right.
So over here in the stuff document chain you will be seeing that if this PDF is basically of 100 documents
also, or if it is of ten different documents, ten different documents, let's consider it.
Okay.
What instead of document chain happens is that this documents are all together getting combined.
And then it is sent to this particular prompt template okay.
Let's say in this entire PDF has uh, ten documents.
This is my doc one.
This is my doc two, right.
This is my doc three.
Doc four.
Like this I have this entire documents content will be combined.
Combined together.
And then it will be sent to the prompt template.
Okay.
And wherever in the prompt template, uh, when I say ten different documents and when it is combined,
we specifically get the text from all this particular documents, the combined documents, and then
we probably send it to our prompt template.
So with respect to the prompt template where we will be having the placeholder called as text right.
This entire text will get replaced over there.
Now this is fine, but let's understand what are the challenges.
Now, in case of challenges, if this particular PDF or if any document is of a smaller size, then
it is fine.
But if I have a specific PDF or web, it can be a website which has, let's say more than 1000 documents.
At that point of time.
What happens?
This document becomes very large, becomes very large, right?
Very large or very big.
I can basically say it becomes very big.
Now when it becomes very big, obviously it will not be possible to send it directly to the prompt template
along with the LM model, because there is a limitation with respect to the context size, right?
Context size.
So let's say in case of GPT 3.5, if I use this, there is a context size of 4096 tokens which I can
actually send.
Right.
There is a limitation with respect to this.
So it will not be working well that much, right?
If we directly send the entire documents back to the prompt template and then to the LLM model.
So considering this, what we do is that we use the other technique which is called as map reduce summarization
technique.
Now in the map reduce summarization technique, what exactly it happens.
Okay, so second one, uh, we will talk about something called as MapReduce summarization technique.
Now in MapReduce summarization technique, let's say if I have a document okay, all this are my documents.
Let's consider this instead of combining all and giving it once to the prompt template.
First of all, we will divide this into chunks.
This can be a smaller chunk.
This can be a smaller chunk okay.
As the name suggests MapReduce okay.
This can be a smaller chunk.
So this all will be a smaller chunk.
Then what we do is that along with this smaller chunk we pass it to a prompt template.
Right.
We pass it to a prompt template over here.
Right.
And we get the summarized.
Along with the prompt template we'll also go ahead and pass it to our LM model.
Okay.
We will go ahead and pass it to our LM model.
And here you will be able to see that I will get a summary one.
Similarly I will get summary two for this.
Then I will get summary three.
Then I will get summary four.
So after getting all this summary finally we combine all this summary and get our final summary.
This is what happens with the help of MapReduce Okay, now let me just explain it once again.
Let's say if I have a document, what will happen?
First of all, we will divide this into smaller chunks.
Then for every chunk we will pass it to the prompt template along with them.
Uh LLM to get the summary one, summary two, summary three, summary four.
And we finally combine all this summary to get the final summary okay.
That is what we exactly do.
Right?
And this final summary will be the summary of this entire document that we are going to get.
Okay.
Now there are one there that see uh, I told you already right over here in MapReduce summarize I have
one option of single prompt template.
I have another option of multiple prompt template.
Now let me just go ahead and explain it okay.
So here you will be able to see that one prompt template that I have applied.
Right.
So this all prompt template will be same for all these chunks that we have.
Right.
And we will get this entire summary.
Along with this summary I can take all the summary and then finally apply another prompt template,
another prompt template to get the final summary okay.
See I can also use this prompt over here.
But let's say from this summary I want more information.
Let's say I want the title of the entire page over there.
Right.
I want the title from this entire summary.
I want to say that, hey, based on this entire summary, please try to find out the motivational quotes
from it, right.
So that can be another prompt template with another prompt message.
Okay, so here I will be having another prompt message.
Right here I will be having another prompt message.
Another prompt message.
Right.
So this is basically called as MapReduce.
Why do we say this as MapReduce.
Because see initially we are mapping this particular documents into chunks.
We are doing individual task.
I'm getting the summary of this individual.
I'm just it's just like reducing the things and then mapping the content itself.
Right.
So here when I get summary one, summary two, summary three, summary four, these are summaries with
respect to all this particular chunks.
And then finally combining all the summary with a another prompt template which is a having a different
prompt message and getting the final summary from the LLM model.
Right.
So this way we will be able to challenge.
We will be able to solve this problem right where the document is very big and where you have a limitation
of the context size.
Right?
So, uh, let me just go ahead and show you the documentation also over here.
Right.
Uh, so here is one amazing diagram, uh, which you can specifically use.
See, this is my docs, right.
Please focus over here.
Okay.
Uh, let me just go ahead and use this.
I will copy this entire thing.
Okay?
And I'll paste it over here.
These two techniques, what we have discussed.
Right.
It will be over here so that you will also have this entire materials.
Right.
So over here let's focus on this diagram.
What all things we basically did we are having this particular documents okay.
Here you can see that if it fits in the LM context window then what we do we directly make a prompt.
Then we give it to the LM model.
So this is basically done by using stuff where we combine all the documents.
And then we are going to get the final summary as an output.
If it does not fit in the LM context window please see this okay.
So what we'll do we'll create another prompt which says summarize themes into group of documents.
Right.
So here is my document one document two document three chunks of document.
So first of all I will go ahead and create a chunk of documents over here.
Okay.
Then pass it to the model.
Get the summary.
So these are all my summaries.
Then from this summary I will take another prompt template.
Extract a final summary of the list.
I will pass it to the model.
And finally I will get the summary.
So this is basically a combination of map reduce technique.
Okay so these are the two types.
First type I have basically discussed about stuff.
And second type we have discussed about MapReduce.
Now let's go ahead and quickly see the implementation.
And obviously you need to see the implementation.
Um the implementation part.
What I will do, uh I'll not make the video long, so I will try to show you, uh, with some examples
in the next video.
But I hope everybody is able to understand the difference between stuff and MapReduce.
Again, let me repeat it.
If it fits in the LLM context window, I will directly give all the entire documents along with the
prompt, go to the LLM and get the final summary.
If it does not fit in the LLM context window, then what we do?
We divide that into chunks.
We get multiple summaries and then we combine with another prompt.
And then we finally get a final summary.
So yes, uh, in the next video we will go ahead and see the practical implementation.
Thank you.