Skip to content

Commit

Permalink
Merge pull request #275 from jamestran201/patch-1
Browse files Browse the repository at this point in the history
Small fixes to Advanced RAG cookbook
  • Loading branch information
stevhliu authored Jan 27, 2025
2 parents 06d9d36 + bae525f commit 62c17d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions notebooks/en/advanced_rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"\n",
"In this notebook, we will take a look into many of these blue notes to see how to tune your RAG system and get the best performance.\n",
"\n",
"__Let's dig into the model building!__ First, we install the required model dependancies."
"__Let's dig into the model building!__ First, we install the required model dependencies."
]
},
{
Expand All @@ -39,7 +39,7 @@
},
"outputs": [],
"source": [
"!pip install -q torch transformers transformers accelerate bitsandbytes langchain sentence-transformers faiss-cpu openpyxl pacmap datasets langchain-community ragatouille"
"!pip install -q torch transformers accelerate bitsandbytes langchain sentence-transformers faiss-cpu openpyxl pacmap datasets langchain-community ragatouille"
]
},
{
Expand Down Expand Up @@ -272,7 +272,7 @@
"👀 As you can see, __the chunk lengths are not aligned with our limit of 512 tokens__, and some documents are above the limit, thus some part of them will be lost in truncation!\n",
" - So we should change the `RecursiveCharacterTextSplitter` class to count length in number of tokens instead of number of characters.\n",
" - Then we can choose a specific chunk size, here we would choose a lower threshold than 512:\n",
" - smaller documents could allow the split to focus more on specific ideas.\n",
" - Smaller documents could allow the split to focus more on specific ideas.\n",
" - But too small chunks would split sentences in half, thus losing meaning again: the proper tuning is a matter of balance."
]
},
Expand Down
14 changes: 7 additions & 7 deletions notebooks/en/rag_evaluation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"outputs": [],
"source": [
"!pip install -q torch transformers transformers langchain sentence-transformers tqdm openpyxl openai pandas datasets langchain-community ragatouille"
"!pip install -q torch transformers langchain sentence-transformers tqdm openpyxl openai pandas datasets langchain-community ragatouille"
]
},
{
Expand Down Expand Up @@ -366,7 +366,7 @@
"\n",
"We thus build critique agents that will rate each question on several criteria, given in [this paper](https://huggingface.co/papers/2312.10003):\n",
"- **Groundedness:** can the question be answered from the given context?\n",
"- **Relevance:** is the question relevant to users? For instance, `\"What is the date when transformers 4.29.1 was released?\"` is not relevant for ML practicioners.\n",
"- **Relevance:** is the question relevant to users? For instance, `\"What is the date when transformers 4.29.1 was released?\"` is not relevant for ML practitioners.\n",
"\n",
"One last failure case we've noticed is when a function is tailored for the particular setting where the question was generated, but undecipherable by itself, like `\"What is the name of the function used in this guide?\"`.\n",
"We also build a critique agent for this criteria:\n",
Expand Down Expand Up @@ -426,12 +426,12 @@
"\n",
"question_standalone_critique_prompt = \"\"\"\n",
"You will be given a question.\n",
"Your task is to provide a 'total rating' representing how context-independant this question is.\n",
"Your task is to provide a 'total rating' representing how context-independent this question is.\n",
"Give your answer on a scale of 1 to 5, where 1 means that the question depends on additional information to be understood, and 5 means that the question makes sense by itself.\n",
"For instance, if the question refers to a particular setting, like 'in the context' or 'in the document', the rating must be 1.\n",
"The questions can contain obscure technical nouns or acronyms like Gradio, Hub, Hugging Face or Space and still be a 5: it must simply be clear to an operator with access to documentation what the question is about.\n",
"\n",
"For instance, \"What is the name of the checkpoint from which the ViT model is imported?\" should receive a 1, since there is an implicit mention of a context, thus the question is not independant from the context.\n",
"For instance, \"What is the name of the checkpoint from which the ViT model is imported?\" should receive a 1, since there is an implicit mention of a context, thus the question is not independent from the context.\n",
"\n",
"Provide your answer as follows:\n",
"\n",
Expand Down Expand Up @@ -804,7 +804,7 @@
"source": [
"Now our synthetic evaluation dataset is complete! We can evaluate different RAG systems on this evaluation dataset.\n",
"\n",
"We have generated only a few QA couples here to reduce time and cost. But let's kick start the next part by loading a pre-generated dataset:"
"We have generated only a few QA couples here to reduce time and cost. But let's kickstart the next part by loading a pre-generated dataset:"
]
},
{
Expand Down Expand Up @@ -1123,7 +1123,7 @@
"source": [
"# 3. Benchmarking the RAG system\n",
"\n",
"The RAG system and the evaluation datasets are now ready. The last step is to judge the RAG system's output on this evlauation dataset.\n",
"The RAG system and the evaluation datasets are now ready. The last step is to judge the RAG system's output on this evaluation dataset.\n",
"\n",
"To this end, __we setup a judge agent__. ⚖️🤖\n",
"\n",
Expand Down Expand Up @@ -1427,7 +1427,7 @@
"## Example results\n",
"\n",
"Let us load the results that I obtained by tweaking the different options available in this notebook.\n",
"For more detail on why these options could work on not, see the notebook on [advanced_RAG](advanced_rag).\n",
"For more detail on why these options could work or not, see the notebook on [advanced_RAG](advanced_rag).\n",
"\n",
"As you can see in the graph below, some tweaks do not bring any improvement, some give huge performance boosts.\n",
"\n",
Expand Down

0 comments on commit 62c17d8

Please sign in to comment.