Closed LiuRossa closed 7 months ago
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been inactive for 7 days since being marked as stale.
Describe the bug
TUTORIAL BUG ONLY: Missing model.eval() in the SapBERT implementations.
There is a mistake causing inconsistent results in the NLP tutorials for at least two notebooks:
and should also be in the stable branch NeMo/examples/nlp/entity_linking in every .py file who use model.forward(...) function.
After the training part the model is not set to eval mode and thus the Dropout remains active. This could be quite misleading for anyone who whishes to implement those methods.
Steps/Code to reproduce bug
1) Run the tutorial code for the aforementionned notebooks in Colab for instance (any setting). 2) Run the evaluation part twice: you get different results.
Wrong results printed in Notebook
Run this block at twice, will see:
The second line can be any other proportion possible.
In Entity Linking via Nearest Neighbor Search,
The similar score of SapBERT and most similar concepts is always changing even if the model is always the same one.
Expected behavior
The evaluation of the model should give consistent results.
One solution suggestion
Set model mode to eval each time at evaluation and restore the initial mode at the end of evaluation.
Replace the function get_embeddings(model, dataloader) by:
It resolve the problem and the output of SapBERT is fixed.
Additional comment
We think this bug always exist as this project is created. And the author has observed this mistaking result. But he wrote
in the section of Model Evaluation.
Actually, after done the debug, the result (on our side) is
BERT + SAP acts always better than BERT Base Baseline even thought with the tiny example dataset.
Environment overview
Environment details
Additional context
Add any other context about the problem here. Example: GPU model