🚀 インド法律用にファインチューニングされたMistral-7B
Mistral 7B
モデルのファインチューニング版です。Parameter-Efficient Fine-Tuning (PEFT) とQLoRA、LoRA技術を用いて、インド法律に関する理解と応答生成を最適化しています。
✨ 主な機能
このモデルは、インド法律に関するテキストの理解と生成に特化しており、以下のような機能を備えています。
- タスク:法律テキストの理解と生成
- ファインチューニングデータセット:カスタムインド法律コーパス (jizzu/llama2_indian_law_v3)
- ファインチューニング方法:PEFTとQLoRA、LoRAを使用
- パープレキシティスコア:37.32
- リポジトリ:mistralai/Mistral-7B-v0.1
適用範囲外の使用
- 非常に曖昧な法律クエリやインド以外の法律システムには対応できない場合があります。
- パープレキシティの結果から、拡張トレーニングやデータの追加による改善の余地があります。
🚀 クイックスタート
以下のコードを使用して、モデルを始めることができます。
pip install transformers peft torch
を使用し、torchはcudaを使用してください。
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
model_name = "ajay-drew/midtral-7b-indian-law"
tokenizer = AutoTokenizer.from_pretrained(model_name)
base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mixtral-7B-v0.1")
model = PeftModel.from_pretrained(base_model, model_name)
text = "What is the penalty for using forged document? "
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(**inputs, max_length=200)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
メトリクス
モデルのパープレキシティを確認するには、pip install transformers datasets torch
を実行した後、以下のコードを使用してください。cudaサポート付きのtorchを使用すると、メトリクスの確認が高速化されます。
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from datasets import load_dataset
import torch
dataset = load_dataset("kshitij230/Indian-Law", split="train")
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16
)
model_name = "ajay-drew/Mistral-7B-Indian-Law"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=quantization_config,
device_map="auto"
)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.eval()
total_loss = 0
total_tokens = 0
test_texts = dataset['Instruction'][:500]
with torch.no_grad():
for text in test_texts:
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512).to(device)
outputs = model(**inputs, labels=inputs["input_ids"])
loss = outputs.loss
if loss is not None:
total_loss += loss.item() * inputs["input_ids"].size(1)
total_tokens += inputs["input_ids"].size(1)
if total_tokens > 0:
perplexity = torch.exp(torch.tensor(total_loss / total_tokens)).item()
print(f"Perplexity: {perplexity}")
print(f"Total tokens: {total_tokens}")
print(f"Total loss: {total_loss}")
else:
print("Error: No tokens processed. Check dataset or tokenization.")
🔧 技術詳細
ハードウェア
- ハードウェアタイプ:NVIDIA GeForce RTX 4050 Laptop GPU
- 使用時間:24:19:47
モデルアーキテクチャ
- ベースモデル:
Mistral 7B
(70億パラメータのTransformerベースの言語モデル)
- アーキテクチャ:
- マルチヘッドセルフアテンションレイヤーを持つデコーダー専用のTransformer。
- 32層、4096の隠れサイズ、16のアテンションヘッド (Mistral 7Bから継承)。
- 効率的なファインチューニングのためにLow-Rank Adaptation (LoRA) レイヤーで修正。
- ファインチューニングアプローチ:
- PEFT:メモリ使用量を削減するためのParameter-Efficient Fine-Tuning。
- QLoRA:4ビット量子化を使用して重みを効率的に適応させるQuantized LoRA。
- ファインチューニングされるパラメータ:LoRAは特定の重み行列を対象とし、ベースモデルの大部分は凍結されたままです。
ソフトウェア
- CUDA:PyTorch - 2.6.0+cu126
📚 ドキュメント
モデルカードの連絡先
- Gmail:drewjay05@gmail.com
- GitHub:github.com/ajay-drew
- Linkedin:linkedin.com/in/ajay-a-133b1326a/
フレームワークバージョン