Downloads · 30 days
7
21% of all-time downloads
FelipeAg5/mistral-7b-french-legal-qa
mistral-7b-french-legal-qa is a text generation model from FelipeAg5. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
This model is a fine-tuned version of mistralai/Mistral-7B-Instruct-v0.3 on a French legal question-answering dataset using LoRA (Low-Rank Adaptation).
Downloads · 30 days
7
21% of all-time downloads
All-time downloads
34
Public
Repo size
508 MB
Likes
0
Public
Click a slice to open those files.
.safetensors503 MB · 73%
From the Hugging Face model README
This model is a fine-tuned version of mistralai/Mistral-7B-Instruct-v0.3 on a French legal question-answering dataset using LoRA (Low-Rank Adaptation).
Nahla-yasmine/mistral-7b-french-legal-qamistralai/Mistral-7B-Instruct-v0.3This is a LoRA fine-tuned adapter for Mistral-7B-Instruct, trained on a curated French legal question-answering dataset focused on data protection and privacy laws (e.g., Law 18-07 in Algeria).
The goal is to assist users in understanding legal rights, definitions, and procedures related to personal data protection.
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("Nahla-yasmine/mistral-7b-french-legal-qa")
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"mistralai/Mistral-7B-Instruct-v0.3",
torch_dtype=torch.bfloat16,
device_map="auto"
)
# Load LoRA weights
model = PeftModel.from_pretrained(base_model, "Nahla-yasmine/mistral-7b-french-legal-qa")
# Generate response
def ask_question(question):
prompt = f"<s>[INST] {question} [/INST]"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=200,
temperature=0.3,
top_p=0.9,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response.split("[/INST]")[-1].strip()
# Example usage
question = "Qu'est-ce qu'une donnée à caractère personnel ?"
answer = ask_question(question)
print(f"Question: {question}")
print(f"Answer: {answer}")
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch
# Configure quantization
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16
)
# Load with quantization
tokenizer = AutoTokenizer.from_pretrained("Nahla-yasmine/mistral-7b-french-legal-qa")
base_model = AutoModelForCausalLM.from_pretrained(
"mistralai/Mistral-7B-Instruct-v0.3",
quantization_config=bnb_config,
device_map="auto"
)
model = PeftModel.from_pretrained(base_model, "Nahla-yasmine/mistral-7b-french-legal-qa")
The model can answer various French legal questions such as:
This model is designed for answering questions about French legal topics, particularly data protection and privacy law. It should be used as a helpful assistant but always verify important legal information with qualified professionals.
If you use this model, please cite the original Mistral paper:
@article{jiang2023mistral,
title={Mistral 7B},
author={Jiang, Albert Q and Sablayrolles, Alexandre and Mensch, Arthur and Bamford, Chris and Chaplot, Devendra Singh and Casas, Diego de las and Bressand, Florian and Lengyel, Gianna and Lample, Guillaume and Saulnier, Lucile and others},
journal={arXiv preprint arXiv:2310.06825},
year={2023}
}
For questions about this fine-tuned model, please open an issue in this repository.