Docsity

Techical report summ, Summaries of Information Integration

Partial preview of the text

Download Techical report summ and more Summaries Information Integration in PDF only on Docsity!

Technical report of the ERC

project HyperModeLex

Hyperdimensional Modelling of the Legal System in Digital Society

Michele Corazza, Monica Palmirani, University of Bologna

Chapter 1

Introduction

The subject of this technical report is the discussion of our progress in creating tools to aid the legislative process in the context of European institutions and European Member States. The legislative process is a complex task, which involves a multitude of goals that need to be addressed before and during the drafting and discussion of any piece of legislation. Typically, one of the more demanding aspects is the discovery of existing regulation on a given subject, which in the case of a European country involves an examination of documents from a multitude of institutions: the existing national legislation, European legislation, the constitution and judgments from the national Constitutional Court or equivalent institutions. With respect to the heterogeneous sources, there are legal theory principles that need to be considered, which also create a hierarchy of legal sources:

  • Lex superior derogat inferiori : there is a hierarchy between the legal sources. For example, an EU regulation is directly enforceable in Member states, and a new law should not violate constitutional principles;
  • Lex specialis derogat legi generali: a process of increased specification can happen, so that a more specific law is approved on a subject that already has some legislation about it. In this case, the more specific provisions will alter the existing law in the relevant portions.
  • Lex posterior derogat legi priori : there is a temporal component that needs to be considered when a new law is approved. In general, new laws can supersede previous ones.

Another aspect of the discovery of existing legislation is an analysis of poli- cies, or goals that a specific institutions aims to achieve with his legislative efforts. In this context, one of the subjects examined in this report regards the Sustainable Development Goals program from the United Nations. These are 17 global goals adopted by all the United Nation members in 2015, and their goal is to promote “peace and prosperity for people and the planet”. With these goals

Chapter 2

Large Language Model for the

legislative process

One of the goals of our research is the creation of a large language model (LLM) for the legislative process. While it would be possible to define many different tasks for such a model, our first use case is the automatic generation of preambles in European legislative documents. The choice of preambles is motivated by the idea that these are portions of documents that are less normative than others, therefore they can be generated by an automatic process with a smaller impact on the autonomy of the European institutions. In general, the naif application of a LLM to generate any portion of a legisla- tive documents is not a sound approach. This is because, even in the presence of a very accurate model, the documents that are in force change over time, with amendments, abrogations, new norms entering into force all the time. This is motivated by the fact that LLMs are only aware of documents that they have previously been trained on. For this reason, it is crucial to devise a method of Retrieval Augmented Generation, often abbreviated to RAG [1], which is an approach where relevant information is retrieved before prompting the model, allowing the LLM to leverage relevant information that is provided before gen- erating an answer. This would allow the model to be aware of all the recent changes to the existing legislation, even when said changes are not part of its training set. For this reason, a preliminary goal of our approach is to create a Transformer model which is able to retrieve relevant legislative documents to allow an LLM to generate preambles.

2.1 Objectives and Challenges

In order to generate preambles, the most relevant objectives of a retrieval model should be the normative references that are included in citations, which are needed in order to allow the model to include them in the generated document without generating spurious or out-of-date references (hallucinations). Since

