Repository navigation
Description
Hi everyone,
I am trying to fine-tune GLiNER but the results are consistently poor.
At first, I used an artificially generated dataset, but after fine-tuning, the model completely lost its ability to recognize and correctly label entities.
To verify whether the problem was with my data, I ran the official examples/fine-tuning.ipynb notebook with the sample dataset provided by the authors. However, even with that dataset, the model produces very bad results. (It is unclear to me how it previously gave good results, since now it consistently fails, even though I am using the same code and the same dataset.)
I also read in an another issue that the model may suffer from catastrophic forgetting, and that merging the Pile-NER dataset with the target dataset during fine-tuning could help. I tried that approach with various dataset sizes (small, medium, large), various ratios between my dataset and the Pile-NER one (1:2, 1:5) and various hyperparameters, but the results did not improve.
After fine-tuning, the model tends to over-predict by labeling every token, or sometimes even entire phrases, as entities. In many cases, it assigns the same label to all of them, and even when the labels vary, they are consistently incorrect. Here is a sample output:
Whiplash => treatment
, => treatment
a => treatment
soft => treatment
tissue injury to the neck, is also called neck sprain => treatment
or => treatment
strain => treatment
. => treatment
Treatment depends on the cause => treatment
, => treatment
but => treatment
may include => treatment
applying => treatment
ice => treatment
, => treatment
taking => treatment
pain relievers, getting physical therapy or wearing => treatment
a => treatment
cervical collar => treatment
. => treatment
You => treatment
rarely => treatment
need => treatment
surgery => treatment
. => treatment
Has anyone else experienced this issue?
Is there a recommended approach to improve this?
Activity
tamarastojanova commentedon Sep 22, 2025
@urchade @Ingvarstep
Sorry for bothering but I'm doing a bachelor's degree project on this :)
Ingvarstep commentedon Sep 23, 2025
@tamarastojanova , hi, thanks for informing me about this issue. It was related to the incorrect interface to the loss function, and masking of negative labels was done incorrectly. Here is my fix, it's still under review, feel free to give your feedback: #296
jzamora-281992 commentedon Sep 23, 2025
Hi @Ingvarstep I have uninstalled and redownloaded the library and the model and I'm still getting the same behaviour. Here is my data (completly synthetic):
{'tokenized_text': ['', '', 'Reporte', 'Clínico', '', '', '\n\n', '', '', 'Paciente', ':', '', 'María', 'del', 'Carmen', 'Ramos', 'Martínez', '\n', '', '', 'DNI', ':', '', '12345678', '\n', '', '', 'Fecha', 'de', 'Nacimiento', ':', '', '12', 'de', 'mayo', 'de', '1985', '\n', '', '', 'Teléfono', ':', '', '915654321', '\n', '', '', 'Dirección', ':', '', 'Cl', '.', 'de', 'Alcalá', ',', '123', ',', 'Madrid', '\n\n', '', '', 'Fecha', 'del', 'Examen', ':', '', '22', 'de', 'febrero', 'de', '2023', '\n', '', '', 'Médico', ':', '', 'Dr.', 'Juan', 'Luis', 'Ramos', '\n\n', '', '', 'Examen', 'Físico', ':', '', 'El', 'paciente', 'se', 'presentó', 'en', 'la', 'consulta', 'con', 'un', 'estado', 'general', 'de', 'salud', 'regular', '.', 'El', 'apoyo', 'corporal', 'es', 'de', '165', 'cm', 'y', 'un', 'peso', 'de', '55', 'kg', ',', 'lo', 'que', 'corresponde', 'a', 'una', 'IMC', 'de', '20,5', 'kg', '/', 'm2', '.', 'La', 'piel', 'y', 'los', 'tejidos', 'subcutáneos', 'presentan', 'una', 'normoflora', 'y', 'no', 'hay', 'alteraciones', 'observables', 'en', 'las', 'mucosas', '.', '\n\n', 'El', 'paciente', 'tiene', 'una', 'apnea', 'normal', 'y', 'la', 'periferia', 'pulpar', 'es', 'normal', '.', 'El', 'examen', 'abdominal', 'reveló', 'un', 'abdomen', 'laxo', 'y', 'asimétrico', ',', 'con', 'hipoacusia', 'en', 'el', 'cuadrante', 'superior', 'izquierdo', '.', 'No', 'se', 'observaron', 'lesiones', 'cutáneas', 'o', 'alteraciones', 'en', 'la', 'piel', '.', 'La', 'circulación', 'linfática', 'es', 'normal', '.', '\n\n', 'La', 'inspectión', 'del', 'pecho', 'reveló', 'una', 'silueta', 'corporal', 'regular', ',', 'con', 'respiración', 'ruidosa', 'periférica', 'en', 'ambos', 'lados', '.', 'Se', 'escuchó', 'un', 'sonido', 'cardíaco', 'normal', 'y', 'no', 'se', 'detectaron', 'murmuros', 'o', 'ruidos', 'anómalos', '.', 'La', 'palpación', 'reveló', 'un', 'pulso', 'regular', 'y', 'no', 'se', 'encontraron', 'áreas', 'de', 'tensión', 'muscular', 'anómalas', '.', '\n\n', '', '', 'Hallazgos', ':', '', 'Se', 'observaron', 'signos', 'de', 'estrés', 'y', 'ansiedad', ',', 'manifestando', 'un', 'estado', 'de', 'alerta', 'y', 'vigilancia', '.', 'La', 'evaluación', 'neurológica', 'reveló', 'reflexos', 'normales', 'y', 'no', 'se', 'detectaron', 'alteraciones', 'en', 'la', 'marcha', 'o', 'coordinación', '.', '\n\n', '', '', 'Recomendaciones', ':', '', 'Como', 'resultado', 'del', 'examen', 'físico', ',', 'es', 'recomendable', 'que', 'el', 'paciente', 'realice', 'un', 'seguimiento', 'médico', 'cada', '6', 'meses', 'para', 'evaluar', 'su', 'estado', 'general', 'de', 'salud', 'y', 'controlar', 'las', 'posibles', 'complicaciones', '.', 'También', 'se', 'recomienda', 'que', 'el', 'paciente', 'realice', 'un', 'ejercicio', 'moderado', 'regularmente', 'para', 'mejorar', 'su', 'condición', 'física', 'y', 'reducir', 'el', 'estrés', '.', '\n\n', '', '', 'Next', 'Steps', ':', '', 'Se', 'programó', 'una', 'cita', 'para', 'revisión', 'en', '6', 'meses', 'y', 'se', 'le', 'recomienda', 'realizar', 'una', 'consulta', 'con', 'un', 'especialista', 'en', 'medicina', 'general', 'si', 'presenta', 'alguna', 'dolencia', 'o', 'síntoma', 'desagradable', 'en', 'el', 'futuro', '.', '\n\n', '', '', 'Firma', 'del', 'Médico', ':', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '\n', '', '', 'Firma', 'del', 'Paciente', ':', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], 'ner': [[12, 17, 'PERSON'], [23, 24, 'DNI'], [32, 37, 'DATE'], [43, 44, 'TELEPHONE'], [50, 58, 'ADRESS'], [66, 71, 'DATE'], [78, 81, 'PERSON']]}
With this code I'm getting this behaviour on training:
I don't see what am I doing wrong. Can you please help me?
thanks.
Ingvarstep commentedon Sep 23, 2025
Hi, I'm sorry for the bug you experienced. To apply the latest changes, you need to install GLiNER from the source, please, check the instructions here: https://github.com/urchade/GLiNER/blob/main/README_Extended.md#install-from-source
jzamora-281992 commentedon Sep 23, 2025
Thanks! this solved the issue. Very grateful.
Ingvarstep commentedon Sep 23, 2025
You are welcome
jzamora-281992 commentedon Sep 24, 2025
Hi again. I managed to train the model by doing the installation from the source but now I'm running into a different error when trying to infer with the model I just fine-tuned. Here is the code:
From what I've seen in the examples the way is correct so it make sme doubt about if there is another issue with the library or is the way my model has been trained.
Thanks in advance for any help!
jzamora-281992 commentedon Sep 24, 2025
Hi, I just saw my error. I was using the incorrect method since the one I was using was for batches of entities. THe correct method for a string would be "predict_entitites". I'll leave it here just in case it happens to any other person XD. Thanks you!!!!
jpmallette commentedon Oct 17, 2025
Thank you for this, I had the same issue, it is now resolved.
I would recommend to change the finetune google colab example with the following two changes:
%%bash
pip uninstall gliner -y
rm -rf GLiNER
git clone https://github.com/urchade/GLiNER.git
cd GLiNER
pip install -r requirements.txt
pip install .
python -c "import gliner; print(f'✓ GLiNER version: {gliner.version}')"