aloe-vera commited on
Commit
6a61a18
·
1 Parent(s): 40872fd

add RAG experiment tap

Browse files
Files changed (3) hide show
  1. app.py +101 -3
  2. leaderboard/data/rag_methods_compare.csv +13 -0
  3. src/populate.py +17 -2
app.py CHANGED
@@ -28,7 +28,7 @@ from src.display.utils import (
28
  Precision
29
  )
30
  from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
31
- from src.populate import get_evaluation_queue_df, get_leaderboard_df
32
  from src.submission.submit import add_new_eval
33
  import base64
34
 
@@ -122,6 +122,7 @@ except Exception:
122
 
123
  # LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS, BENCHMARK_COLS)
124
  LEADERBOARD_DF = get_leaderboard_df("leaderboard/data/leaderboard.csv")
 
125
 
126
  # (
127
  # finished_eval_queue_df,
@@ -259,10 +260,107 @@ with demo:
259
 
260
  gr.Code(code_example_chat, language="shell")
261
 
262
- with gr.TabItem("📝 Details", elem_id="llm-benchmark-tab-table", id=2):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  gr.Markdown((Path(__file__).parent / "docs.md").read_text(), elem_classes="markdown-text")
264
 
265
- with gr.TabItem("🚀 Submit Here! ", elem_id="llm-benchmark-tab-table", id=3):
266
  gr.Markdown((Path(__file__).parent / "submit.md").read_text(), elem_classes="markdown-text")
267
 
268
  # with gr.Column():
 
28
  Precision
29
  )
30
  from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
31
+ from src.populate import get_evaluation_queue_df, get_leaderboard_df, get_rag_leaderboard_df
32
  from src.submission.submit import add_new_eval
33
  import base64
34
 
 
122
 
123
  # LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS, BENCHMARK_COLS)
124
  LEADERBOARD_DF = get_leaderboard_df("leaderboard/data/leaderboard.csv")
125
+ RAG_DF = get_rag_leaderboard_df("leaderboard/data/rag_methods_compare.csv")
126
 
127
  # (
128
  # finished_eval_queue_df,
 
260
 
261
  gr.Code(code_example_chat, language="shell")
262
 
263
+
264
+ with gr.TabItem("🧪 RAG Techniques and Hallucinations", elem_id="llm-benchmark-tab-table", id=2):
265
+ rag_techniques_markdown = textwrap.dedent(
266
+ """
267
+ ## Comparison of Different RAG Techniques and Hallucinations
268
+
269
+ Many LLMs can generate fluent answers but still hallucinate facts—especially in RAG settings. This experiment aims to understand how different prompting strategies impact hallucination rates across models. It helps answer: Which prompt format is most reliable? Which models are more sensitive to prompt structure? The goal is to inform better design of RAG pipelines for reducing factual errors in downstream tasks.
270
+
271
+ We presents hallucination rates for various LLMs under three different RAG prompting strategies. Each method delivers the same document context and question, but differs in how the information is structured during the prompt.
272
+
273
+ ### RAG Techniques Evaluated
274
+
275
+ **1. Two-Turn Explicit RAG**
276
+ The document and question are sent in separate user messages:
277
+ ```
278
+ [System]: You are an assistant for question-answering tasks.
279
+ Given the QUESTION and DOCUMENT you must answer the QUESTION using the information in the DOCUMENT.
280
+ You must not offer new information beyond the context provided in the DOCUMENT. Do not add any external knowledge.
281
+ The ANSWER also must not contradict information provided in the DOCUMENT.
282
+ If the DOCUMENT does not contain the facts to answer the QUESTION or you do not know the answer, you truthfully say that you do not know.
283
+ You have access to information provided by the user as DOCUMENT to answer the QUESTION, and nothing else.
284
+ Use three sentences maximum and keep the answer concise.
285
+
286
+ [User]: DOCUMENT: <context>
287
+ [User]: QUESTION: <prompt>
288
+ ```
289
+ This method creates a multi-turn format, which allows the model to treat the context and question independently.
290
+ *Note: This method does not work on Gemma 3 27B due to its restriction on consecutive user messages without an intervening assistant response.*
291
+
292
+ **2. System-Prompt Injection RAG**
293
+ The document is embedded inside the system prompt, and the user sends only the question:
294
+ ```
295
+ [System]: You are an assistant for question-answering tasks.
296
+ Given the QUESTION and DOCUMENT you must answer the QUESTION using the information in the DOCUMENT.
297
+ You must not offer new information beyond the context provided in the DOCUMENT. Do not add any external knowledge.
298
+ The ANSWER also must not contradict information provided in the DOCUMENT.
299
+ If the DOCUMENT does not contain the facts to answer the QUESTION or you do not know the answer, you truthfully say that you do not know.
300
+ You have access to information provided by the user as DOCUMENT to answer the QUESTION, and nothing else.
301
+ Use three sentences maximum and keep the answer concise.
302
+ DOCUMENT: <context>
303
+
304
+ [User]: <prompt>
305
+ ```
306
+ This approach places the grounding context within the model’s instruction space.
307
+
308
+ **3. Single-Turn Concatenated RAG**
309
+ Both the document and question are concatenated in a single user message:
310
+ ```
311
+ [System]: You are an assistant for question-answering tasks.
312
+ Given the QUESTION and DOCUMENT you must answer the QUESTION using the information in the DOCUMENT.
313
+ You must not offer new information beyond the context provided in the DOCUMENT. Do not add any external knowledge.
314
+ The ANSWER also must not contradict information provided in the DOCUMENT.
315
+ If the DOCUMENT does not contain the facts to answer the QUESTION or you do not know the answer, you truthfully say that you do not know.
316
+ You have access to information provided by the user as DOCUMENT to answer the QUESTION, and nothing else.
317
+ Use three sentences maximum and keep the answer concise.
318
+
319
+ [User]:
320
+ DOCUMENT: <context>
321
+ QUESTION: <prompt>
322
+
323
+ ```
324
+ This is the most compact format, sending everything as one prompt input.
325
+
326
+ ### Metric
327
+
328
+ The values in the table indicate the **hallucination rate (%)** of answers deemed factually incorrect or ungrounded given the provided context.
329
+
330
+ """
331
+
332
+
333
+ )
334
+
335
+ gr.Markdown(rag_techniques_markdown, elem_classes="markdown-text")
336
+
337
+
338
+ rag_leaderboard = Leaderboard(
339
+ value=RAG_DF,
340
+ datatype=["markdown", "number", "number", "number"],
341
+ select_columns=SelectColumns(
342
+ default_selection=[
343
+ "Models",
344
+ "Two-Turn Explicit RAG (%)",
345
+ "System-Prompt Injection RAG (%)",
346
+ "Single-Turn Concatenated RAG (%)"
347
+ ],
348
+ cant_deselect=["Models"],
349
+ label="Select RAG Method Columns:",
350
+ ),
351
+ search_columns=["Models"],
352
+ bool_checkboxgroup_label=None,
353
+ interactive=False,
354
+ height=700
355
+ )
356
+
357
+
358
+
359
+
360
+ with gr.TabItem("📝 Details", elem_id="llm-benchmark-tab-table", id=3):
361
  gr.Markdown((Path(__file__).parent / "docs.md").read_text(), elem_classes="markdown-text")
