Blackstoneは、長型の非構造化された法的テキストを処理するためのスペイシーモデルおよびライブラリです。 Blackstoneは、イングランドとウェールズの研究室のための法人法評議会の実験研究プロジェクトです。ICLR&D。ブラックストーンはダニエル・ホードリーによって書かれました。
なぜ私たちはブラックストーンを建設しているのですか?
ブラックストーンの特別なところは何ですか?
観察や注目に値するもの
インストール
ライブラリをインストールします
Blackstoneモデルをインストールします
モデルについて
パイプライン
指名されたエンティティ認識者
テキストカテゴリザー
使用法
NERモデルの適用
エンティティの視覚化
テキストカテゴリザーモデルの適用
カスタムパイプライン拡張機能
略語と長期の定義解決
複合ケース参照検出
法律リンカー
文セグメントター
過去数年間、法律と技術の交差点で活動が急増しています。しかし、英国では、その活動の圧倒的な大部分が法律事務所やその他の商業的文脈で行われています。この結果、法律情報分野での開発の突風が終わらないにもかかわらず、オープンソースベースではほとんど研究が利用できないということです。
さらに、英国の法律情報領域(オープンであろうと閉鎖かどうか)における研究の大部分は、本質的に取引される契約やその他の法的文書を自動化するためのNLPアプリケーションの開発に焦点を当てています。これは理解できます。なぜなら、英国の法的NLP研究の主要な恩人は法律事務所であり、法律事務所は、トレーニングデータとして利用できる取引文書を手に入れることは難しいと感じていないからです。
問題は、私たちが見るように、英国の法的NLP研究は商業アプリケーションに集中しており、判断、学術記事、スケルトン議論、訴えなどの他の法的テキストに関して利用可能な法的NLP研究の開発への投資をする価値があるということです。
注記! Blackstoneを仮想環境にインストールすることを強くお勧めします!仮想環境の詳細については、こちらをご覧ください。 Blackstoneは、Python 3.6以降と互換性があるはずです。
Blackstoneをインストールするには、次の手順に従います。
最初のステップは、現在、いくつかのカスタムスペイシーコンポーネントが含まれているライブラリをインストールすることです。そのようにライブラリをインストールする:
pip install blackstone
2番目のステップは、SPACYモデルをインストールすることです。そのようなモデルをインストールする:
pip install https://blackstone-model.s3-eu-west-1.amazonaws.com/en_blackstone_proto-0.0.1.tar.gz
Blackstoneを開発している場合は、次のようなソースからインストールできます。
pip install --editable .
pip install -r dev-requirements.txt
これはBlackstoneの最初のリリースであり、モデルはプロトタイプとして最もよく見えることです。それは端の周りで荒いものであり、ICLR&Dによって実行される法的テキストに関するNLPのオープンソース研究のより大きな進行中のプログラムの最初のステップを表しています。
それが邪魔にならないように、プロトモデルで起こっていることの簡単な要約を次に示します。
このリリースに含まれるプロトモデルには、そのパイプラインに次の要素があります。
合法的なテキストのラベル付けされた部分的な部分と依存関係のトレーニングデータが不足しているため、 tokenizer 、 tagger 、 parserパイプラインコンポーネントは、Spacyのen_core_web_smモデルから取得されています。概して、これらのコンポーネントはまともな仕事をしているように見えますが、将来のある時点でこれらのコンポーネントをカスタムトレーニングデータで再訪するのは良いことです。
nerおよびtextcatコンポーネントは、特にBlackstone向けにトレーニングされているカスタムコンポーネントです。
BlackstoneモデルのNERコンポーネントは、次のエンティティタイプを検出するためにトレーニングされています。
| ent | 名前 | 例 |
|---|---|---|
| casename | ケース名 | たとえば、スミスvジョーンズ、ジョーンズ、ジョーンズの場合 |
| 引用 | 引用(報告されていないケースおよび報告されていないケースの一意の識別子) | 例(2002)2 Cr App R 123 |
| 楽器 | 書かれた法的手段 | 例:1968年盗難法、欧州人権条約、CPR |
| 規定 | 書面による法的手段内のユニット | 例:セクション1、アート2(3) |
| 裁判所 | 裁判所または裁判所 | 例:控訴裁判所、アッパー裁判所 |
| 裁判官 | 裁判官への参照 | 例:コーンヒルのビンガムLord |
Blackstoneのこのリリースには、テキストカテゴリザーも付いています。 NERコンポーネント(トークンと一連の関心のあるトークンを識別するためにトレーニングされている)とは対照的に、テキストカテゴリザーは、文などの長いテキストのスパンを分類します。
テキストカテゴリーは、次の5つの相互に排他的なカテゴリのいずれかに従ってテキストを分類するように訓練されています。これは次のとおりです。
| 猫 | 説明 |
|---|---|
| 公理 | テキストは、確立された原則を仮定しているようです |
| 結論 | テキストは、発見、保持、決意、結論を出すようです |
| 問題 | テキストは問題や質問について議論しているようです |
| legal_test | このテストは、法的テストについて議論しているようです |
| uncat | テキストは上記の4つのカテゴリのいずれかに分類されません |
これは、R(Miller)v国務長官の欧州連合(Birnie介入) [2017] UKSC 5の国務長官の判決のパラ31から取られたいくつかのテキストにモデルがどのように適用されるかの例です。 [2018] AC 61:
import spacy
# Load the model
nlp = spacy . load ( "en_blackstone_proto" )
text = """ 31 As we shall explain in more detail in examining the submission of the Secretary of State (see paras 77 and following), it is the Secretary of State’s case that nothing has been done by Parliament in the European Communities Act 1972 or any other statute to remove the prerogative power of the Crown, in the conduct of the international relations of the UK, to take steps to remove the UK from the EU by giving notice under article 50EU for the UK to withdraw from the EU Treaty and other relevant EU Treaties. The Secretary of State relies in particular on Attorney General v De Keyser’s Royal Hotel Ltd [1920] AC 508 and R v Secretary of State for Foreign and Commonwealth Affairs, Ex p Rees-Mogg [1994] QB 552; he contends that the Crown’s prerogative power to cause the UK to withdraw from the EU by giving notice under article 50EU could only have been removed by primary legislation using express words to that effect, alternatively by legislation which has that effect by necessary implication. The Secretary of State contends that neither the ECA 1972 nor any of the other Acts of Parliament referred to have abrogated this aspect of the Crown’s prerogative, either by express words or by necessary implication.
"""
# Apply the model to the text
doc = nlp ( text )
# Iterate through the entities identified by the model
for ent in doc . ents :
print ( ent . text , ent . label_ )
> >> European Communities Act 1972 INSTRUMENT
> >> article 50 EU PROVISION
>> > EU Treaty INSTRUMENT
> >> Attorney General v De Keyser ’ s Royal Hotel Ltd CASENAME
> >> [ 1920 ] AC 508 CITATION
>> > R v Secretary of State for Foreign and Commonwealth Affairs , Ex p Rees - Mogg CASENAME
>> > [ 1994 ] QB 552 CITATION
> >> article 50 EU PROVISION Spacyは、NERのVisualiserを含む、Visualisersの優れたセットを備えた出荷時です。 Blackstoneには、ディスプレイを使用するときにソーステキストのエンティティを簡単に区別できるようにするために使用できるカスタムカラーパレットが付属しています。
"""
Visualise entities using spaCy's displacy visualiser.
Blackstone has a custom colour palette: `from blackstone.displacy_palette import ner_displacy options`
"""
import spacy
from spacy import displacy
from blackstone . displacy_palette import ner_displacy_options
nlp = spacy . load ( "en_blackstone_proto" )
text = """
The applicant must satisfy a high standard. This is a case where the action is to be tried by a judge with a jury. The standard is set out in Jameel v Wall Street Journal Europe Sprl [2004] EMLR 89, para 14:
“But every time a meaning is shut out (including any holding that the words complained of either are, or are not, capable of bearing a defamatory meaning) it must be remembered that the judge is taking it upon himself to rule in effect that any jury would be perverse to take a different view on the question. It is a high threshold of exclusion. Ever since Fox’s Act 1792 (32 Geo 3, c 60) the meaning of words in civil as well as criminal libel proceedings has been constitutionally a matter for the jury. The judge’s function is no more and no less than to pre-empt perversity. That being clearly the position with regard to whether or not words are capable of being understood as defamatory or, as the case may be, non-defamatory, I see no basis on which it could sensibly be otherwise with regard to differing levels of defamatory meaning. Often the question whether words are defamatory at all and, if so, what level of defamatory meaning they bear will overlap.”
18 In Berezovsky v Forbes Inc [2001] EMLR 1030, para 16 Sedley LJ had stated the test this way:
“The real question in the present case is how the courts ought to go about ascertaining the range of legitimate meanings. Eady J regarded it as a matter of impression. That is all right, it seems to us, provided that the impression is not of what the words mean but of what a jury could sensibly think they meant. Such an exercise is an exercise in generosity, not in parsimony.”
"""
doc = nlp ( text )
# Call displacy and pass `ner_displacy_options` into the option parameter`
displacy . serve ( doc , style = "ent" , options = ner_displacy_options )これは次のようなものを生成します:
Blackstoneのテキストカテゴリザーは、 docの予測された分類を生成します。 textcatパイプラインコンポーネントは、多くの文で構成される単一のドキュメントではなく、個々の文に適用されるように設計されています。
import spacy
# Load the model
nlp = spacy . load ( "en_blackstone_proto" )
def get_top_cat ( doc ):
"""
Function to identify the highest scoring category
prediction generated by the text categoriser.
"""
cats = doc . cats
max_score = max ( cats . values ())
max_cats = [ k for k , v in cats . items () if v == max_score ]
max_cat = max_cats [ 0 ]
return ( max_cat , max_score )
text = """
It is a well-established principle of law that the transactions of independent states between each other are governed by other laws than those which municipal courts administer.
It is, however, in my judgment, insufficient to react to the danger of over-formalisation and “judicialisation” simply by emphasising flexibility and context-sensitivity.
The question is whether on the facts found by the judge, the (or a) proximate cause of the loss of the rig was “inherent vice or nature of the subject matter insured” within the meaning of clause 4.4 of the Institute Cargo Clauses (A).
"""
# Apply the model to the text
doc = nlp ( text )
# Get the sentences in the passage of text
sentences = [ sent . text for sent in doc . sents ]
# Print the sentence and the corresponding predicted category.
for sentence in sentences :
doc = nlp ( sentence )
top_category = get_top_cat ( doc )
print ( f" " { sentence } " { top_category } n " )
> >> "In my judgment, it is patently obvious that cats are a type of dog." ( 'CONCLUSION' , 0.9990500807762146 )
> >> "It is a well settled principle that theft is wrong." ( 'AXIOM' , 0.556410014629364 )
> >> "The question is whether on the facts found by the judge, the (or a) proximate cause of the loss of the rig was “inherent vice or nature of the subject matter insured” within the meaning of clause 4.4 of the Institute Cargo Clauses (A)." ( 'ISSUE' , 0.5040785074234009 )コアモデルに加えて、Blackstoneのこのプロトリリースには3つのカスタムコンポーネントが付属しています。
AbbreviationDetector()コンポーネントに大きく基づいており、省略形式をその長い形式の定義、例えばECtHR > European Court of Human Rightsに解決します。CASENAMEとCITATIONペアを特定して、その親CASENAMEへのCITATIONのマージを可能にするアルファコンポーネントです。法的文書の著者が、文書の残りの部分を投げかける代わりに使用される長年の用語を略すことは珍しくありません。例えば、
欧州人権裁判所(「ECTHR」)は、欧州人権条約(「ECHR」)の申請を最終的に担当する裁判所です。
Blackstoneの略語検出コンポーネントは、ScispacyのAbbreviationDetector()のかつてないほど修正されたバージョンを実装することにより、これに対処しようとしています(これは、本書に記載されているアプローチの実装です:https.stanford.stanford.edu/psb-online/proceedings/psb03/schwartz.pdf)。私たちの実装にはまだいくつかの問題がありますが、その使用の例は次のとおりです。
import spacy
from blackstone . pipeline . abbreviations import AbbreviationDetector
nlp = spacy . load ( "en_blackstone_proto" )
# Add the abbreviation pipe to the spacy pipeline.
abbreviation_pipe = AbbreviationDetector ( nlp )
nlp . add_pipe ( abbreviation_pipe )
doc = nlp ( 'The European Court of Human Rights ("ECtHR") is the court ultimately responsible for applying the European Convention on Human Rights ("ECHR").' )
print ( "Abbreviation" , " t " , "Definition" )
for abrv in doc . _ . abbreviations :
print ( f" { abrv } t ( { abrv . start } , { abrv . end } ) { abrv . _ . long_form } " )
> >> "ECtHR" ( 7 , 10 ) European Court of Human Rights
>> > "ECHR" ( 25 , 28 ) European Convention on Human Rights Blackstoneの複合ケース参照検出コンポーネントは、親CASENAMEエンティティとCITATIONエンティティを結婚するように設計されています。
慣習法の管轄区域は、通常、名前の結合(通常はケースの当事者の名前から派生した)と、ケースが報告されている場所を特定するためのいくつかのユニークな引用を介したケース参照に関連しています。
レジーナvホーンキャッスル[2010] 2 AC 373
BlackstoneのNERモデルは、 CASENAMEとCITATIONエンティティを個別に識別しようとします。ただし、これらのエンティティをペアとして引き出すことは、潜在的に有用です(特に情報抽出のコンテキストでは)。
CompoundCases() 、NERの後にカスタムパイプを適用し、2つのシナリオでCASENAME / CITATIONペアを識別します。
import spacy
from blackstone . pipeline . compound_cases import CompoundCases
nlp = spacy . load ( "en_blackstone_proto" )
compound_pipe = CompoundCases ( nlp )
nlp . add_pipe ( compound_pipe )
text = "As I have indicated, this was the central issue before the judge. On this issue the defendants relied (successfully below) on the decision of the High Court in Gelmini v Moriggia [1913] 2 KB 549. In Jones' case [1915] 1 KB 45, the defendant wore a hat."
doc = nlp ( text )
for compound_ref in doc . _ . compound_cases :
print ( compound_ref )
> >> Gelmini v Moriggia [ 1913 ] 2 KB 549
>> > Jones ' case [ 1915 ] 1 KB 45BlackstoneのLegislation Linkerは、NERモデルを使用してINSTRUMENTの存在を識別し、依存関係ツリーをナビゲートして子の提供を識別することにより、その提供物へのPROVISIONをその親INSTRUMENTに結合しようとします。
BlackstoneがPROVISIONを特定すると、 INSTRUMENTペアが特定されると、Legislation.gov.ukの提供と機器の両方にターゲットURLを生成しようとします。
import spacy
from blackstone . utils . legislation_linker import extract_legislation_relations
nlp = spacy . load ( "en_blackstone_proto" )
text = "The Secretary of State was at pains to emphasise that, if a withdrawal agreement is made, it is very likely to be a treaty requiring ratification and as such would have to be submitted for review by Parliament, acting separately, under the negative resolution procedure set out in section 20 of the Constitutional Reform and Governance Act 2010. Theft is defined in section 1 of the Theft Act 1968"
doc = nlp ( text )
relations = extract_legislation_relations ( doc )
for provision , provision_url , instrument , instrument_url in relations :
print ( f" n { provision } t { provision_url } t { instrument } t { instrument_url } " )
> >> section 20 http : // www . legislation . gov . uk / ukpga / 2010 / 25 / section / 20 Constitutional Reform and Governance Act 2010 http : // www . legislation . gov . uk / ukpga / 2010 / 25 / contents
> >> section 1 http : // www . legislation . gov . uk / ukpga / 1968 / 60 / section / 1 Theft Act 1968 http : // www . legislation . gov . uk / ukpga / 1968 / 60 / contentsBlackstoneは、すぐにボックスの文のセグメンテーションルールを困惑させる傾向がある法的テキストに固有のさまざまな特性に対処するカスタムルールベースの文セグメンターを搭載しています。
この動作は、オプションで、一致内の文の境界検出を明示的に防止するスペイシースタイルのマッチャーパターンのリストを渡すことで拡張できます。
import spacy
from blackstone . pipeline . sentence_segmenter import SentenceSegmenter
from blackstone . rules import CITATION_PATTERNS
nlp = spacy . load ( "en_blackstone_proto" )
# add the Blackstone sentence_segmenter to the pipeline before the parser
sentence_segmenter = SentenceSegmenter ( nlp . vocab , CITATION_PATTERNS )
nlp . add_pipe ( sentence_segmenter , before = "parser" )
doc = nlp (
"""
The courts in this jurisdiction will enforce those commitments when it is legally possible and necessary to do so (see, most recently, R. (on the application of ClientEarth) v Secretary of State for the Environment, Food and Rural Affairs (No.2) [2017] P.T.S.R. 203 and R. (on the application of ClientEarth) v Secretary of State for Environment, Food and Rural Affairs (No.3) [2018] Env. L.R. 21). The central question in this case arises against that background.
"""
)
for sent in doc . sents :
print ( sent . text )このプロトタイプを構築するために(直接的または間接的に)私たちを助けてくれた以下の人々/組織に感謝したいと思います。