-
Notifications
You must be signed in to change notification settings - Fork 0
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
Hyperparam opt, more models, more flexible training #2
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For the DNSM, I've decided to drop the padding mask because now we're looking at masking for all of the sequence with Ns. But here is the old version: def forward(self, parent_onehots: Tensor, padding_mask: Tensor) -> Tensor:
"""Build a binary log selection matrix from a one-hot encoded parent sequence.
Because we're predicting log of the selection factor, we don't use an
activation function after the transformer.
Parameters:
parent_onehots: A tensor of shape (B, L, 20) representing the one-hot encoding of parent sequences.
padding_mask: A tensor of shape (B, L) representing the padding mask for the sequence.
Returns:
A tensor of shape (B, L, 1) representing the log level of selection
for each amino acid site.
"""
# Multiply by sqrt(d_model) to match the transformer paper.
parent_onehots = parent_onehots * math.sqrt(self.d_model)
# Have to do the permutation because the positional encoding expects the
# sequence length to be the first dimension.
parent_onehots = self.pos_encoder(parent_onehots.permute(1, 0, 2)).permute(
1, 0, 2
)
# NOTE: not masking due to MPS bug
out = self.encoder(parent_onehots) # , src_key_padding_mask=padding_mask)
out = self.linear(out)
out = F.logsigmoid(out)
return out.squeeze(-1)
def selection_factors_of_aa_str(self, aa_str: str):
"""Do the forward method without gradients from an amino acid string and convert to numpy.
Parameters:
aa_str: A string of amino acids.
Returns:
A numpy array of the same length as the input string representing
the level of selection for each amino acid site.
"""
aa_onehot = sequences.aa_onehot_tensor_of_str(aa_str)
model_device = next(self.parameters()).device
# Create a padding mask with False values (i.e., no padding)
padding_mask = torch.zeros(len(aa_str), dtype=torch.bool).to(model_device)
with torch.no_grad():
aa_onehot = aa_onehot.to(model_device)
model_out = self(aa_onehot.unsqueeze(0), padding_mask.unsqueeze(0)).squeeze(
0
)
final_out = torch.exp(model_out)
return final_out[: len(aa_str)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.