the application of transformer models to large collections of data is expensive, it is not feasible to apply a model to the existing documents each time the user asks for relevant references for a new normative document, since this would require a lot of computational power to compare the query to tens of thousands of documents. For this reason, our goal is to create a model that creates vector representations for documents which support the application of a distance or similarity metric, so that the comparison between a user query and the existing documents is an operation on a vector database, not involving expensive models. The results can then be improved by using a cross-encoder for re-ranking [2] to further improve the performance of the model. To create a retrieval model for legislative documents, there are a number of challenges that need to be addressed, which involve a multitude of peculiari- ties of legislative documents. These challenges do not allow the straightforward application of an existing model, and they require different solutions. One of the challenges of treating legislative documents is the fact that there are infor- mation about said documents which are not included when considering only a plain text representation of their content. In particular, legislative documents are structured in a hierarchical way, where for example and article is composed of multiple paragraphs, and some of them might include lists of points or sub- paragraphs. In addition to these structural aspects of the document, another challenge is the fact that information about context is also a challenging as- pect of these types of documents: the jurisdiction and temporal parameters of a normative document are generally represented in text, but they might be missed by an encoder model. Finally, the usage of normative references is also problematic from the point of view of any language model that aims to perform some tasks on legislative document. As an example, in European directives and regulations it is frequent to find definitions that have the form: “(50) ‘personal data’ means personal data as defined in Article 4, point (1), of Regulation (EU) 2016/679;”. In these instances, the definition of ‘personal data’ is defined from a normative reference (in this case the GDPR), meaning that we are not able to represent the actual definition without resolving the normative reference first. For these reasons, our aim is to create a model which leverages the information contained in the Akoma Ntoso XML standard [3, 4], which has been adopted by a multitude of international institution [5, 6, 7, 8, 9] and which is able to represent all the relevant information about legal documents (temporal aspects, normative references, structure of the document, etc). For these reasons, both the retrieval model and the LLM should operate on Akoma Ntoso documents and not plain text ones. Another challenge that emerges when applying any LLM or transformer model to normative documents is the fact that most models operate on relatively short sequences of text, since the attention mechanism behind transformers has a memory cost that is quadratic in the length of the input. With longer sequences, the naif application of the quadratic multi-head attention which is present both in encoder and decoder models becomes unfeasible. This is especially critical for encoder model, which typically operate on very short sequences of 512 tokens maximum. In this context, a visualization of the length of normative documents

the j-th reference present in fragment i. We also denote as tij the position of the [REF] token corresponding to Rij in the sequence of tokens of fragment fi. The referenced document is then chunked in different fragments, which we denote as rij 1 ,... , rijn. The local references model is applied to the various fragments as follows: erijh = LR(rijh) (2.1)

Where Lr is an encoder model (in our experiments we are using RoBERTa) which we call the local references model, which returns a vector represen- tation for the sequence. We denote as eRij the concatenation of all the vector representations of the reference fragments:

eRij =

M^ n

h=

erijh erijh ∈ R^1 ×es^ (2.2)

Where

L

denotes the concatenation of vectors along their first dimension. In order to use the resulting vectors in a global model, we first need to insert the [SEP] and [CLS] tokens that are used at the beginning and end of the sequences in BERT and other encoders, which we denote using the BERT nomenclature for clarity. The presence of these special tokens is crucial, as it allows the model to understand where sequences begin and end. These tokens are represented using their embedding, which are derived from the embedding layer of the global references model GR. Given the sequence of local embeddings eRij we produce the inputs for the global model as follows:

IRij = eg ([CLS]) ⊕ eRij ⊕ eg ([SEP ]) (2.3)

Where eg represents an embedding layer, and [CLS], [SEP ] represent the index assigned to the [CLS] and [SEP] tokens used in encoders. Then, it is possible to apply the global model to the vector to obtain a vector representation for an entire document: DRij = GR(IRij ) (2.4)

Where GR is an encoder model, the global references model, which does not use an embedding layer, instead it only applies positional embeddings to the existing embeddings (IRij ). The next step for the encoding of entire document is to incorporate information about normative references in the overall repre- sentation of the document. For this purpose, we devised a method that uses the vector representation for the references DRij as one of the inputs for the representation of the document. For a given fragment fi we first produce the embeddings for its tokens using an embedding layer:

Efi = el(fi) (2.5)

In order to correctly position the references, we move each reference in the position of the corresponding [REF] token in a matrix which we call ER:

ER = (hij ) (2.6)

hij =

DRik ∃k tik = j 0 otherwise

Figure 2.2: The procedure used to include information about references in the vector representation of documents

Furthermore, we produce a mask MR which contains 0 only when the corre- sponding token is a reference, 1 elsewhere:

MR = (mij ) (2.8)

mij =

0 , ∃h tih = j 1 otherwise

Then, it is possible to combine the embeddings Ef i with the matrix as follows:

E^ ˆf i = Efi ⊙ MR + ER (2.10)

Where ⊙ denotes the Hadamard product (element-wise product) of the two ma- trices. The resulting embeddings Eˆf i have the desired properties: they encode normative references as inputs to the model and their position in the text is still considered. The overall procedure used to represent references inside the input is shown in Figure 2.2. From the embeddings Eˆf i we can then apply a local model as follows:

