richardpaulhudson / coreferee

Coreference resolution for English, French, German and Polish, optimised for limited training data and easily extensible for further languages
MIT License
113 stars 19 forks source link

Using coreferee with custom model #13

Closed riccardopinosio closed 1 year ago

riccardopinosio commented 1 year ago

Hello,

I would like to use coreferee with a custom spacy model that is a slight variation of the en_core_web_lg version 3.4.1 (it's basically the same model that has been trained to recognize one additional entity type using the standard spacy training process).

Trying to add coreferee to the trained pipeline with .add_pipe fails with a model version not supported error. In the readme it says that I'm supposed to train a new coreferee model for this custom model, however I would like to essentially use the same model for en_core_web_lg as my custom model is very similar. Is there any way to just lift that coreferee model for use with a custom spacy model?

Tanmay98 commented 1 year ago

Hi @riccardopinosio ,

I am also interested in incorporating coreferee with my custom NER spacy model. My problem is the entities are quite different from the default spacy model itself so using pretrainedncorefree or neuralcoref would not be a good choice right?

So, my solution would be to annotate small dataset and finetune the existing model on it right? Any suggestions

richardpaulhudson commented 1 year ago

Named-entity labels are one of many feature types that Coreferee uses as neural-network inputs, with one neuron per type and a fixed mapping from labels to neurons. This means that if you are using a custom NER model, however close this model is to the published standard model, it will make sense to train a custom Coreferee model to ensure you are achieving the best accuracy possible.

For English this should be both straightforward and quick:

@Tanmay98, you don't specify if your custom NER spaCy model is for English or for another language. If English, please follow the above instructions; if for another language, please get back to me.

Tanmay98 commented 1 year ago

Hi @richardpaulhudson , Thanks for your response. I am a little confused. So, I have a custom spacy model for NER in English language. My only question is since the Litbank dataset has entities like person, organization, etc. for NER whereas my spacy model has different Entities. So wouldnt I want to finetune the coreferee model for some newly annotated dataset according to my NER entities. Also, Since then I have tried annotating small dataset for coreference using Bran software which was mentioned by the Litbank guyz but their documentation is not very clear on how to use that So, I used LabelStudio to annotate and then wrote code which convert the json to bran format and finally using litbank loaderclass for training. My last question is according to the guidelines mention in coreferee repo, am I finetuning using the train command or training a whole new model?

Thanks again in advance !

richardpaulhudson commented 1 year ago

Unfortunately this is all quite confusing.

richardpaulhudson commented 1 year ago

Two other important points I forgot to mention earlier:

Tanmay98 commented 1 year ago

@richardpaulhudson Thanks for the wonderful explanation. Now, it makes sense to me. So, since I have already annotated some training data, I will combine it with the existing Litbank corpora and try to train on the whole.

One thing, my custom spacy model just has one entity "ACT", as in the legal acts, for NER. So, I just want the coreferences of the act to be detected.

For example,

Bail under the Narcotic Drugs and Psychotropic Substances Act 1985 (‘NDPS Act’). The court while considering the application for bail with reference to Section 37 of the Act is not called upon to record a finding of not guilty.

-So, here my spacy model currently detects [ACT] Narcotic Drugs and Psychotropic Substances Act 1985 [ACT] but I also want Section 37 of the Act to be detected as part of the parent entity.

This looks doable with combining the Litbank and sample annotated dataset, I think probably

richardpaulhudson commented 1 year ago

Yes, what will be important for this use case will be defining act and any other relevant nouns as mapping to ACT in the entity noun dictionary.

Tanmay98 commented 1 year ago

@richardpaulhudson Thanks, I updated the config with my custom spacy model and also updated the entity noun dictionary. After training the model. Now I am running the command to install the new coreferee model but I am facing the below issue even after running from the root coreferee directory where the models dir is present

Screenshot 2022-12-09 at 3 38 58 PM

Tanmay98 commented 1 year ago

Hi , it's workin now i had to just run python3 -m coreferee install en and it updated for the new coreferee model so everything seems to work. Thanks!!