Skip to content
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

CASTER layer implementation #73

Merged

Conversation

andriy-nikolov
Copy link
Collaborator

@andriy-nikolov andriy-nikolov commented Feb 2, 2022

Summary

An implementation of the CASTER model layers based on https://github.com/kexinhuang12345/CASTER

Note:

  • covers only supervised training stage

  • input dimensionality assumed to be correct and meaningful according to the assumptions of the algorithm

  • TODO: inclusion of the unsupervised stage (would require a pipeline hook)

  • TODO: inclusion of the BIOSNAP dataset from the paper

  • TODO: data loading using the input processing from the paper

  • Unit tests provided for these changes

  • Documentation and docstrings added for these changes using the sphinx style

Changes

  • Implementation of the CASTER model with the custom loss function
  • An example script for invoking the model (performance not meaningful because of the incomplete implementation of the model)
  • A unit test method to check the output dimensionality

- only supervised training stage
- input dimensionality assumed to be correct
chemicalx/models/caster.py Outdated Show resolved Hide resolved
def __init__(
self,
*,
drug_channels: int = 1722,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be set based on dataset and not have a default

)

# predictor: eight layer NN
predictor_layers_dict = OrderedDict()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very hard to think about. can you just use a list?

"""
Run a forward pass of the CASTER model

:param drug_pair_features (torch.FloatTensor): functional representation of each drug pair (see unpack method)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to make a named tuple class to document this kind of thing

@cthoyt
Copy link
Collaborator

cthoyt commented Feb 2, 2022

@andriy-nikolov note I did some reorganization of the code in this PR. Make sure you pull before you begin to work on it again

@codecov-commenter
Copy link

codecov-commenter commented Feb 2, 2022

Codecov Report

Merging #73 (a9aaae8) into main (5449f96) will increase coverage by 0.83%.
The diff coverage is 97.93%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #73      +/-   ##
==========================================
+ Coverage   93.87%   94.70%   +0.83%     
==========================================
  Files          29       30       +1     
  Lines         832     1058     +226     
==========================================
+ Hits          781     1002     +221     
- Misses         51       56       +5     
Impacted Files Coverage Δ
chemicalx/pipeline.py 87.67% <66.66%> (-0.91%) ⬇️
chemicalx/models/deepddi.py 95.00% <94.73%> (-5.00%) ⬇️
chemicalx/models/deepdrug.py 96.77% <96.66%> (-3.23%) ⬇️
chemicalx/models/gcnbmp.py 97.61% <97.59%> (-2.39%) ⬇️
chemicalx/loss.py 100.00% <100.00%> (ø)
chemicalx/models/caster.py 100.00% <100.00%> (ø)
tests/unit/test_models.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5449f96...a9aaae8. Read the comment docs.

kajocina and others added 6 commits February 3, 2022 15:54
* WIP: model forward pass works, not tested

* added dropout and batch norm

* WIP: made DeepDrug example, not tested

* moved to using layers only, not GCN torchdrug model

* docstring

* added dropout and made context feats optional

* added DeepDrug unit test

* deepdrug self attribute fix

* docstring update

* unpack method update (when no context feats used)

* isort

* fixed test setting (context_channels)

* fixed testing without context

* black

* RST fix

* RST fix

* more pythonic loop + swap i to _

* removed context feat support in DeepDrug

* removed context handling from testing DeepDrug

* fixed examples DeepDrug, no context handling, decreased epochs 100->20

* removed unused import

* used a wrapper for calling the same layers on pairs of batches

* used a wrapper for calling the same layers on pairs of batches

* docstring fix

* Abstract process applied to left and right sides

* Apply black

* Cleanup

Co-authored-by: Charles Tapley Hoyt <cthoyt@gmail.com>
* linting

* GCNBMP Scatter Reduction fix

* Using Rel Conv Layers instead of RGCN Model (avoid unecessary sum readouts)

* Added docstrings and fixed highway update implementation

* Make number of relationship configurable

* little help of black for linting

* Cleaning upuseless imports

* Sharing attention between right and left side

* Adding reference to GCNBMP docstring

* Type hinting everything

* Fixing docstring in example

* - Removing type hints in docstrings as they were added to signatures
- Chunked iteration of the BMP backbone for better readability

* Ading more-itertools as a dependecy

* Using pairwise for encoder construction

* Adding missing docstrings

* Fixing linting and precommit hook

* Fixing the citation back to what is in main

* Tests,formatting,example

* Tests,formatting,example

* GCNBMP

* Cleanup

Co-authored-by: kcvc236 <kcvc236@seskscpg057.prim.scp>
Co-authored-by: Rozemberczki <kmdb028@astrazeneca.net>
Co-authored-by: kcvc236 <kcvc236@seskscpg059.prim.scp>
Co-authored-by: Charles Tapley Hoyt <cthoyt@gmail.com>
* update: Add deepddi model

* update: Add deepddi examples

* update: Add deepddi test case

* Style: deepddi model

* Style: deepddi model

* Style: deepddi_examples.py

* Update deepddi.py

* Update deepddi.py

Co-authored-by: Charles Tapley Hoyt <cthoyt@gmail.com>
@benedekrozemberczki benedekrozemberczki merged commit 6463147 into AstraZeneca:main Feb 3, 2022
@benedekrozemberczki benedekrozemberczki linked an issue Feb 3, 2022 that may be closed by this pull request
@cthoyt
Copy link
Collaborator

cthoyt commented Feb 3, 2022

I have several concerns with this PR, would have been nice to do a review first. Most importantly: why does it change the standard interface of the forward() function? I don't see where any of the other things it returns are used

@benedekrozemberczki
Copy link
Contributor

benedekrozemberczki commented Feb 3, 2022

The paper discusses two types of training techniques - supervised and unsupervised. In the unsupervised setting you could use any type of drug pair dataset. This forward pass allows for both setups, in our experiments we only consider supervised ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the CASTER model
7 participants