Package: tibert
Current StatusNote that this is an early release. Don't hesitate to report bugs/possible improvements! There are surely many.TibertTibertis a transformers-compatible reproduction from the paperEnd-to-end Neural Coreference Resolutionwith several modifications. Among these:Usage of BERT (or any BERT variant) as an encoder as inBERT for Coreference Resolution: Baselines and Analysisbatch size can be greater than 1Support of singletons as inAdapted End-to-End Coreference Resolution System for Anaphoric Identities in DialoguesIt can be installed withpip install tibert.DocumentationSimple Prediction ExampleHere is an example of using the simple prediction interface:fromtibertimportBertForCoreferenceResolution,predict_coref_simplefromtibert.utilsimportpprint_coreference_documentfromtransformersimportBertTokenizerFastmodel=BertForCoreferenceResolution.from_pretrained("compnet-renard/bert-base-cased-literary-coref")tokenizer=BertTokenizerFast.from_pretrained("bert-base-cased")annotated_doc=predict_coref_simple("Sli did not want the earpods. He didn't like them.",model,tokenizer)pprint_coreference_document(annotated_doc)results in:>>> (0 Sli ) did not want the earpods. (0 He ) didn't like them.Batched Predictions for PerformanceA more advanced prediction interface is available:fromtransformersimportBertTokenizerFastfromtibertimportpredict_coref,BertForCoreferenceResolutionmodel=BertForCoreferenceResolution.from_pretrained("compnet-renard/bert-base-cased-literary-coref")tokenizer=BertTokenizerFast.from_pretrained("bert-base-cased")documents=["Sli did not want the earpods. He didn't like them.","Princess Liana felt sad, because Zarth Arn was gone. The princess went to sleep.",]annotated_docs=predict_coref(documents,model,tokenizer,batch_size=2)fordocinannotated_docs:pprint_coreference_document(doc)results in:>>> (0 Sli ) did not want the earpods . (0 He ) didn't like them .>>> (0 Princess Liana ) felt sad , because (1 Zarth Arn ) was gone . (0 The princess) went to sleep .Using Coreference ChainsThe coreference chains predicted can be accessed using the.coref_chainsattribute:annotated_doc=predict_coref_simple("Princess Liana felt sad, because Zarth Arn was gone. The princess went to sleep.",model,tokenizer)print(annotated_doc.coref_chains)>>>[[Mention(tokens=['The', 'princess'], start_idx=11, end_idx=13), Mention(tokens=['Princess', 'Liana'], start_idx=0, end_idx=2)], [Mention(tokens=['Zarth', 'Arn'], start_idx=6, end_idx=8)]]Training a modelAside from thetibert.train.train_coref_modelfunction, it is possible to train a model from the command line. Training a model requires installing thesacredlibrary. Here is the most basic example:python-mtibert.run_trainwith\dataset_path=/path/to/litbank/repository\out_model_dir=/path/to/output/model/directoryThe following parameters can be set (taken from./tibert/run_train.pyconfig function):ParameterDefault Valuebatch_size1epochs_nb30dataset_name"litbank"dataset_path"~/litbank"mentions_per_tokens0.4antecedents_nb350max_span_size10mention_scorer_hidden_size3000sents_per_documents_train11mention_loss_coeff0.1bert_lr1e-5task_lr2e-4dropout0.3segment_size128encoder"bert-base-cased"out_model_dir"~/tibert/model"checkpointNoneOne can monitor training metrics by adding run observers using command line flags - seesacreddocumentation for more details.MethodWe reimplemented the model fromLee et al., 2017from scratch, but used BERT as the encoder as inJoshi et al., 2019. We do not use higher order inference as inLee et al., 2018since it was found to be not necessarily useful byXu and Choi, 2020.SingletonsUnfortunately, the framework fromLee et al., 2017cannot represent singletons. This is because the authors were working on the OntoNotes dataset, where singletons are not annotated. We wanted to work on Litbank, so we had to find a way to represent singletons.We opted to do as inXu and Choi, 2021: we consider mention with a high enough mention scores as singletons, even when they are in no clusters. To force the model to learn proper mention scores, we add an auxiliary loss on mention score (as inXu and Choi, 2021). To counter dataset imbalance between positive and negative mentions, we opt to compute a weighted loss instead of performing sampling.Additional FeaturesSeveral work make use of additional features. For now, only the distance between spans is implemented.ResultsThe following table presents the results we obtained by training this model (for now, it has only one entry !). Note that:the reported results usemax_span_size=5instead ofmax_span_size=10as in training.the reported results were obtained by splitting documents for performance reasons, with subdocuments having a maximum length of 11 sentences. They may not be accurate with the performance on full documentsthe reported results can not be directly compared to the performance inthe original Litbank papersince we only compute performance on one split of the datasDatasetBase modelMUCB3CEAFCoNLL F1Litbankbert-base-cased77.3567.6356.6667.21CitationIf you use this software in a research project, you can cite Tibert as follows:@Misc{tibert,author={Amalvy, A. and Labatut, V. and Dufour, R.},title={Tibert},year={2023},url={https://github.com/CompNet/Tibert},}