แบล็กสโตนเป็นรูปแบบของเครื่องรางและห้องสมุดสำหรับการประมวลผลข้อความทางกฎหมายที่ไม่มีโครงสร้างแบบยาว แบล็กสโตนเป็นโครงการวิจัยเชิงทดลองจากการรายงานสภากฎหมายที่จัดตั้งขึ้นสำหรับห้องปฏิบัติการวิจัยของอังกฤษและเวลส์ ICLR & D Blackstone เขียนโดย Daniel Hoadley
ทำไมเราถึงสร้างแบล็กสโตน?
แบล็กสโตนพิเศษมีอะไรบ้าง?
การสังเกตและสิ่งอื่น ๆ ที่ควรสังเกต
การติดตั้ง
ติดตั้งไลบรารี
ติดตั้งรุ่นแบล็กสโตน
เกี่ยวกับโมเดล
ท่อ
ผู้จดจำเอนไซม์
นักหมวดหมู่ข้อความ
การใช้งาน
การใช้โมเดล ner
การแสดงภาพหน่วยงาน
การใช้โมเดล Categoriser ข้อความ
ส่วนขยายไปป์ไลน์ที่กำหนดเอง
ตัวย่อและความละเอียดการกำหนดรูปแบบยาว
การตรวจจับการอ้างอิงกรณีผสม
Linker กฎหมาย
เซ็กเมนต์ประโยค
หลายปีที่ผ่านมาได้เห็นกิจกรรมที่จุดตัดของกฎหมายและเทคโนโลยี อย่างไรก็ตามในสหราชอาณาจักรจำนวนมากของกิจกรรมนั้นเกิดขึ้นใน บริษัท กฎหมายและบริบทเชิงพาณิชย์อื่น ๆ ผลที่ตามมาก็คือแม้จะไม่มีการพัฒนาที่ไม่สิ้นสุดในพื้นที่ตามกฎหมาย แต่แทบจะไม่มีการวิจัยใด ๆ ที่มีอยู่บนพื้นฐานของโอเพ่นซอร์ส
ยิ่งไปกว่านั้นความสำคัญของการวิจัยในโดเมนตามกฎหมายของสหราชอาณาจักร (ไม่ว่าจะเป็นการเปิดหรือปิด) ได้เพ่งความสนใจไปที่การพัฒนาแอปพลิเคชัน NLP สำหรับการทำสัญญาอัตโนมัติและเอกสารทางกฎหมายอื่น ๆ ที่ทำธุรกรรมตามธรรมชาติ สิ่งนี้เป็นที่เข้าใจได้เนื่องจากผู้มีอุปการคุณหลักของการวิจัย NLP ทางกฎหมายในสหราชอาณาจักรเป็น บริษัท กฎหมายและ บริษัท กฎหมายมีแนวโน้มที่จะไม่พบว่าเป็นการยากที่จะได้รับเอกสารการทำธุรกรรมที่สามารถควบคุมได้เป็นข้อมูลการฝึกอบรม
ปัญหาดังที่เราเห็นคือการวิจัย NLP ทางกฎหมายในสหราชอาณาจักรได้เริ่มจดจ่อกับแอพพลิเคชั่นเชิงพาณิชย์และคุ้มค่าที่จะลงทุนในการพัฒนางานวิจัย NLP ทางกฎหมายที่มีอยู่เกี่ยวกับตำราทางกฎหมายอื่น ๆ เช่นการตัดสินบทความทางวิชาการข้อโต้แย้งโครงกระดูกและคำวิงวอน
บันทึก! ขอแนะนำอย่างยิ่งให้คุณติดตั้งแบล็กสโตนในสภาพแวดล้อมเสมือนจริง! ดูที่นี่สำหรับข้อมูลเพิ่มเติมเกี่ยวกับสภาพแวดล้อมเสมือนจริง แบล็กสโตนควรเข้ากันได้กับ Python 3.6 ขึ้นไป
ในการติดตั้ง Blackstone ทำตามขั้นตอนเหล่านี้:
ขั้นตอนแรกคือการติดตั้งไลบรารีซึ่งในปัจจุบันมีส่วนประกอบของเครื่องร่องที่กำหนดเองจำนวนหนึ่ง ติดตั้งไลบรารีเช่น So:
pip install blackstone
ขั้นตอนที่สองคือการติดตั้งโมเดล Spacy ติดตั้งรุ่นเช่น SO:
pip install https://blackstone-model.s3-eu-west-1.amazonaws.com/en_blackstone_proto-0.0.1.tar.gz
หากคุณกำลังพัฒนาแบล็กสโตนคุณสามารถติดตั้งได้จากแหล่งที่มาเช่นนั้น:
pip install --editable .
pip install -r dev-requirements.txt
นี่คือการเปิดตัวครั้งแรกของแบล็กสโตนและแบบจำลองนั้นถูกมองว่า เป็นต้นแบบ ที่ดีที่สุด มันคร่าวๆรอบ ๆ ขอบและแสดงถึงขั้นตอนแรกในโปรแกรมการวิจัยโอเพนซอร์สที่มีขนาดใหญ่ขึ้นอย่างต่อเนื่องใน NLP เกี่ยวกับข้อความทางกฎหมายที่ดำเนินการโดย ICLR & D
เมื่อไม่นานมานี้นี่เป็นบทสรุปสั้น ๆ ของสิ่งที่เกิดขึ้นในโมเดลโปรโต
โมเดลโปรโตที่รวมอยู่ในรุ่นนี้มีองค์ประกอบต่อไปนี้ในท่อ:
เนื่องจากความขาดแคลนข้อมูลการฝึกอบรมส่วนหนึ่งและการพึ่งพาที่มีป้ายกำกับสำหรับข้อความทางกฎหมายส่วนประกอบ tokenizer tagger และ parser ได้ถูกนำมาจากโมเดล en_core_web_sm ของ Spacy ส่วนประกอบเหล่านี้ดูเหมือนจะทำงานได้ดี แต่ก็เป็นการดีที่จะทบทวนส่วนประกอบเหล่านี้ด้วยข้อมูลการฝึกอบรมที่กำหนดเองในบางจุดในอนาคต
ส่วนประกอบ ner และ textcat เป็นส่วนประกอบที่กำหนดเองที่ได้รับการฝึกฝนโดยเฉพาะอย่างยิ่งสำหรับ Blackstone
ส่วนประกอบ NER ของโมเดลแบล็กสโตนได้รับการฝึกฝนให้ตรวจจับประเภทเอนทิตีต่อไปนี้:
| ความรู้สึก | ชื่อ | ตัวอย่าง |
|---|---|---|
| casename | ชื่อเคส | เช่น Smith v Jones ใน Re Jones ในกรณี ของ Jones |
| การอ้างอิง | การอ้างอิง (ตัวระบุที่ไม่ซ้ำกันสำหรับกรณีที่รายงานและไม่ได้รายงาน) | เช่น (2002) 2 Cr App R 123 |
| อุปกรณ์ | เครื่องมือทางกฎหมายเป็นลายลักษณ์อักษร | เช่นพระราชบัญญัติการโจรกรรม 2511 อนุสัญญายุโรปว่าด้วยสิทธิมนุษยชน CPR |
| ข้อกำหนด | หน่วยภายในเครื่องมือทางกฎหมายเป็นลายลักษณ์อักษร | เช่นส่วนที่ 1, ศิลปะ 2 (3) |
| ศาล | ศาลหรือศาล | เช่นศาลอุทธรณ์ศาล |
| ผู้พิพากษา | การอ้างอิงถึงผู้พิพากษา | เช่น Eady J, Lord Bingham แห่ง Cornhill |
แบล็กสโตนรุ่นนี้มาพร้อมกับหมวดหมู่ข้อความ ในทางตรงกันข้ามกับองค์ประกอบของ NER (ซึ่งได้รับการฝึกอบรมเพื่อระบุโทเค็นและชุดโทเค็นที่น่าสนใจ) ผู้จัดหมวดหมู่ข้อความจำแนกประเภทข้อความที่ยาวขึ้นเช่นประโยค
หมวดหมู่ข้อความได้รับการฝึกฝนให้จำแนกประเภทข้อความตามหนึ่งในห้าหมวดหมู่ร่วมกันซึ่งมีดังนี้:
| แมว | คำอธิบาย |
|---|---|
| สัจพจน์ | ข้อความดูเหมือนจะอ้างถึงหลักการที่ได้รับการยอมรับอย่างดี |
| บทสรุป | ข้อความดูเหมือนจะทำการค้นพบการถือครองการตัดสินใจหรือข้อสรุป |
| ปัญหา | ข้อความดูเหมือนจะหารือเกี่ยวกับปัญหาหรือคำถาม |
| legal_test | การทดสอบดูเหมือนจะหารือเกี่ยวกับการทดสอบทางกฎหมาย |
| ทำให้ไม่ได้ | ข้อความไม่ได้ตกอยู่ในหนึ่งในสี่หมวดหมู่ด้านบน |
นี่คือตัวอย่างของวิธีการใช้แบบจำลองกับข้อความบางส่วนที่นำมาจากวรรค 31 ของคำพิพากษาของศาลใน R (มิลเลอร์) v เลขาธิการแห่งรัฐสำหรับการออกจากสหภาพยุโรป (Birnie แทรกแซง) [2017] UKSC 5; [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 เรือที่มีชุด Visualisers ที่ยอดเยี่ยมรวมถึง Visualiser สำหรับ NER ทำนาย แบล็กสโตนมาพร้อมกับจานสีที่กำหนดเองที่สามารถใช้เพื่อให้ง่ายต่อการกระจายเอนทิตีในข้อความต้นฉบับเมื่อใช้ความไม่พอใจ
"""
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 )ซึ่งสร้างสิ่งที่มีลักษณะเช่นนี้:
หมวดหมู่ข้อความของแบล็กสโตนสร้างการจัดหมวดหมู่ที่คาดการณ์ไว้สำหรับ 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 )นอกเหนือจากโมเดลหลักแล้วการเปิดตัวโปรโตของแบล็กสโตนนี้มาพร้อมกับสามองค์ประกอบที่กำหนดเอง:
AbbreviationDetector() ใน [scispacy] และแก้ไขรูปแบบตัวย่อตามคำจำกัดความรูปแบบยาวเช่น ECtHR -> European Court of Human RightsCASENAME และ CITATION ที่ช่วยให้การรวม CITATION ไปยัง CASENAME แม่ของมันไม่ใช่เรื่องแปลกสำหรับผู้เขียนเอกสารทางกฎหมายที่จะย่อคำที่ยืดยาวซึ่งจะใช้แทนการทำเอกสารที่เหลือยาวของเอกสาร ตัวอย่างเช่น,
ศาลสิทธิมนุษยชนแห่งยุโรป ("ECTHR") เป็นศาลในที่สุดรับผิดชอบในการใช้อนุสัญญายุโรปว่าด้วยสิทธิมนุษยชน ("ECHR")
ส่วนประกอบการตรวจจับตัวย่อใน Blackstone พยายามที่จะแก้ไขปัญหานี้โดยใช้ AbbreviationDetector() ซึ่งเป็นการดำเนินการตามวิธีการที่กำหนดไว้ในบทความนี้: https://psb.stanford.edu/psb-online/proceedings/psb03/schwartz. การดำเนินการของเรายังคงมีปัญหาบางอย่าง แต่ตัวอย่างของการใช้งานมีดังนี้:
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 ส่วนประกอบการตรวจจับการอ้างอิงกรณีแบบผสมในแบล็กสโตนได้รับการออกแบบมาเพื่อแต่งงานกับหน่วยงาน CITATION กับเอนทิตี CASENAME หลักของพวกเขา
เขตอำนาจศาลทั่วไปมักเกี่ยวข้องกับการอ้างอิงกรณีผ่านการมีเพศสัมพันธ์ของชื่อ (โดยทั่วไปจะได้มาจากชื่อของคู่สัญญาในกรณี) และการอ้างอิงที่ไม่ซ้ำกันบางอย่างเพื่อระบุตำแหน่งที่รายงานคดีเช่น:
Regina v Horncastle [2010] 2 AC 373
โมเดล NER ของแบล็กสโตนแยกความพยายามที่จะระบุตัวตนของ CASENAME และ CITATION อย่างไรก็ตามมันอาจเป็นประโยชน์ (โดยเฉพาะอย่างยิ่งในบริบทของการสกัดข้อมูล) เพื่อดึงเอนทิตีเหล่านี้ออกเป็นคู่
CompoundCases() ใช้ท่อที่กำหนดเองหลังจาก NER และระบุคู่ 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 45 Linker กฎหมายของ Blackstone พยายามที่จะจับคู่การอ้างอิงถึง PROVISION ของ INSTRUMENT หลักโดยใช้แบบจำลอง NER เพื่อระบุการมีอยู่ของ INSTRUMENT จากนั้นนำทางต้นไม้พึ่งพาเพื่อระบุบทบัญญัติของเด็ก
เมื่อแบล็กสโตนระบุ PROVISION : คู่ INSTRUMENT มันจะพยายามสร้าง URL เป้าหมายให้กับทั้งบทบัญญัติและเครื่องมือในการออกกฎหมาย gov.uk
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 / contentsแบล็กสโตนจัดส่งด้วยเซ็กเมนต์ประโยคตามกฎที่กำหนดเองซึ่งระบุถึงคุณสมบัติที่หลากหลายในข้อความทางกฎหมายที่มีแนวโน้มที่จะทำให้ยุ่งเหยิงกฎการแบ่งส่วนประโยคนอกกรอบ
พฤติกรรมนี้สามารถขยายออกไปได้โดยการเลือกรายการรูปแบบการจับคู่สไตล์ Spacy ซึ่งจะป้องกันการตรวจจับขอบเขตประโยคภายในการแข่งขันอย่างชัดเจน
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 )เราขอขอบคุณผู้คน/องค์กรต่อไปนี้ที่ช่วยเรา (โดยตรงหรือโดยอ้อม) เพื่อสร้างต้นแบบนี้