Skip to content

frtennis1/namedtensor

 
 

Repository files navigation

NamedTensor

Introduction

A proposal for a named tensor for PyTorch described in the blog post:

http://nlp.seas.harvard.edu/NamedTensor

Currently the library targets the PyTorch ecosystem and Python >= 3.6.

Usage

from namedtensor import ntorch

Creation and manipulation:

x = ntorch.randn(dict(batch=10, h=10, w=20))
x = x.log()
x = x.float()
x = ntorch.exp(x)
x.shape

Transposition:

x = x.transpose("batch", "w", "h")

# or early dim stay in place 

x = x.transpose("w", "h")

View replacements:

x = x.stack(stacked = ("w", "h"))

# Roundtrip

x = x.split(stacked = ("w", "h"), w=20)

Dim replacements:

x = x.narrow("w", 0, 10)
x = x.softmax("w")

Reduction:

x = x.mean("w")
x, argmax = x.max("w")

Matrix Operations / EinSum:

x = ntorch.randn(dict(batch=10, h=10, w=20))
y = ntorch.randn(dict(batch=10, w=20, c=30))
x.dot(y, "w")

NN Modules

linear = ntorch.nn.Linear(20, 25)
x = linear(x)

# or 

linear.rename(wout="w")
x = linear(x)

Other Goodies

  • Named NN
  • Named Distributions libary

Documentation

http://nlp.seas.harvard.edu/namedtensor/

Authors

About

Proof of concept for a dynamic named tensor for pytorch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 85.3%
  • Python 14.4%
  • Other 0.3%