How to Get Started with the STRONG Model for Legal Opinion Summarization

Mar 21, 2024 | Educational

The STRONG model is an innovative tool designed for summarizing long legal opinions from CanLII. It utilizes an advanced LED-based architecture, allowing users to generate structure-controllable summaries. This blog post will guide you through the steps required to set up and run the STRONG model, complete with troubleshooting tips for any issues you might encounter along the way.

What You’ll Need

  • Python installed on your system
  • Access to the terminal/command prompt
  • Basic familiarity with Python libraries

Installation

Before diving into the code, you need to install the necessary libraries. Run the following command:

pip install -U transformers

Understanding the Input Structure

To properly run the STRONG model, the input must consist of two primary components:

  1. Summary Structure Prompt: This involves concatenating a series of IRC structure labels, such as Non_IRC, Issue, Reason, Conclusion. Use “ ” (two spaces) as a separator.
  2. Legal Opinion Text: Following the special token ==, you should input the text of the legal opinion you want summarized.

Running the Model on CPU

Here’s a simple code snippet you can use to run the model on a CPU:

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("allenailed-base-16384")
model = AutoModelForCausalLM.from_pretrained("yznlpSTRONG-LED")

input_text = "Non_IRC  Issue  Conclusion == Legal Case Content"
input_ids = tokenizer(input_text, return_tensors='pt')
outputs = model.generate(**input_ids, max_length=256, num_beams=4, length_penalty=2.0)
print(tokenizer.decode(outputs[0]))

Running the Model on Multi-GPU Setup

If you have access to a multi-GPU setup, the following snippet will help you utilize that environment:

# pip install accelerate
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("allenailed-base-16384")
model = AutoModelForCausalLM.from_pretrained("yznlpSTRONG-LED", device_map="auto")

input_text = "Non_IRC  Issue  Conclusion == Legal Case Content"
input_ids = tokenizer(input_text, return_tensors='pt')
outputs = model.generate(**input_ids, max_length=256, num_beams=4, length_penalty=2.0)
print(tokenizer.decode(outputs[0]))

Understanding the Code: An Analogy

Think of running the STRONG model like organizing a legal conference:

  • The Summary Structure Prompt is like an agenda for your conference, detailing the topics to be covered – in this case, Non_IRC, Issue, Reason, Conclusion.
  • The Legal Opinion Text is the main content of your conference, much like the detailed discussions you will have under each agenda point.
  • When you execute the code, it’s like presenting the conference material: the structure helps guide the audience (the model), and the legal content provides the actual discussion.

Troubleshooting Tips

If you encounter issues while using the STRONG model, here are some troubleshooting ideas:

  • Module Not Found Error: Ensure that you’ve installed the transformers library correctly using the given pip install command.
  • CUDA Errors: If running on a GPU, ensure that your NVIDIA drivers and PyTorch library are correctly installed and compatible.
  • Unexpected Outputs: Double-check that your input format follows the defined structure—incorrectly formatted input can lead to nonsensical summaries.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

With STRONG, you have the power to distill complex legal opinions into concise summaries, enhancing your ability to comprehend and relay intricate information quickly. The structure-controllable feature provides an added layer of customization that can cater to various requirements.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox