A text summarization tool generating irrelevant sentences for legal documents could suffer from improper weighting of key legal terms, lack of domain-specific fine-tuning, over-aggressive truncation, or ineffective importance scoring.
Here is the code snippet you can refer to:

In the above code we are using the following key points:
- Using a General-Purpose Model Instead of a Legal-Specific Model → Switched to "nsi319/legal-led-base-16384", fine-tuned for legal text.
- Loss of Key Legal Terms Due to Improper Truncation → Adjusted max_length and min_length to retain relevant content.
- Irrelevance Due to Poor Importance Scoring → Disabled do_sample to ensure deterministic, legally precise summarization.
- Contextual Meaning Loss → Ensured long-context attention with a legal-domain model.
- Lack of Legal Terminology Awareness → A specialized model understands legal-specific wording and concepts.
Hence, fixing irrelevant outputs in a legal document summarization tool requires using a fine-tuned legal model, optimizing truncation limits, improving term preservation, and refining importance weighting to ensure accuracy and relevance.