Back to Blog

Summarizing Legal Documents for Different Personas Using AI21 Studio

Yuval Belfer
,
Technical Product Marketing
,
,
May 31, 2024
No items found.

Create your own custom summarizer using AI21 Studio's large language models. This tutorial demonstrates the process on legal documents.

We’ve all experienced reading long, tedious, and boring pieces of text - financial reports, legal documents, or terms and conditions (though, who actually reads those terms and conditions to be honest?).

Imagine a company that employs hundreds of thousands of employees. In today's information overload age, nearly 30% of the workday is spent dealing with documents. There's no surprise here, given that some of these documents are long and convoluted on purpose (did you know that reading through all your privacy policies would take almost a quarter of a year?). Aside from inefficiency, workers may simply refrain from reading some documents (for example, Only 16% of Employees Read Their Employment Contracts Entirely Before Signing!). 

This is where AI-driven summarization tools can be helpful: instead of reading entire documents, which is tedious and time-consuming, users can (ideally) quickly extract relevant information from a text. With large language models, the development of those tools is easier than ever, and you can offer your users a summary that is specifically tailored to their preferences.

Let's take legal documents, for example. Though they are written in English, many people find legal documents to be difficult to comprehend, as if they were actually written in a foreign language. Moreover, the interesting parts of each document may differ depending on the person who reads it, so off-the-shelf summarization tools may be too general or too specific. As an example, let's look at the involved personas:

  1. Lawyers. They are interested in several key points, but legal language and terms are especially relevant to them.
  2. Your average Joe. Doesn’t understand all the legal terms, and really wants to get the gist in simple words.

Using the IRS as our example, we will demonstrate here how to build a simple summarizer for those 2 personas, and discuss which future directions one should consider.

Working with large language models

Large language models naturally follow patterns in input (prompt), and provide coherent completion that follows the same patterns. For that, we want to feed them with several examples in the input ("few-shot prompt"), so they can follow through. The process of creating the correct prompt for your problem is called prompt engineering, and you can read more about it here.

Collecting data

Ideally, you should have a variety of examples to draw from. It is important that those examples represent the actual documents that your summarizer should work on. This means they should be written in the same way as real world documents, and they should be as varied as possible.

Don't have it? No need to worry - large language models generalize exceptionally well, so the results will still be good. In the end, optimal results can always be achieved with proper data - but you can revisit this at a later date.

Summarize for lawyers

If you are summarizing legal documents for lawyers, you should definitely maintain all legal terms from the original document. In this demonstration, we will work on the opening paragraphs of legal letters.

Here is an example of a few-shot prompt:

And the completion:

- The Parties requested an extension of time under §301.9100-3 of the Procedure and Administration Regulations to file an election.
- The Parties are requesting an extension of time to file the Election Statement with respect to Purchaser's acquisition of all the stock of S Corporation Target from Shareholder on Date 1.
- The Parties represented that they are not seeking to alter a return position for which an accuracy-related penalty has been or could be imposed under section 6662.
##

Notes

  • It is wise to try several phrasings for your prompt. You can, for instance, keep it simple and direct by writing:
  • Alternatively, you can take a more elaborate approach, such as:
  • As you can see, we are providing the model with several examples, separated by a stop sequence, which is easily spotted while reading the text. You can read more about stop sequences here.
  • Because this task requires high accuracy, we recommend working at a low temperature. It's best to explore the range of 0.0-0.3, since temperature 0 does tend to produce short summaries. You can read more about temperature here.
  • You can test several options for the prompt in our playground.
  • There is a consistent structure to all the examples in the prompt. This few-shot prompt can be created using the following code (assuming you have the paragraphs and summaries):

Summarize for the average Joe

Despite the fact that there are over 1.3 million lawyers in the United States alone, most people  (still) aren't lawyers and have trouble understanding legal documents. In this case, we probably want the summary to be written in a simple, easy-to-understand manner.

As this task involves both summarizing and simplifying texts, it is inherently more difficult. Thus, we will probably need more "shots" in our few-shot prompt (in this case, we added another example to the prompt).

Here is an example of a few-shot prompt:

Due to the difficulty of this task, this prompt is not sufficient. By adding another example ("shot"), however, we will get much better results. Below you can see the completion:

A corporation asks the government for more time to file a statement related to its financial performance for a specific tax year. The government has granted the request but may check the information provided by the company later.<br>
##

Notes:

  • Like in the previous case, you should try several phrasings for your prompt.
  • You can test several options for the prompt in our playground.
  • Alternatively, you could have summarized for lawyers first, and then simplified the summary (using a different prompt). This method may, however, result in some information being lost.

Summary

In this post, we explore the use-case of summarization.
If you need a simple, off-the-shelf summarizer, be sure to check out our specialized summarization API. However, for more specific use-cases and customization, it’s wise to get closer to the core with the help of large language models, as custom models that are tailored to your specific needs will always get you higher quality results. Click here to learn more.

Related Blogs