Post
1272
ππ±π± ππΌππΏπ°π² π΅πΆπ΄π΅πΉπΆπ΄π΅ππΆπ»π΄ ππΌ ππΌππΏ π₯ππ πππππ²πΊ! ππ‘
RAG systems are supposed to make your LLM's answer more trustworthy, by inserting in the prompt some supporting documents from a knowledge base : we say that we're "adding some context".
π But if you don't know which part of the answer has been generated based on which input tokens, it's hard to tell wether it was effectively grounded in the context knowledge or not!
π€ I've been working on the question: is it possible to add notes to the answer linking to which part of the context they're generated from?
And I've found a great solution: a great technique called Layer-wise Relevance Propagation (LRP), showcased in a paper at ICML `24 by Reduan Achtibat et al allows, allows to precisely score how important each input token was in generating your output! They've made it into a library called LXT.
π For each generated output token, LXT gives you attribution scores for each input token.
βοΈ So I've worked a bit more on aggregating these scores into meaningful spans between successive input and output tokens, and I finally obtained my desired result: RAG with source highlighting!
Try the demo here π m-ric/rag_highlights
Caveats:
- It slows down generation (for now quite a lot, could hopefully be reduced a lot)
- For now it supports only specific models: Llama models and Mixtral
If there's enough interest in this solution, I can improve it further and spin it off into a specific library for RAG! π
RAG systems are supposed to make your LLM's answer more trustworthy, by inserting in the prompt some supporting documents from a knowledge base : we say that we're "adding some context".
π But if you don't know which part of the answer has been generated based on which input tokens, it's hard to tell wether it was effectively grounded in the context knowledge or not!
π€ I've been working on the question: is it possible to add notes to the answer linking to which part of the context they're generated from?
And I've found a great solution: a great technique called Layer-wise Relevance Propagation (LRP), showcased in a paper at ICML `24 by Reduan Achtibat et al allows, allows to precisely score how important each input token was in generating your output! They've made it into a library called LXT.
π For each generated output token, LXT gives you attribution scores for each input token.
βοΈ So I've worked a bit more on aggregating these scores into meaningful spans between successive input and output tokens, and I finally obtained my desired result: RAG with source highlighting!
Try the demo here π m-ric/rag_highlights
Caveats:
- It slows down generation (for now quite a lot, could hopefully be reduced a lot)
- For now it supports only specific models: Llama models and Mixtral
If there's enough interest in this solution, I can improve it further and spin it off into a specific library for RAG! π