eFi = LD ( Eˆf i) (2.11)

Where LD is an encoder model which does not apply an embedding layer and which returns a vector representation of the entire sequence. The resulting representations for the fragments are then combined as follows, in the same way that reference fragment embeddings were combined in equation 2.3:

Id = eG([CLS]) ⊕ eFi ⊕ eG([SEP ]) (2.12)

Figure 2.4: The fine-tuning procedure using the Masked Language Modeling training objective

the first dimension:

C = (LD (p 1 ),... , Ld(pbs)) ⊕ (LD (n 1 ),... , Ld(nbs)) (2.14)

We also compute the title embedding from the global model:

T^ ˆ = GD (T ) (2.15)

We can then compute the cosine similarity matrix between the title embed- dings and the positive and negative samples as follows:

S = λ

T Cˆ T

| Tˆ ||C|

Where |T | denotes the l2 norm of each row of a matrix and the fraction is also applied row-wise, λ is an integer value used to scale the cosine similarity. Since the positive samples appear before the negative samples, we can calculate some labels which inform us of where to find the relevant document for each title:

y = diag(1, 2 ,... , bs) (2.17)

Which represents a matrix where only the diagonal contains positive numbers, while the rest of the matrix is set to 0. Finally, we can define the loss function

in terms of cross-entropy as follows:

L(T, S) =

bs

Xbs

i=

log

exp Si Pbs j=0 exp^ Sj

y (2.18)

Which attempts to condition the model to produce title vectors which are most similar with positive sample embeddings (cosine similarity of 1), while title em- beddings and negative sample embeddings should be orthogonal (cosine similar- ity of 0). The procedure used to train the model is shown in Figure 2.4. Finally by applying this procedure, we are able to train a model that can handle very long sequences of tokens ( 5122 = 262k), which can include information about normative references in its representation of documents, and that is suitable to perform information retrieval for the generation of preambles.

2.3 Document Chunking Strategy

In order to perform the chunking of documents required for the model, we could use a simple sentence-based approach, where we would segment the document in sentences and use those as fragments for the local models. However, thanks to the structural information provided by the Akoma Ntoso XML format, it is possible to leverage this information to produce fragments that follow the structure of the document itself.

Figure 2.5: An example of the application of our Akoma-Ntoso informed chunk- ing procedure.

In order to achieve this goal, we adopted a greedy algorithm, which operates by traversing the XML tree using a depth-first approach (which coincides with processing the XML elements in sequence). First, we start to segment from the beginning of the document (the first token) and establish a token limit of 512 for our approach, which is the maximum allowed length for BERT and similar

aware, meaning that it is able to consider the content of normative references when producing the vector representation of a model. Finally, the result of the application of the model is a vector representation for each document, which can be compared with the title of the norm being created by just applying cosine similarity to their vector representations. This approach has relatively small requirements in terms of computational cost. In terms of the current progress, first we managed to collect a corpus of ap- proximately 40k EU legislative documents in the Akoma Ntoso format, which in terms of files size corresponds to 3.8 GiB. In an effort to reduce the number of tokens per document and to discard less relevant information we proceeded to exclude many different types of data and metadata for our experiments (tables, annexes, attachments, lifecycles, proprietary, restrictions, etc). This resulted in a marked reduction in the overall size of the dataset, which is now of approx- imately 2.0 GiB. The entire model is ready, but we are still testing whether it behaves as expected by applying it to a standard Information Retrieval dataset, The Stanford Question Answering Dataset 2.0 [14, 15], before reintroducing all the complexities which are connected with the legal domain. Meanwhile, we are investigating ways to reduce the memory requirements of the model such as reducing the vocabulary size of the global models to only include [CLS] and [SEP]. For the local models, we are also investigating more advanced vocabu- lary transfer techniques [16] in order to reduce the number of tokens for our documents.

Chapter 3

Hybrid classification of

Sustainable Development

Goals in European legislative

documents

