モデル概要
モデル特徴
モデル能力
使用事例
🚀 Pile of Law BERT largeモデル (uncased)
このモデルは、英語の法的および行政テキストに対して、RoBERTaの事前学習目標を用いて事前学習されたものです。法的な自然言語処理タスクに役立ちます。
🚀 クイックスタート
このモデルは、マスク付き言語モデリングに直接使用することができます。また、下流タスクに対して微調整することも可能です。
✨ 主な機能
- BERT large model (uncased) のアーキテクチャを持つトランスフォーマーモデルです。
- Pile of Law という、約256GBの英語の法的および行政テキストからなるデータセットで事前学習されています。
📦 インストール
このモデルを使用するには、transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install transformers
💻 使用例
基本的な使用法
マスク付き言語モデリングのパイプラインでモデルを直接使用する方法は次の通りです。
>>> 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 = "Replace me by any text you'd like."
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 = "Replace me by any text you'd like."
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
📚 ドキュメント
想定される用途と制限
生のモデルをマスク付き言語モデリングに使用するか、下流タスクのために微調整することができます。このモデルは英語の法的および行政テキストコーパスで事前学習されているため、法的な下流タスクがこのモデルにとってより適切なドメインとなる可能性が高いです。
制限とバイアス
データセットとモデルの使用に関する著作権の制限については、Pile of Law論文の付録Gを参照してください。
このモデルはバイアスのある予測を行う可能性があります。次の例では、モデルをマスク付き言語モデリングのパイプラインで使用した場合、犯罪者の人種記述において、「black」のスコアが「white」よりも高く予測されています。
>>> 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'}]
このバイアスは、このモデルのすべての微調整バージョンにも影響を与えます。
学習データ
Pile of Law BERT largeモデルは、Pile of Lawというデータセットで事前学習されています。このデータセットは、言語モデルの事前学習用の約256GBの英語の法的および行政テキストから構成されています。Pile of Lawは35のデータソースから構成され、法的分析、裁判所の意見や申立書、政府機関の出版物、契約書、法令、規則、判例集などが含まれます。データソースの詳細については、Pile of Law論文の付録Eで説明しています。Pile of Lawデータセットは、CreativeCommons Attribution-NonCommercial-ShareAlike 4.0 Internationalライセンスの下に置かれています。
学習手順
前処理
モデルの語彙は、HuggingFace WordPiece tokenizer を使用してPile of Lawに適合させたカスタムワードピース語彙からの29,000トークンと、Black's Law Dictionaryからランダムにサンプリングされた3,000の法的用語から構成され、語彙サイズは32,000トークンです。BERT と同じように、80-10-10のマスキング、破損、残りの分割を使用し、各コンテキストに対して異なるマスクを作成するために複製率20を使用します。シーケンスを生成するために、LexNLP sentence segmenter を使用します。これは法的引用の文分割を処理します(法的引用はしばしば誤って文と見なされます)。入力は、文を256トークンになるまで埋め、[SEP]トークンを続け、その後、全体の範囲が512トークン未満になるように文を埋めるようにフォーマットされます。シリーズの次の文が大きすぎる場合は追加されず、残りのコンテキスト長はパディングトークンで埋められます。
事前学習
モデルは、SambaNovaクラスタで8つのRDUを使用して170万ステップ学習されました。学習データのソースの多様性による学習の不安定性を軽減するために、5e-6の小さな学習率と128のバッチサイズを使用しました。RoBERTa で説明されているように、NSP損失のないマスク付き言語モデリング(MLM)目標を事前学習に使用しました。モデルはすべてのステップで512のシーケンス長で事前学習されました。
同じ設定で2つのモデルを並列に学習し、異なる乱数シードを使用しました。最低の対数尤度を持つモデル pile-of-law/legalbert-large-1.7M-1(PoL-BERT-Largeと呼びます)を実験に選択しましたが、2番目のモデル pile-of-law/legalbert-large-1.7M-2 も公開しています。
評価結果
LexGLUE論文 で提供されているCaseHOLDバリアントで微調整した場合、このモデル(PoL-BERT-Large)は次の結果を達成します。以下の表では、BERT-Large-Uncased と CaseLaw-BERT の結果も報告しています。下流タスクでハイパーパラメータチューニングを行ったモデルの結果と、LexGLUE論文 からのCaseLaw-BERTモデルの報告結果を報告しています。この論文では固定された実験設定を使用しています。
モデル | F1 |
---|---|
CaseLaw-BERT (tuned) | 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}
}



