From 142bb3aef34d707b83c46edad07925b4c2e52d1a Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Sat, 9 May 2020 08:44:52 +0200 Subject: [PATCH] Added dropout_sparse() --- decagon_pytorch/__init__.py | 3 +++ decagon_pytorch/dropout.py | 18 ++++++++++++++++++ decagon_pytorch/model.py | 0 decagon_pytorch/{weight.py => weights.py} | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 decagon_pytorch/__init__.py create mode 100644 decagon_pytorch/dropout.py create mode 100644 decagon_pytorch/model.py rename decagon_pytorch/{weight.py => weights.py} (85%) mode change 100755 => 100644 diff --git a/decagon_pytorch/__init__.py b/decagon_pytorch/__init__.py new file mode 100644 index 0000000..f628a28 --- /dev/null +++ b/decagon_pytorch/__init__.py @@ -0,0 +1,3 @@ +from .weights import * +from .convolve import * +from .model import * diff --git a/decagon_pytorch/dropout.py b/decagon_pytorch/dropout.py new file mode 100644 index 0000000..3162572 --- /dev/null +++ b/decagon_pytorch/dropout.py @@ -0,0 +1,18 @@ +import torch + + +def dropout_sparse(x, keep_prob): + """Dropout for sparse tensors. + """ + x = x.coalesce() + i = x._indices() + v = x._values() + size = x.size() + + n = keep_prob + torch.rand(len(v)) + n = torch.floor(n).to(torch.bool) + i = i[:,n] + v = v[n] + x = torch.sparse_coo_tensor(i, v, size=size) + + return x * (1./keep_prob) diff --git a/decagon_pytorch/model.py b/decagon_pytorch/model.py new file mode 100644 index 0000000..e69de29 diff --git a/decagon_pytorch/weight.py b/decagon_pytorch/weights.py old mode 100755 new mode 100644 similarity index 85% rename from decagon_pytorch/weight.py rename to decagon_pytorch/weights.py index 5321660..305a70f --- a/decagon_pytorch/weight.py +++ b/decagon_pytorch/weights.py @@ -2,7 +2,7 @@ import torch import numpy as np -def weight_variable_glorot(input_dim, output_dim): +def init_glorot(input_dim, output_dim): """Create a weight variable with Glorot & Bengio (AISTATS 2010) initialization. """