The Sustainable Development Goals (SDGs) were adopted by the UN assembly in 2015 and they are composed by 17 goals and 169 targets, typically 12 to 15 for each goal. Our goal is to adopt an unsupervised hybrid classification framework to match existing legislative documents from the EU with SDG targets, pro- ducing a fine-grained classification of articles. This approach allows an ex-ante analysis of drafts, which can help the legislative efforts by checking whether new legislation is in line with the policies outlined by the SDGs. Crucially, the same analysis can also be applied ex-post, allowing a more long-term analysis of the merits and shortcomings of existing legislation with respect to the SDGs. The Joint Research Center (JRC) of the European Commission recognized the importance of matching JRC with existing legislation, and for this reason a manual annotation of legislative documents has been performed starting in

  1. This annotation effort was applied to actions from the Juncker commis- sion (2014-2019) so that all document were clearly annotated with one or more SDG goals [17]. While the effort to map EU legislation with SDG targets, con- tinues, the von der Leyen commission opted to perform an automatic annotation of the documents, which allowed the creation of a second, manually annotated, matching between SDG and EU legislative documents. Both annotations can be found at https://knowsdgs.jrc.ec.europa.eu/policies-sdgs, where “pre- vious initiatives” corresponds to the Juncker commission’s manual annotation, while “current initiatives” is the current effort to annotate documents automat- ically. Crucially, both the manual and automatic annotations only examined the

In Figure 3.1, we show the number of documents that have been annotated with each one of the 17 SDG goals. From this image, it is clear that all goals are represented in our dataset, but there are strong differences in their prevalence in our dataset. In particular, the second goal (“end hunger, achieve food security and improved nutrition and promote sustainable agriculture”) is very prominent in EU legislative documents, appearing in more than 20% of the documents, and goal 16 (“promote peaceful and inclusive societies for sustainable development, provide access to justice for all and build effective, accountable and inclusive institutions at all levels”) is also relatively prominent, encompassing more than 10% of the documents. On the other hand, the least attested goal is number 5 (“achieve gender equality and empower all women and girls”), found in less than 1% of the documents, and goal number 6 (“ensure availability and sustainable management of water and sanitation for all”) is also relatively rare.

Figure 3.2: The 27 most featured targets in our dataset.

While examining the relative frequency of overarching goals can already pro- vide useful information about the legislative efforts and it is crucial to consider the existing imbalances between goals for any automatic annotation method, it is also interesting to consider whether there are meaningful differences with re- spect to SDG targets, which are the main objective of our hybrid classification. For this purpose, we can observe Figure 3.2, which shows the 25 most frequent targets in our dataset. Unsurprisingly, the targets belonging to goal 2 appear frequently, with 3 different targets in the 25 most frequent (targets 2.3, 2.1 and 2.b). Targets 2.3 and 2.1 are also the ones that are overall more frequent in the entire dataset. The third most frequent target is 10.3 from goal 10, whose aim is to “Reduce inequality within and among countries”. Another prominent goal in the most frequent targets is goal 16, represented by 4 targets (16.b, 16.4, 16.3, 16.10,16.a), the most out of any other goal. From this preliminary analysis it is already clear that the behavior of targets and SDG goals can be different from one goal to another. As an example, goal 16 appears more infrequently than goal 2, but it is represented by more targets.

This heterogeneous behavior must be considered when examining the results, as the prominence of some SDGs can be higher than those of others by two orders of magnitude, making any automatic classification more challenging.

3.2 Method

In order to produce an unsupervised model to classify legislative documents with its SDG targets, we opted to use a Sentence Transformer model [18]. These models have a crucial advantage over other types of transformer models, and it has to do with how the embeddings obtained from them behave. These embeddings are trained using an approach similar to Siamese Networks, with a contrastive loss, which allows the direct application of a similarity or distance metric (typically cosine similarity) in order to assess the semantic similarity between two different sentences. Between the various pretrained models, we chose all-distilroberta-v1 since it shows good performance and it supports a sequence length of 512 tokens.

Figure 3.3: From left to right, the tree and flat strategies to average the em- beddings, applied to an article with three paragraphs, one containing a list of points. Each node in the XML tree that directly contains text is associated with its own embedding vector from the model (the list, which contains no text, is ignored in the flat strategy). The vectors are then aggregated using the two strategies, and the sum in some nodes denotes the mean between vectors. The arrows denote the flow of the (aggregated) vectors in the tree.

