This repository hosts the uOttawa model developed for Subtask B (Legal Natural Language Inference) in the LegalLens-2024 shared task. The task focuses on classifying relationships between legal texts, such as determining if a premise (e.g., a summary of a legal complaint) entails, contradicts, or is neutral with respect to a hypothesis (e.g., an online review).
-
Model Type: Transformer-based model combined with a Convolutional Neural Network (CNN)
-
Framework: PyTorch, Transformers library
-
Training Data: LegalLensNLI dataset provided by the LegalLens-2024 organizers
-
Architecture: Integration of RoBERTa (ynie/roberta-large-snli_mnli_fever_anli_R1_R2_R3-nli) with a custom CNN for keyword pattern detection
-
Use Case: Classifying relationships between legal documents for applications like legal case matching and automated reasoning
-
RoBERTa model: Responsible for capturing contextual information from the input text.
-
CNN model: Used for keyword detection, including an embedding layer and three convolutional layers with filter sizes (2, 3, 4).
-
Fully connected layer: Combines the outputs from RoBERTa and CNN for the final classification.
To use this model, clone this repository and make sure to have the following installed:
1pip install torch
2pip install transformers
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
3# Load the model and tokenizer
4model = AutoModelForSequenceClassification.from_pretrained("nimamegh/roberta_cnn_legal")
5tokenizer = AutoTokenizer.from_pretrained("nimamegh/roberta_cnn_legal")
6
7# Example inputs
8premise = "The cat is on the mat."
9hypothesis = "The animal is on the mat."
10inputs = tokenizer(premise, hypothesis, return_tensors='pt')
11
12# Get predictions
13outputs = model(**inputs)
14predictions = outputs.logits.argmax(dim=-1)
15
16# Print the prediction result
17print("Predicted class:", predictions.item())
18
19# Interpretation (optional)
20label_map = {0: "Entailment", 1: "Neutral", 2: "Contradiction"}
21print("Result:", label_map[predictions.item()])
-
Learning Rate: 2e-5
-
Batch Size: 4 (train and evaluation)
-
Number of Epochs: 20
-
Weight Decay: 0.01
-
Optimizer: AdamW
-
Trainer Class: Used for fine-tuning with early stopping and warmup steps
The model was evaluated using an F1-score across multiple domains in the validation set:
-
Performance on Hidden Test Set: F1-score of 0.724, achieving 5th place in the LegalLens-2024 competition.
-
Comparison:
-
Falcon 7B: 81.02% (average across domains)
-
RoBERTa base: 71.02% (average)
-
uOttawa Model: 88.6% (average on validation)
1@misc{meghdadi2024uottawalegallens2024transformerbasedclassification,
2 title={uOttawa at LegalLens-2024: Transformer-based Classification Experiments},
3 author={Nima Meghdadi and Diana Inkpen},
4 year={2024},
5 eprint={2410.21139},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2410.21139},
9}