Blackstone adalah model spacy dan perpustakaan untuk memproses teks hukum yang tidak terstruktur. Blackstone adalah proyek penelitian eksperimental dari Laboratorium Penelitian Dewan Hukum Incorporated untuk Lab Penelitian Inggris dan Wales, ICLR&D. Blackstone ditulis oleh Daniel Hoadley.
Mengapa kita membangun Blackstone?
Apa yang istimewa dari Blackstone?
Pengamatan dan hal -hal lain yang patut dicatat
Instalasi
Instal perpustakaan
Pasang model Blackstone
Tentang model
Pipa
Pengakuan Nama-Entity
Kategoriser teks
Penggunaan
Menerapkan model NER
Memvisualisasikan entitas
Menerapkan model kategoriser teks
Ekstensi pipa khusus
Singkatan dan resolusi definisi panjang
Deteksi referensi kasus majemuk
Penghubung undang -undang
Segmenter Kalimat
Beberapa tahun terakhir telah melihat lonjakan aktivitas di persimpangan hukum dan teknologi. Namun, di Inggris, sebagian besar kegiatan itu telah terjadi di firma hukum dan konteks komersial lainnya. Konsekuensi dari ini adalah bahwa terlepas dari kesibukan pembangunan yang tidak pernah berakhir di ruang-diformatika legal, hampir tidak ada penelitian yang tersedia berdasarkan sumber terbuka.
Selain itu, jurusan penelitian dalam domain hukum-informatika Inggris (baik terbuka atau tertutup) telah berfokus pada pengembangan aplikasi NLP untuk mengotomatisasi kontrak dan dokumen hukum lainnya yang bersifat transaksional. Ini dapat dimengerti, karena dermawan utama penelitian NLP hukum di Inggris adalah firma hukum dan firma hukum cenderung tidak merasa sulit untuk mendapatkan dokumentasi transaksional yang dapat dimanfaatkan sebagai data pelatihan.
Masalahnya, seperti yang kita lihat, adalah bahwa penelitian NLP hukum di Inggris telah menjadi terlalu terkonsentrasi pada aplikasi komersial dan bahwa ada baiknya melakukan investasi dalam mengembangkan penelitian NLP hukum yang tersedia sehubungan dengan teks hukum lainnya, seperti penilaian, artikel ilmiah, argumen kerangka dan pembelaan.
Catatan! Sangat disarankan agar Anda memasang Blackstone ke lingkungan virtual! Lihat di sini untuk lebih lanjut tentang lingkungan virtual. Blackstone harus kompatibel dengan Python 3.6 dan lebih tinggi.
Untuk menginstal Blackstone ikuti langkah -langkah ini:
Langkah pertama adalah menginstal perpustakaan, yang saat ini berisi beberapa komponen spacy khusus. Instal perpustakaan seperti itu:
pip install blackstone
Langkah kedua adalah menginstal model spacy. Instal model seperti itu:
pip install https://blackstone-model.s3-eu-west-1.amazonaws.com/en_blackstone_proto-0.0.1.tar.gz
Jika Anda mengembangkan Blackstone, Anda dapat menginstal dari sumber seperti itu:
pip install --editable .
pip install -r dev-requirements.txt
Ini adalah rilis pertama Blackstone dan model ini paling baik dipandang sebagai prototipe ; Ini kasar di sekitar tepi dan mewakili langkah pertama dalam program penelitian open source yang lebih besar tentang NLP tentang teks -teks hukum yang dilakukan oleh ICLR&D.
Dengan itu, inilah ikhtisar singkat tentang apa yang terjadi dalam model proto.
Model proto yang termasuk dalam rilis ini memiliki elemen -elemen berikut dalam pipa:
Karena kelangkaan data pelatihan sebagian berlabel dan ketergantungan untuk teks hukum, komponen pipa tokenizer , tagger , dan parser telah diambil dari model en_core_web_sm Spacy. Pada umumnya, komponen -komponen ini tampaknya melakukan pekerjaan yang layak, tetapi akan lebih baik untuk meninjau kembali komponen -komponen ini dengan data pelatihan khusus di beberapa titik di masa depan.
Komponen ner dan textcat adalah komponen khusus yang dilatih terutama untuk Blackstone.
Komponen NER dari model Blackstone telah dilatih untuk mendeteksi jenis entitas berikut:
| Ent | Nama | Contoh |
|---|---|---|
| Casename | Nama kasus | misalnya Smith v Jones , di Re Jones , dalam kasus Jones |
| KUTIPAN | Kutipan (pengidentifikasi unik untuk kasus yang dilaporkan dan tidak dilaporkan) | misalnya (2002) 2 CR App R 123 |
| INSTRUMEN | Instrumen hukum tertulis | misalnya Undang -Undang Pencurian 1968, Konvensi Hak Asasi Manusia Eropa, CPR |
| PERSEDIAAN | Unit dalam instrumen hukum tertulis | misalnya Bagian 1, Pasal 2 (3) |
| PENGADILAN | Pengadilan atau pengadilan | misalnya Pengadilan Banding, Pengadilan Atas |
| HAKIM | Referensi kepada Hakim | misalnya Eady J, Lord Bingham dari Cornhill |
Rilis Blackstone ini juga dilengkapi dengan kategoriser teks. Berbeda dengan komponen NER (yang telah dilatih untuk mengidentifikasi token dan serangkaian token yang menarik), kategoriser teks mengklasifikasikan rentang teks yang lebih lama, seperti kalimat.
Kategoriser teks telah dilatih untuk mengklasifikasikan teks menurut salah satu dari lima kategori yang saling eksklusif, yaitu sebagai berikut:
| Kucing | Keterangan |
|---|---|
| AKSIOMA | Teks tersebut muncul untuk mendalilkan prinsip yang mapan |
| KESIMPULAN | Teks tampaknya membuat temuan, memegang, tekad atau kesimpulan |
| MASALAH | Teks tampaknya membahas masalah atau pertanyaan |
| Legal_test | Tes tampaknya membahas tes hukum |
| Uncat | Teks tidak termasuk dalam salah satu dari empat kategori di atas |
Berikut adalah contoh bagaimana model ini diterapkan pada beberapa teks yang diambil dari paragraf 31 dari putusan pengadilan divisi dalam R (Miller) v Sekretaris Negara karena keluar dari Uni Eropa (Birnie Intervence) [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 Kapal Spacy dengan satu set visualiser yang sangat baik, termasuk visualiser untuk prediksi NER. Blackstone hadir dengan palet warna khusus yang dapat digunakan untuk membuatnya lebih mudah untuk mendistigu entitas pada teks sumber saat menggunakan Deplacy.
"""
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 )Yang menghasilkan sesuatu yang terlihat seperti ini:
Kategoriser teks Blackstone menghasilkan kategorisasi yang diprediksi untuk doc . Komponen pipa textcat telah dirancang untuk diterapkan pada kalimat individual daripada satu dokumen tunggal yang terdiri dari banyak kalimat.
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 )Selain model inti, rilis proto Blackstone ini hadir dengan tiga komponen khusus:
AbbreviationDetector() dalam [scispacy] dan menyelesaikan bentuk singkatan dari definisi bentuk panjangnya, misalnya ECtHR -> European Court of Human Rights .CASENAME dan CITATION yang memungkinkan penggabungan CITATION untuk CASENAME induknya.Tidak jarang bagi penulis dokumen hukum untuk menyingkat istilah bertele-tele yang akan digunakan sebagai ganti bentuk panjang melalui dokumen lainnya. Misalnya,
Pengadilan Hak Asasi Manusia Eropa ("ECTHR") adalah pengadilan yang pada akhirnya bertanggung jawab untuk menerapkan Konvensi Eropa tentang Hak Asasi Manusia ("ECHR").
Komponen deteksi singkatan di Blackstone berupaya untuk membahas ini dengan menerapkan versi yang sedikit dimodifikasi dari scispacy's AbbreviationDetector() (yang merupakan implementasi dari pendekatan yang ditetapkan dalam makalah ini: https://psb.stanford.edu/psb-online/proedings/psb03/schwartz.pdf). Implementasi kami masih memiliki beberapa masalah, tetapi contoh penggunaannya adalah sebagai berikut:
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 Komponen Deteksi Referensi Kasus Senyawa di Blackstone dirancang untuk menikahi entitas CITATION dengan entitas CASENAME induknya.
Yurisdiksi hukum umum biasanya berkaitan dengan referensi kasus melalui penggabungan nama (biasanya berasal dari nama -nama pihak dalam kasus ini) dan beberapa kutipan unik untuk mengidentifikasi di mana kasus tersebut telah dilaporkan, seperti itu:
Regina v Horncastle [2010] 2 AC 373
Model NER Blackstone secara terpisah berupaya mengidentifikasi CASENAME dan entitas CITATION . Namun, berpotensi berguna (terutama dalam konteks ekstraksi informasi) untuk menarik entitas ini sebagai pasangan.
CompoundCases() menerapkan pipa khusus setelah NER dan mengidentifikasi pasangan CASENAME / CITATION dalam dua skenario:
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 Penghubung undang -undang Blackstone mencoba memasangkan referensi ke PROVISION untuk INSTRUMENT induknya dengan menggunakan model NER untuk mengidentifikasi keberadaan INSTRUMENT dan kemudian menavigasi pohon ketergantungan untuk mengidentifikasi ketentuan anak.
Setelah Blackstone mengidentifikasi PROVISION : pasangan INSTRUMENT , ia akan berusaha untuk menghasilkan URL target untuk ketentuan dan instrumen pada legislasi.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 / contentsBlackstone mengirim dengan segmentasi kalimat berbasis aturan khusus yang membahas berbagai karakteristik yang melekat dalam teks-teks hukum yang memiliki kecenderungan untuk membingungkan aturan segmentasi kalimat di luar kotak.
Perilaku ini dapat diperluas dengan secara opsional melewati daftar pola pencocokan gaya spacy yang secara eksplisit akan mencegah deteksi batas kalimat di dalam pertandingan.
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 )Kami ingin mengucapkan terima kasih kepada orang -orang/organisasi berikut yang telah membantu kami (secara langsung atau tidak langsung) untuk membangun prototipe ini.