Unfortunately, while we opted to maximize the number of tokens that the model supports, some articles were still longer than the allowed limit, which meant that some strategy for chunking and arggregating vectors needed to be adopted. Since our documents are in the Akoma Ntoso XML format, we opted to leverage information about the structural components of the documents (ar- ticles, points, paragraphs, etc) to inform the chunking procedure. In particu- lar, we devised two different aggregation strategies for the chunking procedure, which we dubbed flat and tree (see Figure 3.3). The flat procedure is the simplest of the two, and it works by obtaining the representation of a portion of the document (like an article) from a flat average of its children element in

article from the tree strategy. Finally, it is possible to incorporate the normative references in our vector representation:

v(e) =

2 + |c(e)|

M (t(e)) +

X

i

v(ci(e))

r(e)

X

j

R(rj (e))

Where r(e) is a tuple containing all the references in the text of the node e, while rj (e) represents the j-th reference. The two approaches we described (plus the addition of the references) were used to produce a vector representation for each article of the documents. Then, the vector representation of all the SDG targets descriptions from the official UN documentation were obtained by simply applying the sentence transformer model to them. Finally, a comparison between these two groups could be per- formed by calculating the cosine similarity between them, where a higher sim- ilarity corresponds to a higher degree of relatedness between an article and an SDG target

3.3 Experiments and evaluation

Using the methods described in the previous section, we performed two distinct but related experiments, which have been published in two different conferences. In the first experiment, we wanted to validate the overall approach and to assess which aggregation strategy showed more promise between the flat and tree ones. This experiment was performed using the smaller dataset, which did not yet include the consolidated documents. The tree+ strategy had also not been developed yet. In order to assess the validity of our approach, the first step was to perform a statistical test to see whether the obtained results could be explained by a random choice of SDGs. Unfortunately, we did not have a full annotation of all the documents at the article level, instead we used only annotations at the doc- ument level. To assess the effectiveness of our methods, we made a reasonable assumption about the nature of the relation between SDG targets and articles: that the SDGs that are relevant for a given document should be considered rel- evant for at least one article. Using this assumption, it is possible to calculate the expected number of articles that would be found even by random chance through a Poisson Binomial Distribution to obtain a random baseline and com- pare it with the two splitting strategies, which allows us to obtain a p-value for the results as well. The results, shown in Table 3.1, show that our results can’t be due to random chance (p-values that are less than 10 −^19 ). Unfortunately, the formula for the cumulative distribution of the Poisson Binomial Distribu- tion involves a sum over a large number of probabilities, which led to numeric cancellation, meaning that the p-values can only be expressed as inequalities. This also means that the p-values of the two different strategies are the same, but we do see that the tree strategy produces more correct matches than the flat one.

Split Stategy No. Matches P-value Correct matches Flat 3613 < 2. 71 ∗ 10 −^19 0. 165 Tree 3738 < 2. 71 ∗ 10 −^19 0. 171 Random Baseline 826 0.51 0. 038

Table 3.1: Comparison between the two splitting strategies and a random base- line, including p-values for the right tailed tests.

Another test involves the comparison of the semantic similarity between the distances between articles and SDG targets that are relevant for the document containing them (gold standard SDGs) and those which are not (non gold stan- dard SDGs).

Figure 3.4: The histograms of the similarities from SDG targets in the gold standard and those that are not for the flat split strategy (on the left) and the tree split strategy (on the right).

The first comparison is a visual one and it is applied to both strategies, and is shown in Figure 3.4, which shows that the gold standard SDGs appear to have a higher similarity with the relevant documents when compared with non gold standard SDGs. In order to test this claim, we perform a Welsh t-test on the two distributions, in order to assess whether the observed difference between them is statistically significant.

Split Strategy

Gold Standard SDGs

Non-Gold Standard SDGs P-value Flat 0. 377 ± 0. 06 0. 353 ± 0. 05 6. 84 ∗ 10 −^105 Tree 0. 381 ± 0. 06 0. 357 ± 0. 05 5. 61 ∗ 10 −^113

Table 3.2: Welsh t-test comparing the distributions of top ranking SDG targets that are and are not in the gold standard, respectively, for both splitting strate- gies.

The result of this evaluation, which is shown in Table 3.2, shows that the