-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NB for BERT models #114
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the CI pass, I will study your notebook in details, as I am really curious about it!
examples/basic_tutorial_BERT.ipynb
Outdated
"kernelspec": { | ||
"display_name": "Python [conda env:torch] *", | ||
"language": "python", | ||
"name": "conda-env-torch-py" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the CI is complaining about this name:
jupyter_client.kernelspec.NoSuchKernel: No such kernel named conda-env-torch-py
Can you please change this to:
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Should be fixed now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hkirvesl can you please use os.path.join
to build file path please? windows and posix OS have a different convention (back and forward slashes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion. Done.
…hkdev pull the test fixes
there was a mismatch in where data was downloaded and read from, causing the CI to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear @hkirvesl ,
I think we are almost there: I only have a few minor comments.
I will then review the notebbook in detail.
One important note: did you pull master to your fork before committing? I ask because there is one item in the CI that took > 5h to run and has currently not yet finished (though it should really take 25 mins at most) and I wonder if it is related to not having integrated the fixes. If you have done so, than ignore this last comment
.pre-commit-config.yaml
Outdated
#- repo: https://github.com/psf/black | ||
# rev: 22.8.0 | ||
# hooks: | ||
# - id: black |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood from raphael that mypy is causing issues, however black should not: it should simply frmat the code properly: why are you commenting black
out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please keep the hook for black.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please wait until my pull request is accepted and then pull again from master? I fixed all mypy errors, and the pre-commit does work now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments, Matteo and Raphael. I did recall some discussion about problems with the prehooks and commenting them out being the recommended temporary work around. I just forgot the details and ended up commenting out too much. All these should be fixed now. Thank you Raphael for the fix, this makes our lives much easier.
gdeep/models/utils.py
Outdated
@@ -70,6 +70,6 @@ def __call__( | |||
the output tensor of the module | |||
""" | |||
if isinstance(module_out, tuple): | |||
self.outputs.append(module_out[0].detach()) | |||
self.outputs.append(module_out[0])#.detach()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functionalities are needed in the forward hooks in order to extract the activation values of the layers for example.
Could you please double check if the functionalities to get activations values still works properly without the detachment? Put differently, do you understand the consequences of removing the .detach()
for the forward hooks? If so, could you please write a couple of sentences here below? thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment, this is a very good point indeed. I do understand the consequences and I agree what was proposed is not a good solution. To be honest, I forgot about this myself. It was just a quick and dirty fix to make the BERT models work and since it worked and seemingly didn't break any tests I just proceeded without worrying about it.
A good solution would keep the old functionality where applicable, in the same spirit as the change in trainer.py. I believe this has now been fixed.
gdeep/trainer/trainer.py
Outdated
@@ -266,9 +266,13 @@ def _send_to_device( | |||
new_x.append(xi.to(DEVICE)) | |||
x = new_x | |||
prediction = self.model(*x) | |||
if(hasattr(prediction, "logits")): # unwrapper for HuggingFace BERT model | |||
prediction = prediction.logits # unwrapper for HuggingFace BERT model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all good here!
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It is a more giotto-way to do this. In general, any other comments on how to make the notebook more giotto-like are highly appreciated.
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ca you please preceed this cell with a markdown cell describing what you are doing here?
if this cell and the above one are related to handling masks, then maybe it is worth putting a bit of explanation 2 cells above, details the steps that one needs to take
Reply via ReviewNB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.I added a brief note (and deleted an unnecessary chunk)
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right. Fixed.
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if these two cells are "almost" duplicated, can you please create a function in one cell and call it with different parameters?
Probably same comments may work a few cells above
Reply via ReviewNB
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,1198 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ca you clarify why you compute the gradients (and of what) in a sentence in a .md cell above this one?
Reply via ReviewNB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some discussion on this. Also: If you know of a more giotto-like way of getting your hands on these gradients I think it would improve this notebook.
Thanks for the good comments! I pulled the main and it did fix a lot, (and also managed to close this PR.) Will reopen once I've cleaned the notebook more a bit more as per the suggestions |
Could you please install pre-commit (see README.md) |
Reopening the PR Changelog: The notebook:
1.1) Removed unneeded imports: 1.2) Added import from gdeep.utility import DEVICE
Testing:
models/utils.py
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this loks good and it is very interesting btw! thanks @hkirvesl !!
Reference issues/PRs
Fixes #81 By adding a notebook on BERT models with topological interpretability methods built on top of one. The old tutorials on Q&A and Translation remain for now.
Types of changes
Description
Screenshots (if appropriate)
Any other comments?
Checklist
flake8
to check my Python changes.pytest
to check this on Python tests.