A Two-Stage Architecture for NDA Analysis: LLM-based Segmentation and Transformer-based Clause Classification

This paper proposes a two-stage architecture combining LLaMA-3.1-8B-Instruct for NDA segmentation and a fine-tuned Legal-Roberta-Large for clause classification, achieving high precision (ROUGE F1 of 0.95 and weighted F1 of 0.85) to automate the analysis of complex Non-Disclosure Agreements.

Ana Begnini, Matheus Vicente, Leonardo Souza

Published Thu, 12 Ma
📖 5 min read🧠 Deep dive

Imagine you are a lawyer, but instead of reviewing one contract a day, you are drowning in a sea of Non-Disclosure Agreements (NDAs). These are the legal "handshakes" companies sign to promise they won't spill each other's secrets.

The problem? Every company writes these agreements differently. Some are short and sweet; others are 50 pages of dense, confusing legal jargon with no clear structure. Reading them manually is slow, boring, and easy to mess up. You might miss a tiny clause that says, "Oh, by the way, we own your idea now," buried in paragraph 42.

This paper proposes a two-stage robot team to do the heavy lifting for you. Think of it as a high-tech assembly line for legal documents.

🏗️ The Two-Stage Assembly Line

The system is built like a relay race with two runners: The Segmenter and The Classifier.

Stage 1: The Segmenter (The "Book Binder")

The Problem: An NDA is like a giant, uncut block of marble. It's all one big chunk of text. You can't analyze it until you chop it into manageable pieces (clauses). But legal text is messy; sometimes a clause is one sentence, sometimes it's three paragraphs, and sometimes the formatting is a nightmare.

The Solution: The team uses a super-smart AI called LLaMA (think of it as a very well-read, fast-reading librarian).

  • How it works: You feed the whole NDA to the librarian. The librarian reads the whole thing and says, "Okay, here is Clause 1, here is Clause 2, here is Clause 3..."
  • The Magic Trick: The researchers taught this librarian to ignore the messy formatting (like weird columns or tables) and focus purely on the meaning to find where one idea ends and the next begins.
  • The Result: It's incredibly accurate. If the original document had 100 clauses, the robot found 95 of them perfectly and didn't miss the important details. It's like a master chef slicing a loaf of bread so perfectly that every slice is exactly the right size, even if the loaf was shaped weirdly.

Stage 2: The Classifier (The "Labeling Expert")

The Problem: Now that you have the individual clauses, you need to know what kind of clause they are. Is this the "Confidentiality" clause? The "Governing Law" clause? The "Who gets fired if we break the rules" clause?

The Solution: The team uses a specialized AI called Legal-Roberta (think of this as a legal scholar who has read thousands of contracts and memorized the patterns).

  • How it works: The Segmenter hands the chopped-up clauses to the Scholar. The Scholar reads a clause and shouts, "This is a Confidentiality clause!" or "This is a Termination clause!"
  • The Challenge: Some clauses are tricky. One paragraph might be about both "Confidentiality" and "Liability." It's a multi-label problem (like a song that is both "Rock" and "Jazz"). Also, some types of clauses are rare (like "Competition Rights"), making it hard for the robot to learn them.
  • The Result: The Scholar is very good at spotting the common clauses (getting about 85% accuracy overall). It's like a seasoned detective who can instantly spot the most common types of clues, even if they sometimes miss the rare, obscure ones.

🧪 How Did They Test It?

The researchers didn't just guess; they put the system through a rigorous exam.

  1. The Dataset: They used 322 real NDAs from a public database. These were messy, real-world documents from different companies, not just clean, perfect examples.
  2. The "Needle in a Haystack" Check: To make sure the Segmenter didn't just guess the right number of clauses but actually got the right text, they used a special math algorithm (Needleman-Wunsch). Imagine trying to match two slightly different versions of a story; this algorithm aligns them word-for-word to see how much they match.
  3. The Score:
    • Segmentation: The robot got a 95% score. It basically cut the documents perfectly.
    • Classification: The robot got an 85% score on the most common clauses. It's not perfect yet (because legal language is tricky and some clauses are rare), but it's good enough to save lawyers hours of work.

🚀 Why Does This Matter?

Currently, lawyers spend hours reading these documents, risking burnout and human error.

  • Before: A lawyer reads a 30-page NDA, squinting at the screen, hoping they don't miss a hidden trap.
  • After: The robot reads the 30 pages in seconds, chops it up, and hands the lawyer a neat list: "Here are the 14 clauses. Clause 3 is about money, Clause 7 is about secrecy, and Clause 12 is about who owns the IP. You just need to double-check these three."

🔮 What's Next?

The authors admit the system isn't perfect yet. It struggles a bit with the rare, weird clauses because there weren't enough examples to teach it.

  • Future Plan: They want to teach the robot to not just find and label the clauses, but to rewrite them. Imagine a robot that says, "Hey, this clause is too vague. Here is a better, safer version of it."

In a nutshell: This paper builds a smart assistant that turns a chaotic pile of legal paperwork into a clean, organized, and labeled file, letting human lawyers focus on the big decisions instead of the boring reading.