πŸ‡·πŸ‡Ό Mbaza Legal AI Model

Multilingual Legal Assistant for Rwandan Laws - Supporting Kinyarwanda, English, and French.

Model Description

This model provides intelligent legal assistance for Rwandan laws, punishments, and legal procedures. It uses semantic search with sentence embeddings to match user queries with relevant legal articles and punishment information.

Key Features

  • Multilingual Support: Kinyarwanda, English, and French
  • Greeting Detection: Natural conversation in multiple languages
  • Legal Article Retrieval: Semantic search across Rwandan legal code
  • Punishment Information: Detailed penalty and sentencing information
  • Context Tracking: Maintains conversation history

Technical Details

  • Base Model: sentence-transformers/all-MiniLM-L6-v2
  • Embedding Dimension: 384
  • Similarity Metric: Cosine similarity
  • Framework: PyTorch + SentenceTransformers

Usage

Via Hugging Face Inference API

import requests

API_URL = "https://api-inference.huggingface.co/models/mugwaneza/mbaza-model"
headers = {"Authorization": f"Bearer {YOUR_HF_TOKEN}"}

def query(prompt):
    response = requests.post(API_URL, headers=headers, json={"inputs": [prompt]})
    return response.json()

# Example usage
result = query("Ibihano by'ubujura ni ibihe?")
print(result["text"])

Via Python Client

from huggingface_hub import InferenceClient

client = InferenceClient(token=YOUR_HF_TOKEN)

response = client.post(
    "mugwaneza/mbaza-model",
    json={"inputs": ["Kwinjira aho umuntu atuye bitemewe namategeko"]}
)
print(response)

Via cURL

curl -X POST \
  -H "Authorization: Bearer YOUR_HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"inputs":["Mwaramutse neza"]}' \
  https://api-inference.huggingface.co/models/mugwaneza/mbaza-model

For Mobile Apps (React Native, Flutter, Swift)

// React Native / JavaScript
const API_URL = "https://api-inference.huggingface.co/models/mugwaneza/mbaza-model";
const HF_TOKEN = "your_token_here";

async function queryLegalAI(prompt) {
  const response = await fetch(API_URL, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${HF_TOKEN}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({ inputs: [prompt] })
  });
  
  return await response.json();
}

// Usage
const result = await queryLegalAI("What is the punishment for theft?");
console.log(result.text);

For Laravel Backend

<?php

namespace App\Services;

use Illuminate\Support\Facades\Http;

class MbazaLegalAI
{
    protected $apiUrl = 'https://api-inference.huggingface.co/models/mugwaneza/mbaza-model';
    protected $token;
    
    public function __construct()
    {
        $this->token = config('services.huggingface.token');
    }
    
    public function query($prompt, $userId = 'web_user')
    {
        $response = Http::withHeaders([
            'Authorization' => "Bearer {$this->token}",
            'Content-Type' => 'application/json'
        ])->post($this->apiUrl, [
            'inputs' => [$prompt, $userId]
        ]);
        
        return $response->json();
    }
}

// Usage in Controller
$ai = new MbazaLegalAI();
$result = $ai->query("Ibihano by'ubujura ni ibihe?");
return response()->json($result);

Example Queries

Greetings (Multilingual)

# Kinyarwanda
query("Mwaramutse neza")
# Response: Mwaramutse neza, amakuru yawe?

# English
query("Good morning")
# Response: Good morning, how can I help you with legal matters?

# French
query("Bonjour")
# Response: Bonjour, comment puis-je vous aider?

Legal Questions

# Kinyarwanda
query("Ibihano by'ubujura ni ibihe?")
# Returns: Punishment information for theft

# English
query("What are the laws about corruption in Rwanda?")
# Returns: Relevant legal articles on corruption

# Mixed
query("Kwinjira aho umuntu atuye bitemewe namategeko")
# Returns: Laws about trespassing and unauthorized entry

Punishment Queries

query("Igihano cy'umuntu wakubise undi")
# Returns: Punishment for assault

query("What is the penalty for fraud?")
# Returns: Detailed penalty information

Response Format

{
  "text": "Main response text (formatted for display)",
  "intent": "greeting|law|punishment|fallback",
  "laws": [
    {
      "article": "Article 166",
      "description": "...",
      "punishment": "...",
      "similarity": 0.85
    }
  ],
  "punishments": [
    {
      "crime": "Theft",
      "category": "Property crimes",
      "penalty": "..."
    }
  ]
}

Datasets

The model uses the following datasets:

  1. Legal Code Dataset (dataset-all.csv)

    • Rwandan laws and articles
    • Descriptions in Kinyarwanda, English, and French
    • Article numbers, chapters, and categories
  2. Penal Code (penal_code.csv)

    • Crime categories
    • Punishment details
    • Sentencing guidelines
  3. Greetings (greetings.csv)

    • Multilingual greetings and responses
    • Conversational patterns

Model Files

  • inference.py - Main inference endpoint
  • assistant.py - Core assistant logic
  • retriever.py - Semantic search and embedding management
  • config.py - Configuration and utilities
  • law_embeddings.npy - Precomputed embeddings (384-dim vectors)
  • law_meta.json - Metadata for legal articles
  • conversation_contexts.json - Context tracking storage

Installation (Self-Hosted)

# Clone the model repository
git clone https://huggingface.co/mugwaneza/mbaza-model
cd mbaza-model

# Install dependencies
pip install -r requirements.txt

# Test locally
python inference.py

API Limits

  • Free Tier: ~30,000 requests/month
  • Rate Limiting: ~100 requests/hour (burst)
  • Cold Start: First request may take 10-30 seconds
  • Warm: Subsequent requests ~1-3 seconds

For production with higher limits, consider:

  1. Upgrading to Hugging Face PRO ($9/month)
  2. Self-hosting with this model
  3. Using dedicated inference endpoints

License

MIT License - See LICENSE file for details

Citation

@misc{mbaza-legal-ai,
  author = {Mugwaneza Manzi},
  title = {Mbaza Legal AI: Multilingual Legal Assistant for Rwanda},
  year = {2025},
  publisher = {Hugging Face},
  url = {https://huggingface.co/mugwaneza/mbaza-model}
}

Related Resources

Contact

For questions, issues, or collaboration:


Note: This model is designed for informational purposes. Always consult with a qualified legal professional for official legal advice.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support