🚀 澳大利亞法律嵌入模型 v1.0
澳大利亞法律嵌入模型 v1.0 是一個基於 sentence-transformers
的模型,它能夠將句子和段落映射到 384 維的密集向量空間,可用於聚類或語義搜索等任務。該模型在澳大利亞法律場景下表現出色,為法律文本處理提供了強大的支持。
🚀 快速開始
若要使用此模型,需先安裝 sentence-transformers:
pip install -U sentence-transformers
安裝完成後,即可按如下方式使用該模型:
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('adlumal/auslaw-embed-v1.0')
embeddings = model.encode(sentences)
print(embeddings)
✨ 主要特性
- 向量映射:能夠將句子和段落映射到 384 維的密集向量空間。
- 多任務支持:可用於聚類或語義搜索等任務。
- 微調優化:基於 BAAI/bge-small-en 模型,使用澳大利亞高等法院(HCA)判例法進行微調。
📦 安裝指南
使用此模型前,需安裝 sentence-transformers:
pip install -U sentence-transformers
💻 使用示例
基礎用法
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('adlumal/auslaw-embed-v1.0')
embeddings = model.encode(sentences)
print(embeddings)
📚 詳細文檔
評估結果
模型在 10% 的可用數據上進行了評估,最終步驟的自動評估結果如下:
評估指標 |
得分 |
cos_sim-Accuracy@1 |
0.730206301 |
cos_sim-Accuracy@3 |
0.859562308 |
cos_sim-Accuracy@5 |
0.892737664 |
cos_sim-Accuracy@10 |
0.928352384 |
cos_sim-Precision@1 |
0.730206301 |
cos_sim-Recall@1 |
0.730206301 |
cos_sim-Precision@3 |
0.286520769 |
cos_sim-Recall@3 |
0.859562308 |
cos_sim-Precision@5 |
0.178547533 |
cos_sim-Recall@5 |
0.892737664 |
cos_sim-Precision@10 |
0.092835238 |
cos_sim-Recall@10 |
0.928352384 |
cos_sim-MRR@10 |
0.801075782 |
cos_sim-NDCG@10 |
0.832189447 |
cos_sim-MAP@100 |
0.803593645 |
dot_score-Accuracy@1 |
0.730136604 |
dot_score-Accuracy@3 |
0.859562308 |
dot_score-Accuracy@5 |
0.892737664 |
dot_score-Accuracy@10 |
0.928352384 |
dot_score-Precision@1 |
0.730136604 |
dot_score-Recall@1 |
0.730136604 |
dot_score-Precision@3 |
0.286520769 |
dot_score-Recall@3 |
0.859562308 |
dot_score-Precision@5 |
0.178547533 |
dot_score-Recall@5 |
0.892737664 |
dot_score-Precision@10 |
0.092835238 |
dot_score-Recall@10 |
0.928352384 |
dot_score-MRR@10 |
0.801040934 |
dot_score-NDCG@10 |
0.832163724 |
dot_score-MAP@100 |
0.803558796 |
訓練參數
模型使用以下參數進行訓練:
數據加載器:
torch.utils.data.dataloader.DataLoader
,長度為 2583,參數如下:
{'batch_size': 50, 'sampler': 'torch.utils.data.sampler.SequentialSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
損失函數:
sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss
,參數如下:
{'scale': 20.0, 'similarity_fct': 'cos_sim'}
fit()
方法的參數:
{
"epochs": 2,
"evaluation_steps": 50,
"evaluator": "sentence_transformers.evaluation.InformationRetrievalEvaluator.InformationRetrievalEvaluator",
"max_grad_norm": 1,
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": null,
"warmup_steps": 516,
"weight_decay": 0.01
}
完整模型架構
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': True}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
(2): Normalize()
)
🔧 技術細節
該模型是基於 BAAI/bge-small-en 進行微調的。使用了澳大利亞高等法院(HCA)判例法在 Open Australian Legal Corpus 中的數據,未使用 PDF/OCR 案例。案例使用 bge-small-en
分詞器和 semchunk 分割成小於 512 的上下文塊。使用 mistralai/Mixtral-8x7B-Instruct-v0.1 為每個上下文塊生成法律問題,共使用 129,137 個上下文 - 問題對進行訓練,14,348 個上下文 - 問題對進行評估。
性能對比
使用驗證數據集的 10% 子集,該模型達到了以下命中率性能,並與基礎模型和 OpenAI 的默認 ada
嵌入模型進行了比較:
模型 |
平均命中率 |
BAAI/bge-small-en |
89% |
OpenAI |
92% |
adlumal/auslaw-embed-v1.0 |
97% |
📄 許可證
本項目採用 Apache-2.0 許可證。
📖 引用與作者
@misc{malec-2024-auslaw-embed-v1,
author = {Malec, Adrian Lucas},
year = {2024},
title = {AusLaw Embedding v1.0},
publisher = {Hugging Face},
version = {1.0},
url = {https://huggingface.co/adlumal/auslaw-embed-v1.0}
}