Blackstone هو نموذج ومكتبة Spacy لمعالجة نص قانوني طويل غير منظم. Blackstone هو مشروع بحثي تجريبي من تقارير مجلس القانون في إنجلترا ومختبر الأبحاث في إنجلترا وويلز ، ICLR & D. كتب بلاكستون دانييل هوادلي.
لماذا نبني بلاكستون؟
ما الذي يميز بلاكستون؟
الملاحظات وأشياء أخرى تستحق الإشارة إليها
تثبيت
تثبيت المكتبة
تثبيت نموذج Blackstone
حول النموذج
خط الأنابيب
اسم المعترف بالدخول
فئة النص
الاستخدام
تطبيق نموذج NER
تصور الكيانات
تطبيق نموذج مصفاة النص
ملحقات خط الأنابيب المخصصة
الاختصار وقرار تعريف الشكل الطويل
الاكتشافات المرجعية لحالة المركب
رابط التشريع
مقطع الجملة
شهدت السنوات القليلة الماضية زيادة في النشاط عند تقاطع القانون والتكنولوجيا. ومع ذلك ، في المملكة المتحدة ، حدث الجزء الأكبر من هذا النشاط في شركات المحاماة والسياقات التجارية الأخرى. وكانت نتيجة ذلك أنه على الرغم من عدم انتهاء موجة التنمية في مجال المعلوماتية القانونية ، إلا أنه لا يتم توفير أي من الأبحاث تقريبًا على أساس مفتوح المصدر.
علاوة على ذلك ، ركزت مبلغ الأبحاث في مجال المعلوماتية القانونية في المملكة المتحدة (سواء كانت مفتوحة أو مغلقة) على تطوير طلبات NLP لأتمتة العقود والمستندات القانونية الأخرى التي تعتبر معاملات في الطبيعة. هذا أمر مفهوم ، لأن المستفيدين الرئيسيين في أبحاث NLP القانونية في المملكة المتحدة هم شركات المحاماة ، ولا تميل شركات المحاماة إلى عدم العثور على أيديهم على وثائق المعاملات التي يمكن أن يتم تسخيرها كبيانات تدريب.
المشكلة ، كما نراها ، هي أن أبحاث NLP القانونية في المملكة المتحدة أصبحت تركز على الطلبات التجارية وأنه من المفيد إجراء الاستثمار في تطوير أبحاث NLP القانونية فيما يتعلق بالنصوص القانونية الأخرى ، مثل الأحكام والمقالات العلمية وحجج الهيكل العظمي والمرافعات.
ملحوظة! يوصى بشدة بتثبيت Blackstone في بيئة افتراضية! انظر هنا لمعرفة المزيد عن البيئات الافتراضية. يجب أن يكون Blackstone متوافقًا مع Python 3.6 وأعلى.
لتثبيت Blackstone اتبع هذه الخطوات:
الخطوة الأولى هي تثبيت المكتبة ، والتي تحتوي في الوقت الحالي على حفنة من مكونات Spacy المخصصة. تثبيت المكتبة مثل 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
إذا كنت تقوم بتطوير Blackstone ، فيمكنك التثبيت من مصدر مثل SO:
pip install --editable .
pip install -r dev-requirements.txt
هذا هو الإصدار الأول من Blackstone ، ومن الأفضل النظر إلى النموذج كنموذج أولي ؛ إنه أمر حول الحواف ويمثل الخطوة الأولى في برنامج أكبر من الأبحاث المفتوحة المصدر في NLP على النصوص القانونية التي يتم تنفيذها بواسطة ICLR & D.
مع هذا الطريق ، إليك مجموعة موجزة لما يحدث في نموذج Proto.
يحتوي نموذج Proto المدرج في هذا الإصدار على العناصر التالية في خط أنابيبه:
نظرًا لوجود ندرة بيانات تدريب جزء من الكتاب والتبعية للنص القانوني ، تم أخذ مكونات خط أنابيب tokenizer و tagger و parser من نموذج en_core_web_sm من Spacy. على العموم ، يبدو أن هذه المكونات تعمل في وظيفة لائقة ، ولكن سيكون من الجيد إعادة النظر في هذه المكونات مع بيانات التدريب المخصصة في مرحلة ما في المستقبل.
مكونات ner و textcat هي مكونات مخصصة مدربة خاصة بالنسبة لـ Blackstone.
تم تدريب مكون NER لنموذج Blackstone على اكتشاف أنواع الكيانات التالية:
| ent | اسم | أمثلة |
|---|---|---|
| caseName | أسماء الحالات | Eg Smith v Jones ، in re Jones ، في قضية جونز |
| اقتباس | الاستشهادات (معرفات فريدة للحالات المبلغ عنها وغير المبلغ عنها) | على سبيل المثال (2002) 2 cr app r 123 |
| أداة | الأدوات القانونية المكتوبة | مثل قانون السرقة لعام 1968 ، الاتفاقية الأوروبية لحقوق الإنسان ، CPR |
| رزق | الوحدة داخل أداة قانونية مكتوبة | على سبيل المثال القسم 1 ، المادة 2 (3) |
| محكمة | المحكمة أو المحكمة | مثل محكمة الاستئناف ، المحكمة العليا |
| يحكم على | إشارات إلى القضاة | على سبيل المثال eady J ، اللورد بينغهام من كورنهيل |
يأتي هذا الإصدار من Blackstone أيضًا مع فئة نصية. على النقيض من مكون NER (الذي تم تدريبه لتحديد الرموز المميزة وسلسلة الرموز المميزة) ، يصنف مصفوفة النص تمتد أطول من النص ، مثل الجمل.
تم تدريب فئة النص على تصنيف النص وفقًا لواحدة من خمس فئات حصرية متبادلة ، والتي هي على النحو التالي:
| قطة | وصف |
|---|---|
| البديهية | يبدو أن النص يفترض مبدأ راسخ |
| خاتمة | يبدو أن النص يصنع اكتشافًا أو عقدًا أو قرارًا أو استنتاجًا |
| مشكلة | يبدو أن النص يناقش مشكلة أو سؤال |
| Legal_test | يبدو أن الاختبار يناقش الاختبار القانوني |
| uncat | لا يندرج النص في واحدة من الفئات الأربع المذكورة أعلاه |
فيما يلي مثال على كيفية تطبيق النموذج على بعض النصوص المأخوذة من الفقرة 31 من حكم محكمة القسم في R (Miller) V وزير الخارجية للخروج من الاتحاد الأوروبي (Birnie Intervening) [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 مع مجموعة ممتازة من المرئيات ، بما في ذلك المرئيات للتنبؤ NER. يأتي 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 مع ثلاثة مكونات مخصصة:
AbbreviationDetector() في [scispacy] ويحل شكل مختصر إلى تعريفه الطويل ، على سبيل ECtHR - European Court of Human Rights .CASENAME CITATION مما يتيح دمج CITATION على CASENAME الوالد.ليس من غير المألوف بالنسبة لمؤلفي المستندات القانونية اختصار مصطلحات طويلة الأمد والتي سيتم استخدامها بدلاً من النموذج الطويل من خلال بقية المستند. على سبيل المثال،
المحكمة الأوروبية لحقوق الإنسان ("ECTHR") هي المحكمة المسؤولة في النهاية عن تطبيق الاتفاقية الأوروبية لحقوق الإنسان ("ECHR").
يسعى مكون الكشف عن الاختصار في Blackstone إلى معالجة هذا من خلال تنفيذ نسخة معدلة قليلاً من AbbreviationDetector() (والتي هي في حد ذاتها تنفيذ النهج المنصوص عليه في هذه الورقة: https://psb.stanford.edu/psb-online/proceditings/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 للزواج من كيانات CITATION مع كيانات CASENAME الأم.
تتعلق الولايات القضائية للقانون العام عادةً مراجع الحالة من خلال اقتران اسم (مشتقة عادة من أسماء الأطراف في القضية) وبعض الاقتباس الفريد لتحديد مكان الإبلاغ عن القضية ، مثل ذلك:
Regina v Horncastle [2010] 2 AC 373
يحاول نموذج Blackstone 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 يحاول رابط تشريع Blackstone إشارة إلى PROVISION INSTRUMENT الوالدين باستخدام نموذج NER لتحديد وجود INSTRUMENT ثم التنقل في شجرة التبعية لتحديد توفير الطفل.
بمجرد أن يحدد Blackstone 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يشحن Blackstone مع مقطع جملة مخصص يعتمد على القواعد يتناول مجموعة من الخصائص المتأصلة في النصوص القانونية التي تميل إلى محير قواعد تجزئة الجملة خارج الصندوق.
يمكن تمديد هذا السلوك من خلال تمرير قائمة أنماط المطابقة على طراز 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 )نود أن نشكر الأشخاص/المنظمات التالية الذين ساعدونا (بشكل مباشر أو غير مباشر) لبناء هذا النموذج الأولي.