362
 
363
+ with gr.TabItem("🚀 Submit Here! ", elem_id="llm-benchmark-tab-table", id=4):
364
  gr.Markdown((Path(__file__).parent / "submit.md").read_text(), elem_classes="markdown-text")
365
 
366
  # with gr.Column():
leaderboard/data/rag_methods_compare.csv ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Models,rag1,rag2,rag3
2
+ Meta Llama 3.1 8B,11.92,13.09,8.1
3
+ Qwen2.5-VL 7B,13.24,13.39,9.35
4
+ Mistral NeMo,14.42,13.99,10.63
5
+ Meta Llama 4 Maverick,5.72,6.27,3.34
6
+ Meta Llama 4 Scout,6.98,7.17,4.23
7
+ Mistral Small,7.09,7.5,4.74
8
+ Magistral Small,11.87,12.09,8.62
9
+ Gemma 3 27B,-,6.09,3.71
10
+ Meta Llama 3.3 70B,4.65,4.63,2.12
11
+ DeepSeek-V3-0324,7.09,7.71,4.66
12
+ Qwen3-235B-A22B,6.63,6.8,5.04
13
+ DeepSeek-R1-0528,3.58,3.52,2.26
src/populate.py CHANGED
@@ -4,9 +4,24 @@ import os
4
  import pandas as pd
5
 
6
  from src.display.formatting import has_no_nan_values, make_clickable_model
7
- from src.display.utils import AutoEvalColumn, EvalQueueColumn
8
- from src.leaderboard.read_evals import get_raw_eval_results
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def get_leaderboard_df(results_path):
12
  df = pd.read_csv(results_path)
 
4
  import pandas as pd
5
 
6
  from src.display.formatting import has_no_nan_values, make_clickable_model
7
+ from src.display.utils import EvalQueueColumn
8
+ # from src.leaderboard.read_evals import get_raw_eval_results
9
 
10
+ def get_rag_leaderboard_df(csv_path):
11
+ df = pd.read_csv(csv_path)
12
+
13
+ for col in ["rag1", "rag2", "rag3"]:
14
+ df[col] = pd.to_numeric(df[col], errors="coerce").round(2)
15
+
16
+ pretty = {
17
+ "Models": "Models",
18
+ "rag1": "Two-Turn Explicit RAG (%)",
19
+ "rag2": "System-Prompt Injection RAG (%)",
20
+ "rag3": "Single-Turn Concatenated RAG (%)",
21
+ }
22
+ df = df.rename(columns=pretty)
23
+
24
+ return df
25
 
26
  def get_leaderboard_df(results_path):
27
  df = pd.read_csv(results_path)