Nextorage/Llama-3.1-Swallow-8B-LawInstruct-NLI-LoRA
08
Llama-3.1-Swallow-8B LawInstruct NLI LoRA (T2T)
概要 / Overview
Nextorage AiDAPTIV+ プラットフォーム上で Llama-3.1-Swallow-8B に LoRA ファインチューニングを施した、英語法律文書 NLI(含意関係分類)モデルです。
Accuracy 88.0%、Macro F1 0.827 を達成し、GPT-4o few_shot(Acc 86.0%)を上回りました。LoRA アダプターサイズは約 75MB で、フルモデル(~16GB)に対して約 0.5% のパラメータ更新で実現されています。
A LoRA fine-tuned version of Llama-3.1-Swallow-8B for legal NLI (Natural Language Inference) classification, trained on AiDAPTIV+ platform by Nextorage. Achieves Accuracy 88.0% and Macro F1 0.827 — surpassing GPT-4o few_shot (86.0%) on the same test set, with only a ~75MB LoRA adapter.
性能 / Performance
テストセット: LawInstruct NLI 英語版 100件(entailment/contradiction/neutral の3値分類)
クラス別精度
注: contradiction クラスの Recall がベースライン 0.476 から 0.667 へ大幅改善(FullFT では 0.857)。
使い方 / Usage
LoRA アダプターとして使用(推奨)
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# ベースモデルのロード(要: tokyotech-llm/Llama-3.1-Swallow-8B)
base_model_id = "tokyotech-llm/Llama-3.1-Swallow-8B"
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id,
torch_dtype=torch.bfloat16,
device_map="auto"
)
# LoRA アダプターのロード
model = PeftModel.from_pretrained(
base_model,
"Nextorage/Llama-3.1-Swallow-8B-LawInstruct-NLI-LoRA"
)
SYSTEM_PROMPT = """You are an expert AI assistant specializing in analyzing logical relationships in legal documents.
Classify the relationship between two legal case passages as one of:
entailment – Passage 1 logically implies Passage 2
contradiction – Passage 1 and Passage 2 are logically contradictory
neutral – No logical entailment or contradiction between the passages
Respond with exactly one word: entailment, contradiction, or neutral."""
question = """Analyze these two passages from a US legal case:
do they entail, contradict, or remain neutral to each other?
Passage 1: We agree with the trial court that under the clear terms of
the contract, the seller's obligation was discharged upon
delivery of the goods.
Passage 2: The appellate court held that the seller retained liability
for latent defects regardless of the delivery terms agreed
upon by the parties."""
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": question},
]
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
output = model.generate(input_ids, max_new_tokens=10)
print(tokenizer.decode(output[0][input_ids.shape[1]:], skip_special_tokens=True))
# 期待出力: contradiction推論スクリプト
# 依存パッケージのインストール
pip install transformers peft torch
# 評価・推論の実行
python run_inference.py \
--model_path /path/to/this/adapter \
--original_model_path /path/to/Llama-3.1-Swallow-8B \
--test_data /path/to/nli_test.json \
--output_dir ./results学習設定 / Training Configuration
データセット詳細
- 元データ: LawInstruct(全 20,000 件)から NLI サブセットを抽出
- 英語フィルタ(非ASCII比率 > 10% を除外)後、3値ラベル(entailment/contradiction/neutral)に絞り込み
- 層別分割(stratified split, seed=42): Train 1,565件 / Val 283件 / Test 100件
制限事項 / Limitations
- 英語法律文書の NLI タスク(entailment / contradiction / neutral の 3 値分類)に特化
- 使用には ベースモデル `tokyotech-llm/Llama-3.1-Swallow-8B` が別途必要
- テストセット中約 12% に多言語(ルーマニア語・フィンランド語等)の指示文が残存しており、これらのサンプルでは精度が低下する可能性がある
- 日本語翻訳版データでの学習・評価では Accuracy が大幅に低下(最良 66%)するため、英語法律文書での使用を推奨
ライセンス / License
本モデルは Llama 3.1 Community License に基づいています。 商用利用は条件付きで許可されています。詳細はライセンス全文を参照してください。
引用 / Citation
@misc{nextorage-lawinstruct-nli-lora-2026,
title = {Llama-3.1-Swallow-8B LawInstruct NLI LoRA},
author = {Nextorage Inc.},
year = {2026},
howpublished = {\url{https://huggingface.co/Nextorage/Llama-3.1-Swallow-8B-LawInstruct-NLI-LoRA}},
note = {LoRA fine-tuned model for legal NLI classification on AiDAPTIV+ platform}
}