Join the conversation

Join the community of Machine Learners and AI enthusiasts.

Sign Up
m-ricΒ 
posted an update Oct 1
Post
1275
𝗔𝗱𝗱 π˜€π—Όπ˜‚π—Ώπ—°π—² π—΅π—Άπ—΄π—΅π—Ήπ—Άπ—΄π—΅π˜π—Άπ—»π—΄ π˜π—Ό π˜†π—Όπ˜‚π—Ώ π—₯π—”π—š π˜€π˜†π˜€π˜π—²π—Ί! πŸ“„πŸ’‘

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! πŸš€
In this post