Views
No views yet
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.1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "YourOrg/legal-nli-roberta-base"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Define Premise and Hypothesis
10premise = "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."
11hypothesis = "The supplier must deliver the goods by December 31, 2025, regardless of the payment date."
12
13# Encode the text pair
14encoded_input = tokenizer(
15 premise,
16 hypothesis,
17 truncation=True,
18 padding=True,
19 return_tensors="pt"
20)
21
22# Inference
23with torch.no_grad():
24 outputs = model(**encoded_input)
25 logits = outputs.logits
26
27# Get the predicted label
28predicted_class_id = logits.argmax().item()
29predicted_label = model.config.id2label[predicted_class_id]
30
31print(f"Premise: {premise[:50]}...")
32print(f"Hypothesis: {hypothesis}")
33print(f"NLI Relationship: **{predicted_label}**")
34# Expected Output: Contradiction (due to the "provided that" condition)