Fine-tuning the BERT model #24
-
I want to use contextualSpellCheck for my project. Is it possible to fine-tune the BERT model and use this fine-tuned model for contextual spell checking (I want to fine-tune the BERT model for a specific domain)? Can you please provide some insights or an example on this? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
ContextualSpellCheck relies on 🤗Transformers library to provide the model. So you can follow their fine tuning pipeline and then load the updated model by providing the local path to contextualSpellCheck as below: contextualSpellCheck/examples/ja_example.py Lines 5 to 8 in 96cb79e A snippet on model loading in contextualSpellCheck is below: contextualSpellCheck/contextualSpellCheck/contextualSpellCheck.py Lines 112 to 119 in 96cb79e If you see above, L113 and L119, depends on 🤗Transformers to load the model either from 🤗Transformers cloud storage or local. Depending on 🤗Transformers allows us to support pretrained models in other languages and not isolate the library from taking advantage from peoples contribution to custom models. I hope this solves your issue. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the detailed information :). I am also interested to work on real-word errors in my project. Do you have any suggestions to tackle this problem? |
Beta Was this translation helpful? Give feedback.
-
I am happy the solution worked for you! Regrading the RWE, it is a difficult problem to deal with. I did some reading before starting this project on both RWE and NWE. In my understanding a spell corrector pipeline can be divided as follows:
RWE and NWE are very similar except for step 1. If I remember correctly, they identify misspell (RWE) using n-grams and frequency of occurrence. I did not find anywork which uses ML models to identify misspell (both RWE and NWE). So, a good start maybe for RWE would be to start with this approach. I have the following resource in my backlog. If you find it useful:
If you would like to contribute, that would be great! |
Beta Was this translation helpful? Give feedback.
-
Also I will close this issue for now. If you face any issue with fine tuning, then please check 🤗Transformers repo for more doc or raise an issue if you encounter a bug while fine tuning. |
Beta Was this translation helpful? Give feedback.
-
Hello @R1j1t , I could fine-tune the BERT model as it is shown in the [example] (https://github.com/huggingface/transformers/tree/master/examples/language-modeling) and the model is saved as pytorch_model.bin (413 mb). Then I tried to use this model for the contextualSpellCheck but I am facing the following error:
Can you please help me to resolve this issue? |
Beta Was this translation helpful? Give feedback.
-
I got it worked and the following files must be in the same folder and the path should be projected to the folder (not to the pytorch_model.bin): vocab.txt - vocabulary file |
Beta Was this translation helpful? Give feedback.
-
Hi @R1j1t , Do you know how loss is calculated during fine-tuning the BERTForMaskedLM using run_language_modeling.py? While fine-tuning, we can only see loss and perplexity which is useful. Do you have any better ideas to fine-tune the BERT (apart from BERTForMaskedLM) for spelling correction? |
Beta Was this translation helpful? Give feedback.
-
@naturecreator please check the relevant documentations or code to understand this. |
Beta Was this translation helpful? Give feedback.
ContextualSpellCheck relies on 🤗Transformers library to provide the model. So you can follow their fine tuning pipeline and then load the updated model by providing the local path to contextualSpellCheck as below:
contextualSpellCheck/examples/ja_example.py
Lines 5 to 8 in 96cb79e
A snippet on model loading in contextualSpellCheck is below:
contextualSpellCheck/contextualSpellCheck/contextualSpellCheck.py
Lines 112 to 119 in 96cb79e