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