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

DTNNEmbedding Layer Parameter Error Fix #3455

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deepchem/models/tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,8 @@ def test_dtnn_embedding():
[-0.26653743, 0.15180665, 0.21961051, -0.7263894, -0.4521287],
[0.1925143, -0.5505201, -0.35381562, -0.7409675, 0.6427947]]
embedding_layer_torch = torch_layers.DTNNEmbedding(5, 5, 'xavier_uniform_')
embedding_layer_torch.embedding_list = torch.tensor(embeddings_tf)
embedding_layer_torch.embedding_list = torch.nn.Parameter(
torch.tensor(embeddings_tf))
result_torch = embedding_layer_torch(torch.tensor([3, 2, 4]))
assert torch.allclose(torch.tensor(results_tf), result_torch)
assert result_torch.shape == (3, 5)
Expand Down
28 changes: 15 additions & 13 deletions deepchem/models/torch_models/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2986,16 +2986,6 @@ class DTNNEmbedding(nn.Module):
[1] Schütt, Kristof T., et al. "Quantum-chemical insights from deep
tensor neural networks." Nature communications 8.1 (2017): 1-8.

Parameters
----------
n_embedding: int, optional
Number of features for each atom
periodic_table_length: int, optional
Length of embedding, 83=Bi
initalizer: str, optional
Weight initialization for filters.
Options: {xavier_uniform_, xavier_normal_, kaiming_uniform_, kaiming_normal_, trunc_normal_}

Examples
--------
>>> from deepchem.models.torch_models import layers
Expand All @@ -3012,15 +3002,27 @@ def __init__(self,
periodic_table_length: int = 30,
initalizer: str = 'xavier_uniform_',
**kwargs):

"""
Parameters
----------
n_embedding: int, optional
Number of features for each atom
periodic_table_length: int, optional
Length of embedding, 83=Bi
Copy link
Member

Choose a reason for hiding this comment

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

We should clean this up and explain what 83 means

Copy link
Member

Choose a reason for hiding this comment

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

We can do this in a follow up PR @GreatRSingh

initalizer: str, optional
Weight initialization for filters.
Options: {xavier_uniform_, xavier_normal_, kaiming_uniform_, kaiming_normal_, trunc_normal_}

"""
super(DTNNEmbedding, self).__init__(**kwargs)
self.n_embedding = n_embedding
self.periodic_table_length = periodic_table_length
self.initalizer = initalizer # Set weight initialization

init_func: Callable = getattr(initializers, self.initalizer)
self.embedding_list: torch.Tensor = init_func(
torch.empty([self.periodic_table_length, self.n_embedding]))
self.embedding_list: nn.Parameter = nn.Parameter(
init_func(
torch.empty([self.periodic_table_length, self.n_embedding])))

def __repr__(self) -> str:
"""Returns a string representing the configuration of the layer.
Expand Down
Loading