Jus Mundi at S em E val-2023 Task 6: Using a Frustratingly Easy Domain Adaption for a Legal Named Entity Recognition System (2023)

Abstract: In this work, we present a Named Entity Recognition (NER) system that was trained using a Frustratingly Easy Domain Adaptation (FEDA) over multiple legal corpora. The goal was to create a NER capable of detecting 14 types of legal named entities in Indian judgments. Besides the FEDA architecture, we explored a method based on overlapping context and averaging tensors to process long input texts, which can be beneficial when processing legal documents. The proposed NER reached an F1-score of 0.9007 in the sub-task B of Semeval-2023 Task 6, Understanding Legal Texts.

## introduction in this paper, we present jus mundi's foot_0 participation in task 6 of semeval-2023, legaleval: understanding legal texts @xcite . specifically, jus mundi participated in the sub-task b, legal named entities extraction, which consisted of creating a named entity recognition (ner) system for indian judgment documents in english. the goal was to predict multiple types of entities from both the judgment preamble and the judgment body. our participation consisted of a model trained using a frustratingly easy domain adaptation (feda) algorithm @xcite @xcite . the feda algorithm, as its name indicates, is a type of domain adaption method created by @xcite . the objective of using a feda algorithm is to learn common and domain-specific patterns between multiple datasets @xcite , but it can be used also to mix multiple datasets despite not having the same tagset, as seen in @xcite . moreover, a feda algorithm simplifies many of the questions that generally arise while exploring other types of domain adaptation and transfer learning techniques. for instance, with a feda algorithm, it is not necessary to determine which layers should be frozen, fine-tuned, or substituted. the rest of the paper is organized as follows. in section 2, we introduce the background for the proposed work. this is followed by the methodology in section 3. the data and the experimental settings are described in section 4 and section 5, respectively. in section 6, we present the results and discuss them. finally, the conclusions and future work are detailed in section 7. ## related work named entity recognition (ner) is a fundamental natural language processing (nlp) task that consists of identifying entities that semantically represent elements such as locations, organizations, and people @xcite . while the applications and advantages of using ner systems are well known, in many domains and languages, it is a task that continues to be a challenge. this is the case within the legal domain, where the extent of research regarding ner on this subject is still small in contrast to more general domains, such as conll 2003 @xcite or ontonotes v5 @xcite . the main reasons are the lack of annotated data to train ner systems @xcite but also the complexity of processing legal documents @xcite , e.g. long sentences and specialized vocabulary. nonetheless, in the following paragraphs, we present some of the most representative works regarding the detection of legal named entities. for indian documents, we can highlight the works of @xcite and @xcite . in the former work, the authors trained an ner using ontonotes v5 @xcite and applied it to legal documents in a zero-shot approach. in the latter, the authors proposed an ner corpus from different indian court judgments. moreover, they trained an ner system using a transformer-based architecture @xcite and make use of coreference resolution and rules to reconcile named entities. in the work of @xcite , the authors created an ner robust to spelling mistakes for french court decisions using deep learning and contextual dictionaries of entities. for romanian and german, we have the works of pȃis , et al. @xcite and @xcite , respectively. both works created their legal corpus and utilized a bilstm-crf architecture to train an ner. in the legal domain, it is frequent to find other ner systems in anonymization tools. for instance, schamberger (2021) make use of a bilstm-crf architecture with bert @xcite embeddings to anonymize german court rulings. in @xcite , the authors create an ner for anonymizing documents from the european court of human rights using a transformer-based architecture. similarly, in @xcite the authors use a transformer-based ner for anonymizing finnish documents. regarding the feda algorithm, it was originally proposed by @xcite for sparse machine learning algorithms. it is a simple method that consists of duplicating the input features. then, @xcite , proposed a neural network version of feda in which certain layers are activated according to their respective training dataset. later, cabrera-diego et al. (2021b) used a feda algorithm to train multiple ner systems for lessresourced languages using bert and multilingual datasets with different tagsets. ## methodology we define our feda architecture as a collection of dense layers built over a pre-trained language model, which follows the same ideas presented by @xcite . in other words, it is composed of one general feda layer and multiple specialized feda layers; each specialized feda layer is connected to the general one. nonetheless, we differ from cabrera-diego et al. (2021b) on how the feda layers are defined and connected, as we will describe in this section, but also on how we train the model, as it will be shown in section 5. thus, let us establish a feda layer f as a gelu activation layer (hendrycks and gimpel, 2016) followed by a linear one. we define a general feda layer g as the stack of two layers f joined by a layer normalization layer @xcite . and, we define a specialized feda layer c x as a stack of two layers f joined by a concatenation layer and layer normalization layer. the g layer is linked to each c x layer through their respective concatenation layer. moreover, on top of all the specialized c x layers, we define a conditional random field (crf) @xcite ) that processes their output, similar to the approach used by @xcite to improve an ner system. for a given collection of training datasets defined as @xmath0, d 2 , . . . , d n |@xmath1, where each d x is composed of i entries, e.g. a paragraph or a sentence, of type e i x . our feda architecture is composed of one general feda layer g and n specialized feda layers c x , such that we have @xmath2, c 2 , . . . , c n }. we present the diagram of the proposed feda architecture in figure 1 . for each entry e i x , the output created by the language model is introduced into g and its corresponding c x layer. then, the output generated by g is introduced into c x by concatenating the tensor to the output of the first layer f in the specialized feda layer c x . the concatenated output is then passed through the rest of the layer c x . the output of c x then goes into the crf layer. in summary, g represents a classifier that receives an input comprising of all the entries e i from all the datasets in d, while c @xmath3 ## data as we make use of a feda architecture, we used five different datasets related to the legal domain for training our submitted models. the main training corpus, henceforth legalner, is described in @xcite . it is composed of indian court judgments that have been annotated using 14 types of named entities related to the legal domain: case number, court, date, geopolitical entity (gpe), judge, lawyer, organization, other person, petitioner, precedent, provision, respondent, statute and witness. 2 furthermore, this corpus covers two different parts of a court judgment, the preamble, and the judgment body. the former is a type of introductory cover document where certain legal elements are presented in a concise way without necessarily using sentences or phrases. the latter is a paragraph or a sentence found in the judgment body. granted that legalner is split into train, development, and test partitions, we created our own development partition due to two reasons. firstly, the development corpus was provided after the competition started. moreover, we discovered that the development partition was not proportionally balanced with the training corpus in terms of the quantity and variety of entities. therefore, we created our own development corpus from the training partition. we used a stratified approach, in which we considered three aspects to create the development partition. the first aspect was related to cultural elements that could play a role in the quality of the ner system. specifically, we classified the documents coming from various cities, states, and union territories into three groups: north and west, south and center, and north east. secondly, the proportion of entities had to be around 10% of the training set; this also included the proportion of groups previously defined. the third aspect was prioritizing unique courts for the development corpus. consequently, this would allow us to finely evaluate the generalization of our ner system towards unseen courts. we included the original development corpus as part of the training partition once it was made available to the participants. 3 we present in we automatically pre-processed all the named entities in the train and development corpus partitions, to remove some undesirable patterns that were being learned by the model during the first experiments due to noise in the data. for instance, certain entities had trailing spaces or commas, but also honorifics, such as sri and judge. specifically, we used a combination of regular expressions that matched the noisy patterns and rules to clean the data. also, we manually added and/or changed certain entities in the training and development corpus after doing an error analysis on the predictions produced on the development corpus during the first experiments. for instance, in the document "but it had then discovered that the real accused were intertek and prasanna ghotage, who had together conspired to defraud not only dlc, but also smc in the transaction." 4 , only two entities were marked, intertek and prasanna ghotage, both as other person. we changed intertek to organization, and we added dlc and smc as organizations. the pre-processing allowed us to have a cleaner and more standardized corpus. the additional datasets are described as follows: edgar-ner: a legal corpus created by au et al. (2022) and composed of 52 documents related to financial filings submitted by companies to the us securities and exchange commission. it consists of 7 types of named entities: location, person, business, government, court, legislation/act, and miscellaneous. citations: a jus mundi corpus where different paragraphs from legal documents have been annotated with citations. in this corpus, the definition of citations covers all those defined in @xcite as precedents, statue, cases numbers, and provisions. persons and honorifics: this is also a jus mundi legal corpus that has been annotated with 2 labels, person names, and honorifics, such as mrs. and q.c. metadata: an internal jus mundi corpus that consists of automatically annotated cover pages of arbitration-related documents from different jurisdictions. nine different types of labels exist, arbitrator, date, claimant, respondent, expert, institution, lawyer, title, and member of the tribunal. ## experimental settings all the named entities were encoded using bilou (beginning, inside, last, outside/other, unique) labeling scheme, which has been precedented as an indirect way to improve ner predictions @xcite . we use deberta v3 @xcite large as a pre-trained language model. we trained multiple models during the evaluation period, for which the hyperparameters stayed the same, except for deberta's sequence size. these are presented in during training, we also explored different ways to prevent overfitting. we found out that the best approach was to measure the overfitting per dataset. in effect, once a dataset started to overfit, it was dropped from the training. followed by reloading the model's state on which we obtained the best performance of the dropped dataset and continuing the training. this differs from the approach followed by @xcite , on which the overfit was measured globally, denoting that certain datasets could affect the global performance. additionally, when an input text was longer than the maximum sequence size of deberta, the input text was split into smaller sub-input texts with an overlapping context stride of size 40. 5 the overlapping context strides gives the ner system additional information about entities that can be found close or on the boundaries of a sub-input text. during prediction time, the tensors related to each subinput text were concatenated before the crf layer. the tensor portions belonging to the overlapping contexts were merged through an average. the above-described approach is shown in figure 2 . we decided to do an average of the overlapping context tensors because the output generated by the ner can be discordant depending on the context it is analyzed. for example, an entity might not exist in one sub-input text, it might be assigned a different type, or it might comprise a different number of tokens. thus, by averaging the tensors belonging to the overlapping contextual strides, we can simply and quickly represent a portion of text that was predicted twice by the ner, and give enough information about the tensors to the crf. this method for dealing with long input texts is another extension to the approach undertaken in @xcite . to improve the predictions, we also explored the merging of multiples models outputs through a simple majority voting system. in case of a tie in the voting, we gave priority to the model with the highest score obtained on the test partition. finally, we created a post-processing tool based on regular expressions that improved the entities to avoid some noise produced by the ner. for instance, in some entities, we closed unbalanced brackets while in others we removed leading and trailing punctuation marks, such as quotation marks. some examples of entities that had to be post-processed: "section 147,148, 302/149 (" to "section 147,148, 302/149"; "rajendra kumar (verma" to "rajendra kumar (verma)". ## results and discussions collectively, we submitted 7 different models to the evaluation platform of task 6. 6 these were chosen based on their performance on our development partition. the f1-score of the submitted models, in order of submission, were the following ones: 0.8853, 0.8861, 0.8949, 0.8908, 0.8953, 0.90071, and 0.90072. the first model submitted, 0.8853, was produced by our baseline, a model that consisted of de-berta v3 + crf layer. for the following models, we submitted only feda architectures. the last three submitted models used the majority voting approach and the last two applied the postprocessing tool for cleaning the predictions. the use of the voting system allowed us to pass from an f1-score of 0.8949 to 0.8953, while the use of the post-processing filter surpassed an f1-score of 0.9007. bearing that the testing corpus has not been made public, a deep analysis of the results is unfeasible. although in the following paragraphs, we present some aspects that we observed from the predictions obtained during the fine-tuning of our models and also, on the test submissions. we noticed that pre-processing the training files played an important role in the training of the model. on the first trained models, before submission, we observed that certain noisy patterns were being learned, such as finishing entities with a comma. nonetheless, some patterns could not be fixed because we did not know which was the correct one. for instance, some entities of type date had the prefix dt. while some others did not. it should be indicated that we explored the representation of newlines by adding a special character (<@xmath4. this was done following the works of baldini @xcite and @xcite , in which special characters are used to make bert @xcite focus on specific information. the goal was to try to introduce some kind of formatting to the ner, especially on the preambles, where the format is substantial to better determine an entity type. the performance gain of the models varied a lot. for instance, the third submitted model, with an f1-score of 0.8949, was one of the best models we trained. nonetheless, other variations of our feda model and the special @xmath5, did not show to improve the results in the development partition. and thus, they were not submitted. the reason might be that legalner was the only corpus with this feature among all those used for training. we discovered that the length of deberta's sequence size affected the performance of the ner in great measure. this was especially noticeable in the preambles because it seems that to predict the type of certain entities correctly, a larger context was necessary. for instance, sometimes it was hard to determine whether a party in a preamble was a petitioner or a respondent after a long list of names. related to the previous aspect, sometimes our system had problems predicting a party correctly, either petitioner or respondent, when it was a person representing an organization. in this case, according to the guidelines, the named entity of the party had to include the full address. subsequently, this was hard to train, not only because of the particularity of the guidelines but also because of the length of the context that had to be processed to predict the entity accurately. although we explored longer context strides as a countermeasure for long texts, we noticed that they did not improve the performance on the same scale that the stride was increased. this can be seen in our fourth submission, which achieved an f-score of 0.8908; we sent the best model and we only modified the size of the context stride to 150 characters. however, as it can be seen, its performance was not better than the third submission (0.8949). 7 one of the reasons could be that the approach used to merge overlapping contexts was not robust enough. this was more noticeable when the stride was larger than half of deberta's sequence size. in other words, the average of the overlapping contexts became too noisy when an overlapping context was overlapping another context. in the future, we could try to train a dense layer or an attention layer to overcome this. however, these layers might need to be trained after the main ner model has been selected. additionally, we noticed that separating the early stop patience for each dataset, allowed us to improve the predictions up to a certain degree. as a result, the training of the models took longer and constrained us from exploring other aspects that could have improved the outcomes further. for instance, to increase the size of deberta's sequence size to 512 for the final models. finally, we found out that on certain occasions the crf could not correctly learn the tagset of the smallest training dataset explored, person and honorifics, after we separated the early stop patience. one of the reasons is that the crf was shared among all the datasets and this particular dataset was very easy to train. this meant that the crf had less time to understand the correct chain of possible types of entities, among all those existing. we theorize that this can be solved by creating a unique crf for each dataset, which should also speed up the training of a model. ## conclusion this work presented the participation of jus mundi at semeval-2023 task 6. specifically, we proposed a named entity recognition system that was trained using multiple legal datasets through frustratingly easy domain adaption (feda). the results showed us that our ner system is a performant tool on indian judgments with an f1-score of 0.9007. in the future, we intend to further explore the benefits and limitations of an ner based on a feda architecture. moreover, we will probe different ways to speed up the training given that separating the early stop can make the training of the final models to be slower. we will also seek a better approach to join split sentences to predict entities more accurately in long documents, as commonly occurs in the legal domain. finally, we will apply the proposed architecture to more complex tasks.