Downloads · 30 days
15
21% of all-time downloads
Shoriful025/legal-nli-roberta-base
legal-nli-roberta-base is a machine learning model from Shoriful025. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
The legal-nli-roberta-base model is a fine-tuned RoBERTa-Base model specialized in Legal Natural Language Inference (NLI). Its purpose is to analyze the logical relationship between two pieces of text from legal docum…
Downloads · 30 days
15
21% of all-time downloads
All-time downloads
72
Public
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md3.8 KB · 56%
From the Hugging Face model README
The legal-nli-roberta-base model is a fine-tuned RoBERTa-Base model specialized in Legal Natural Language Inference (NLI). Its purpose is to analyze the logical relationship between two pieces of text from legal documents (e.g., a court ruling and a proposed amendment, or a contract clause and a statement of fact). It classifies the relationship into one of three standard NLI categories: Entailment, Contradiction, or Neutral.
RobertaForSequenceClassification) on text pairs.[CLS] token is passed to a classification head.max_position_embeddings=514). Long premises (e.g., entire contract sections) must be truncated, leading to potential loss of critical information.To analyze the relationship between a legal premise and a hypothesis:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
model_name = "YourOrg/legal-nli-roberta-base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Define Premise and Hypothesis
premise = "The supplier is obligated to deliver all specified goods no later than December 31, 2025, provided that the initial payment is received by October 1st."
hypothesis = "The supplier must deliver the goods by December 31, 2025, regardless of the payment date."
# Encode the text pair
encoded_input = tokenizer(
premise,
hypothesis,
truncation=True,
padding=True,
return_tensors="pt"
)
# Inference
with torch.no_grad():
outputs = model(**encoded_input)
logits = outputs.logits
# Get the predicted label
predicted_class_id = logits.argmax().item()
predicted_label = model.config.id2label[predicted_class_id]
print(f"Premise: {premise[:50]}...")
print(f"Hypothesis: {hypothesis}")
print(f"NLI Relationship: **{predicted_label}**")
# Expected Output: Contradiction (due to the "provided that" condition)