Grounded Summarization Using Command R
Note: we are in the process of updating the links in this notebook. If a link doesn’t work, please open an issue and we’ll rectify it ASAP. Thanks for your understanding!
Links to add:
- Cell 1: long-form, grounded summarisation blog post
- Section 4: to text-rank method (context filtering)
This notebook provides the code to produce the outputs described in this blog post.
1. Setup
Aside: define utils
2. Out-of-the-box summarization with Command-R
First, let’s see Command-R’s out-of-the-box performance. It’s a 128k-context model, so we can pass the full IMF report in a single call. We replicate the exact instructions from the original tweet (correcting for a minor typo) for enabling fair comparisons.
3. Introduce citations to the summary for grounding
When summarizing long documents, introducing citations is one simple method for checking the factuality of the summary without needing to read the full document.
We’ve trained Command-R to introduce citations whenever prompted by our grounded generations instructions. Triggering this grounded mode is straightforward. Starting from the previous snippet, we only need to make two changes:
- Pass our text to the
documents
argument - Pass our instructions to the
message
argument
For more information on how to enable grounded generation via our co.chat
API, please refer to our documentation.
Finally, note that we chunk the IMF report into multiple documents before passing them to co.chat
. This isn’t necessary (co.chat
annotates citations at the character level), but allows for more human-readable citations.
Let’s display the citations inside our answer:
We can now visualise which section of the answer is based on which passage in the main text. Verifying factuality is straightforward: pick a section and verify that the relevant information is contained in the cited chunk.
For instance, let’s verify the statement
by checking its chunk:
Seems convincing! By repeating such checks, it’s straightforward to build trust in your summaries.
4. Reduce the cost of summarization calls
Even though Command-R is an efficient, light-weight model, for some applications we may accept trading off some summarization quality for lower costs. To do this, we must reduce the amount of tokens sent to the model — but how do we select the most relevant bits?
We have a whole notebook dedicated to methods for reducing context length. Here, we call our ‘text-rank’ method to select maximally central chunks in a graph based on the chunk-to-chunk similarties. For more detail, please refer to this cookbook.
The summary is looking convincing! In practice, the trade-off between cost-efficiency and performance should be considered carefully.