--- tags: - legal - bert - classification - kenya-constitution - legal-ai license: apache-2.0 language: en library_name: transformers datasets: kenya-constitution-2010 model_name: legalbert_finetuned widget: - text: "What are the fundamental rights under the Kenyan Constitution?" --- # 📜 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](https://huggingface.co/nlpaueb/legal-bert-base-uncased) - **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**: ```python 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.