Skip to content
Open
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
Binary file removed .DS_Store
Binary file not shown.
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Jupyter Notebook
.ipynb_checkpoints

# VS Code
.vscode/

# MAC
.DS_Store


data/*
Binary file removed __pycache__/preprocession.cpython-37.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import json
from torch.utils.data import IterableDataset

class ConceptFlowDataset(IterableDataset):
def __init__(self, txt_file, config):
self.root_dir = config.data_dir
self.txt_file = txt_file

def __iter__(self):
f = open(f'{self.root_dir}/{self.txt_file}')
return map(json.loads, f)
Binary file removed model/.DS_Store
Binary file not shown.
Binary file removed model/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file removed model/__pycache__/central.cpython-37.pyc
Binary file not shown.
Binary file removed model/__pycache__/conceptflow.cpython-37.pyc
Binary file not shown.
Binary file removed model/__pycache__/embedding.cpython-37.pyc
Binary file not shown.
Binary file removed model/__pycache__/model.cpython-37.pyc
Binary file not shown.
Binary file removed model/__pycache__/outer.cpython-37.pyc
Binary file not shown.
23 changes: 9 additions & 14 deletions model/central.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,14 @@ class LeftMMFixed(torch.autograd.Function):
Implementation of matrix multiplication of a Sparse Variable with a Dense Variable, returning a Dense one.
This is added because there's no autograd for sparse yet. No gradient computed on the sparse weights.
"""

def __init__(self):
super(LeftMMFixed, self).__init__()
self.sparse_weights = None

def forward(self, sparse_weights, x):
if self.sparse_weights is None:
self.sparse_weights = sparse_weights
return torch.mm(self.sparse_weights, x)

def backward(self, grad_output):
sparse_weights = self.sparse_weights
@staticmethod
def forward(ctx, sparse_weights, x):
ctx.sparse_weights = sparse_weights
return torch.mm(ctx.sparse_weights, x)

@staticmethod
def backward(ctx, grad_output):
sparse_weights = ctx.sparse_weights
return None, torch.mm(sparse_weights.t(), grad_output)

I = X._indices()
Expand All @@ -156,6 +152,5 @@ def backward(self, grad_output):
lookup = Y[I[0, :], I[2, :], :]
X_I = torch.stack((I[0, :] * M + I[1, :], use_cuda(torch.arange(Z).type(torch.LongTensor))), 0)
S = use_cuda(Variable(torch.sparse.FloatTensor(X_I, V, torch.Size([B * M, Z])), requires_grad=False))
prod_op = LeftMMFixed()
prod = prod_op(S, lookup)
prod = LeftMMFixed.apply(S, lookup)
return prod.view(B, M, K)
Loading