Bert Large Portuguese Cased Legal Mlm Nli Sts V1
模型概述
這是一個針對葡萄牙語法律文本優化的BERT模型,能夠將句子和段落映射到1024維向量空間,適用於聚類、語義搜索等自然語言處理任務。
模型特點
法律領域優化
基於約3萬份法律文書進行專項訓練,在法律文本處理上表現優異
多階段訓練
經過MLM預訓練、NLI微調和STS專項優化三階段訓練流程
高維向量空間
生成1024維稠密向量,能更好捕捉法律文本的語義特徵
模型能力
句子向量化
語義相似度計算
法律文本分析
語義搜索
文本聚類
使用案例
司法系統
法律文書語義搜索
在法律文檔庫中實現基於語義的相似案例檢索
在IRIS項目中實際應用,提升法律檢索效率
判決書分析
分析判決書中的關鍵句子相似度
自然語言處理
文本相似度計算
計算兩個葡萄牙語句子之間的語義相似度
在assin2數據集上達到0.81皮爾遜相關係數
🚀 stjiris/bert-large-portuguese-cased-legal-mlm-nli-sts-v1 (法律領域葡萄牙語BERT模型)
這是一個用於法律領域的葡萄牙語BERT模型,它可以將句子和段落映射到一個1024維的密集向量空間,可用於聚類或語義搜索等任務。該模型基於Sentence-Transformers框架,在多個葡萄牙語法律相關數據集上進行了訓練和微調,具有良好的語義文本相似度計算能力。
🚀 快速開始
本模型基於 sentence-transformers 框架,使用前請確保已安裝該庫:
pip install -U sentence-transformers
然後可以按照以下方式使用模型:
from sentence_transformers import SentenceTransformer
sentences = ["Isto é um exemplo", "Isto é um outro exemplo"]
model = SentenceTransformer('stjiris/bert-large-portuguese-cased-legal-mlm-nli-sts-v1')
embeddings = model.encode(sentences)
print(embeddings)
✨ 主要特性
- 多數據集訓練:模型在多個葡萄牙語法律相關數據集上進行了訓練,包括 assin、assin2、stsb_multi_mt pt 和 IRIS STS 等,能夠更好地處理法律領域的語義文本相似度任務。
- 語義向量映射:可以將句子和段落映射到一個1024維的密集向量空間,方便進行聚類、語義搜索等任務。
- 多種使用方式:支持使用 sentence-transformers 庫和 HuggingFace Transformers 庫進行調用。
📦 安裝指南
使用本模型需要安裝 sentence-transformers 庫,可通過以下命令進行安裝:
pip install -U sentence-transformers
💻 使用示例
基礎用法
使用 sentence-transformers 庫調用模型:
from sentence_transformers import SentenceTransformer
sentences = ["Isto é um exemplo", "Isto é um outro exemplo"]
model = SentenceTransformer('stjiris/bert-large-portuguese-cased-legal-mlm-nli-sts-v1')
embeddings = model.encode(sentences)
print(embeddings)
高級用法
使用 HuggingFace Transformers 庫調用模型:
from transformers import AutoTokenizer, AutoModel
import torch
#Mean Pooling - Take attention mask into account for correct averaging
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
# Sentences we want sentence embeddings for
sentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained('stjiris/bert-large-portuguese-cased-legal-mlm-nli-sts-v1')
model = AutoModel.from_pretrained('stjiris/bert-large-portuguese-cased-legal-mlm-nli-sts-v1')
# Tokenize sentences
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
model_output = model(**encoded_input)
# Perform pooling. In this case, mean pooling.
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
📚 詳細文檔
模型信息
屬性 | 詳情 |
---|---|
模型類型 | 基於Sentence-Transformers的葡萄牙語法律領域BERT模型 |
訓練數據 | stjiris/portuguese-legal-sentences-v0、assin、assin2、stsb_multi_mt、stjiris/IRIS_sts |
模型評估結果
數據集 | 皮爾遜相關係數 |
---|---|
assin | 0.7774097897260964 |
assin2 | 0.8097518625809903 |
stsb_multi_mt pt | 0.8358844307795662 |
IRIS STS | 0.7856746037418626 |
🔧 技術細節
本模型基於 BERTimbau 大型模型的法律變體 stjiris/bert-large-portuguese-cased-legal-mlm 進行開發。訓練過程分為多個階段:
- MLM訓練:使用MLM技術,學習率為1e-5,在約30000篇文檔的法律句子上進行了15000步訓練。
- NLI數據處理:將模型應用於NLI數據,批量大小為16,學習率為2e-5。
- 語義文本相似度微調:在 assin、assin2、stsb_multi_mt pt 和 IRIS STS 數據集上進行微調,學習率為1e-5。
完整模型架構
SentenceTransformer(
(0): Transformer({'max_seq_length': 514, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 1028, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False})
)
📄 許可證
本模型使用MIT許可證。
📖 引用信息
貢獻者
引用格式
@InProceedings{MeloSemantic,
author="Melo, Rui
and Santos, Pedro A.
and Dias, Jo{\~a}o",
editor="Moniz, Nuno
and Vale, Zita
and Cascalho, Jos{\'e}
and Silva, Catarina
and Sebasti{\~a}o, Raquel",
title="A Semantic Search System for the Supremo Tribunal de Justi{\c{c}}a",
booktitle="Progress in Artificial Intelligence",
year="2023",
publisher="Springer Nature Switzerland",
address="Cham",
pages="142--154",
abstract="Many information retrieval systems use lexical approaches to retrieve information. Such approaches have multiple limitations, and these constraints are exacerbated when tied to specific domains, such as the legal one. Large language models, such as BERT, deeply understand a language and may overcome the limitations of older methodologies, such as BM25. This work investigated and developed a prototype of a Semantic Search System to assist the Supremo Tribunal de Justi{\c{c}}a (Portuguese Supreme Court of Justice) in its decision-making process. We built a Semantic Search System that uses specially trained BERT models (Legal-BERTimbau variants) and a Hybrid Search System that incorporates both lexical and semantic techniques by combining the capabilities of BM25 and the potential of Legal-BERTimbau. In this context, we obtained a {\$}{\$}335{\backslash}{\%}{\$}{\$}335{\%}increase on the discovery metric when compared to BM25 for the first query result. This work also provides information on the most relevant techniques for training a Large Language Model adapted to Portuguese jurisprudence and introduces a new technique of Metadata Knowledge Distillation.",
isbn="978-3-031-49011-8"
}
@inproceedings{souza2020bertimbau,
author = {F{\'a}bio Souza and
Rodrigo Nogueira and
Roberto Lotufo},
title = {{BERT}imbau: pretrained {BERT} models for {B}razilian {P}ortuguese},
booktitle = {9th Brazilian Conference on Intelligent Systems, {BRACIS}, Rio Grande do Sul, Brazil, October 20-23 (to appear)},
year = {2020}
}
@inproceedings{fonseca2016assin,
title={ASSIN: Avaliacao de similaridade semantica e inferencia textual},
author={Fonseca, E and Santos, L and Criscuolo, Marcelo and Aluisio, S},
booktitle={Computational Processing of the Portuguese Language-12th International Conference, Tomar, Portugal},
pages={13--15},
year={2016}
}
@inproceedings{real2020assin,
title={The assin 2 shared task: a quick overview},
author={Real, Livy and Fonseca, Erick and Oliveira, Hugo Goncalo},
booktitle={International Conference on Computational Processing of the Portuguese Language},
pages={406--412},
year={2020},
organization={Springer}
}
@InProceedings{huggingface:dataset:stsb_multi_mt,
title = {Machine translated multilingual STS benchmark dataset.},
author={Philip May},
year={2021},
url={https://github.com/PhilipMay/stsb-multi-mt}
}
相關項目鏈接
Jina Embeddings V3
Jina Embeddings V3 是一個多語言句子嵌入模型,支持超過100種語言,專注於句子相似度和特徵提取任務。
文本嵌入
Transformers 支持多種語言

J
jinaai
3.7M
911
Ms Marco MiniLM L6 V2
Apache-2.0
基於MS Marco段落排序任務訓練的交叉編碼器模型,用於信息檢索中的查詢-段落相關性評分
文本嵌入 英語
M
cross-encoder
2.5M
86
Opensearch Neural Sparse Encoding Doc V2 Distill
Apache-2.0
基於蒸餾技術的稀疏檢索模型,專為OpenSearch優化,支持免推理文檔編碼,在搜索相關性和效率上優於V1版本
文本嵌入
Transformers 英語

O
opensearch-project
1.8M
7
Sapbert From PubMedBERT Fulltext
Apache-2.0
基於PubMedBERT的生物醫學實體表徵模型,通過自對齊預訓練優化語義關係捕捉
文本嵌入 英語
S
cambridgeltl
1.7M
49
Gte Large
MIT
GTE-Large 是一個強大的句子轉換器模型,專注於句子相似度和文本嵌入任務,在多個基準測試中表現出色。
文本嵌入 英語
G
thenlper
1.5M
278
Gte Base En V1.5
Apache-2.0
GTE-base-en-v1.5 是一個英文句子轉換器模型,專注於句子相似度任務,在多個文本嵌入基準測試中表現優異。
文本嵌入
Transformers 支持多種語言

G
Alibaba-NLP
1.5M
63
Gte Multilingual Base
Apache-2.0
GTE Multilingual Base 是一個多語言的句子嵌入模型,支持超過50種語言,適用於句子相似度計算等任務。
文本嵌入
Transformers 支持多種語言

G
Alibaba-NLP
1.2M
246
Polybert
polyBERT是一個化學語言模型,旨在實現完全由機器驅動的超快聚合物信息學。它將PSMILES字符串映射為600維密集指紋,以數值形式表示聚合物化學結構。
文本嵌入
Transformers

P
kuelumbus
1.0M
5
Bert Base Turkish Cased Mean Nli Stsb Tr
Apache-2.0
基於土耳其語BERT的句子嵌入模型,專為語義相似度任務優化
文本嵌入
Transformers 其他

B
emrecan
1.0M
40
GIST Small Embedding V0
MIT
基於BAAI/bge-small-en-v1.5模型微調的文本嵌入模型,通過MEDI數據集與MTEB分類任務數據集訓練,優化了檢索任務的查詢編碼能力。
文本嵌入
Safetensors 英語
G
avsolatorio
945.68k
29
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98