πŸ“œ LegalBERT Fine-Tuned for Kenya Constitution 2010

πŸ“ Model Description

This model is a fine-tuned LegalBERT for legal text classification based on the Kenya Constitution 2010.
It is designed to classify constitutional provisions and assist in legal research by analyzing legal texts with high precision.

πŸ—οΈ Model Details

  • Base Model: LegalBERT
  • Fine-Tuned For: Kenyan constitutional law classification
  • Architecture: BertForSequenceClassification
  • Number of Layers: 6
  • Hidden Size: 512
  • Attention Heads: 8
  • Vocabulary Size: 30,522
  • Max Position Embeddings: 512
  • Dropout Rate: 0.1
  • Transformers Version: 4.48.3

πŸš€ How to Use This Model

You can load and use the model easily with Transformers:

from transformers import BertTokenizer, BertForSequenceClassification

model_name = "CoolCerebralTech/legalbert_finetuned"

# Load tokenizer
tokenizer = BertTokenizer.from_pretrained(model_name)

# Load model
model = BertForSequenceClassification.from_pretrained(model_name)

βš–οΈ Inference: Legal Text Classification
The model predicts legal categories based on input queries.

πŸ”Ή Example: Classifying a Legal Question
import torch

def predict_legal_query(query):
    """Runs inference on a legal query using LegalBERT."""
    inputs = tokenizer(query, return_tensors="pt", truncation=True, padding=True, max_length=512)

    with torch.no_grad():
        outputs = model(**inputs)
        logits = outputs.logits
        predicted_class = torch.argmax(logits, dim=1).item()  # Get highest scoring class

    return predicted_class

# πŸ”Ή User Query
query = "What are the fundamental rights under the Kenyan Constitution?"
prediction = predict_legal_query(query)

# πŸ”Ή Label Mapping (Modify as needed)
label_mapping = {0: "Civil Rights", 1: "Criminal Law", 2: "Property Law", 3: "Other"}
predicted_label = label_mapping.get(prediction, "Unknown")

print(f"πŸ“Œ Query: {query}")
print(f"πŸ”Ή Predicted Legal Category: {predicted_label}")

βœ… Sample Output
πŸ“Œ Query: What are the fundamental rights under the Kenyan Constitution?
πŸ”Ή Predicted Legal Category: Civil Rights

πŸ“Œ Intended Use
Legal Research & Analysis
Kenyan Constitutional Law Classification
Automated Legal Document Processing
⚠️ Limitations & Warnings
This model is fine-tuned on Kenyan constitutional law and may not generalize to other legal systems.
Always consult a qualified legal expert before making legal conclusions.
Downloads last month
1
Safetensors
Model size
35.1M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support