语言:
- 英文
数据集:
- pile-of-law/pile-of-law
管道标签: 填充掩码
法律文书BERT大模型(无大小写区分)
基于RoBERTa预训练目标,在英语法律和行政文本上预训练的模型。
模型描述
法律文书BERT大模型是一个采用BERT大模型(无大小写区分)架构的transformers模型,在法律文书堆上进行了预训练。该数据集包含约256GB的英语法律和行政文本,用于语言模型预训练。
预期用途与限制
您可以将原始模型用于掩码语言建模,或针对下游任务进行微调。由于此模型是在英语法律和行政文本语料库上预训练的,法律相关的下游任务可能更适合此模型。
使用方法
您可以直接使用管道进行掩码语言建模:
>>> from transformers import pipeline
>>> pipe = pipeline(task='fill-mask', model='pile-of-law/legalbert-large-1.7M-1')
>>> pipe("An [MASK] is a request made after a trial by a party that has lost on one or more issues that a higher court review the decision to determine if it was correct.")
[{'sequence': 'an appeal is a request made after a trial by a party that has lost on one or more issues that a higher court review the decision to determine if it was correct.',
'score': 0.6343119740486145,
'token': 1151, '
token_str': 'appeal'},
{'sequence': 'an objection is a request made after a trial by a party that has lost on one or more issues that a higher court review the decision to determine if it was correct.',
'score': 0.10488124936819077,
'token': 3542,
'token_str': 'objection'},
{'sequence': 'an application is a request made after a trial by a party that has lost on one or more issues that a higher court review the decision to determine if it was correct.',
'score': 0.0708756372332573,
'token': 1999,
'token_str': 'application'},
{'sequence': 'an example is a request made after a trial by a party that has lost on one or more issues that a higher court review the decision to determine if it was correct.',
'score': 0.02558572217822075,
'token': 3677,
'token_str': 'example'},
{'sequence': 'an action is a request made after a trial by a party that has lost on one or more issues that a higher court review the decision to determine if it was correct.',
'score': 0.013266939669847488,
'token': 1347,
'token_str': 'action'}]
以下是如何在PyTorch中使用此模型获取给定文本的特征:
from transformers import BertTokenizer, BertModel
tokenizer = BertTokenizer.from_pretrained('pile-of-law/legalbert-large-1.7M-1')
model = BertModel.from_pretrained('pile-of-law/legalbert-large-1.7M-1')
text = "替换为您想要的任何文本。"
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
在TensorFlow中:
from transformers import BertTokenizer, TFBertModel
tokenizer = BertTokenizer.from_pretrained('pile-of-law/legalbert-large-1.7M-1')
model = TFBertModel.from_pretrained('pile-of-law/legalbert-large-1.7M-1')
text = "替换为您想要的任何文本。"
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
限制与偏见
请参阅《法律文书堆》论文的附录G,了解与数据集和模型使用相关的版权限制。
此模型可能存在预测偏见。在以下使用掩码语言建模管道的示例中,对于罪犯的种族描述,模型预测“黑人”的分数高于“白人”。
>>> from transformers import pipeline
>>> pipe = pipeline(task='fill-mask', model='pile-of-law/legalbert-large-1.7M-1')
>>> pipe("The clerk described the robber as a “thin [MASK] male, about six foot tall, wearing a gray hoodie, blue jeans", targets=["black", "white"])
[{'sequence': 'the clerk described the robber as a thin black male, about six foot tall, wearing a gray hoodie, blue jeans',
'score': 0.0013972163433209062,
'token': 4311,
'token_str': 'black'},
{'sequence': 'the clerk described the robber as a thin white male, about six foot tall, wearing a gray hoodie, blue jeans',
'score': 0.0009401230490766466,
'token': 4249, '
token_str': 'white'}]
这种偏见也会影响此模型的所有微调版本。
训练数据
法律文书BERT大模型在《法律文书堆》上进行了预训练,这是一个包含约256GB英语法律和行政文本的数据集,用于语言模型预训练。《法律文书堆》包含35个数据源,包括法律分析、法院意见和文件、政府机构出版物、合同、法规、案例书等。我们在《法律文书堆》论文的附录E中详细描述了这些数据源。《法律文书堆》数据集采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议。
训练过程
预处理
模型词汇表包含29,000个来自自定义词片词汇表的标记,这些标记使用HuggingFace WordPiece分词器拟合《法律文书堆》,以及从《布莱克法律词典》中随机抽取的3,000个法律术语,词汇表总大小为32,000个标记。采用BERT中的80-10-10掩码、损坏、保留分割方法,复制率为20,为每个上下文创建不同的掩码。为了生成序列,我们使用LexNLP句子分割器,该工具可以处理法律引用的句子分割(这些引用经常被错误地视为句子)。输入格式为填充句子直到达到256个标记,后跟一个[SEP]标记,然后填充句子,使整个跨度不超过512个标记。如果系列中的下一个句子过大,则不添加,剩余上下文长度用填充标记填充。
预训练
模型在SambaNova集群上训练,使用8个RDU,进行了170万步训练。我们使用了较小的学习率5e-6和批量大小128,以缓解训练不稳定性,这可能是由于训练数据源的多样性所致。预训练使用了RoBERTa中描述的掩码语言建模(MLM)目标,没有NSP损失。模型在所有步骤中使用512长度的序列进行预训练。
我们使用相同的设置并行训练了两个模型,随机种子不同。我们选择了最低对数似然模型pile-of-law/legalbert-large-1.7M-1,称为PoL-BERT-Large,用于实验,但也发布了第二个模型pile-of-law/legalbert-large-1.7M-2。
评估结果
当在LexGLUE论文提供的CaseHOLD变体上进行微调时,此模型PoL-BERT-Large取得了以下结果。在下表中,我们还报告了BERT-Large-Uncased和CaseLaw-BERT的结果。我们报告了在下游任务上进行超参数调整的模型结果,以及LexGLUE论文中报告的CaseLaw-BERT模型结果,该模型使用固定的实验设置。
CaseHOLD测试结果:
模型 |
F1 |
CaseLaw-BERT (调优) |
78.5 |
CaseLaw-BERT (LexGLUE) |
75.4 |
PoL-BERT-Large |
75.0 |
BERT-Large-Uncased |
71.3 |
BibTeX条目和引用信息
@misc{hendersonkrass2022pileoflaw,
url = {https://arxiv.org/abs/2207.00220},
author = {Henderson*, Peter and Krass*, Mark S. and Zheng, Lucia and Guha, Neel and Manning, Christopher D. and Jurafsky, Dan and Ho, Daniel E.},
title = {Pile of Law: Learning Responsible Data Filtering from the Law and a 256GB Open-Source Legal Dataset},
publisher = {arXiv},
year = {2022}
}