Views
No views yet
| Metric | Base Model | Fine-tuned Model | Improvement |
|---|---|---|---|
| Validation Loss | 2.4934 | 0.4106 | 83.53% |
| Perplexity | 12.1026 | 1.5077 | 87.54% |
| Epoch | Training Loss | Validation Loss |
|---|---|---|
| 1 | 0.6224 | 0.5546 |
| 2 | 0.5209 | 0.4721 |
| 3 | 0.4833 | 0.4408 |
| 4 | 0.4725 | 0.4217 |
| 5 | 0.4477 | 0.4146 |
distilbert-base-uncased1learning_rate = 5e-5
2batch_size = 16
3epochs = 5
4mlm_probability = 0.15
5weight_decay = 0.01
6warmup_steps = 5001pip install transformers torch
2from transformers import AutoModelForMaskedLM, AutoTokenizer
3
4model = AutoModelForMaskedLM.from_pretrained("Nahla-yasmine/legal-distilbert")
5tokenizer = AutoTokenizer.from_pretrained("Nahla-yasmine/legal-distilbert")
6
7# Masked language prediction
8text = "The court found the defendant [MASK] of all charges."
9inputs = tokenizer(text, return_tensors="pt")
10outputs = model(**inputs)1
2def predict_masked_text(text, model, tokenizer, num_predictions=5):
3 inputs = tokenizer(text, return_tensors="pt")
4 with torch.no_grad():
5 outputs = model(**inputs)
6
7 mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]
8 logits = outputs.logits[0, mask_token_index, :]
9 top_tokens = torch.topk(logits, num_predictions, dim=1).indices[0].tolist()
10
11 return [tokenizer.decode([token]) for token in top_tokens]
12
13# Example usage
14predictions = predict_masked_text(
15 "The contract was declared [MASK] due to fraudulent activities.",
16 model, tokenizer
17)
18print(predictions) # ['void', 'invalid', 'bankrupt', 'terminated', 'cancelled']
19- Legal document analysis and processing
- Legal text completion and generation
- Law education and research tools
- Legal AI assistants
- Document review automation
- Legal terminology understanding- English language only
- Maximum sequence length: 512 tokens
- Training data up to 2022