All Projects → harvardnlp → Namedtensor

harvardnlp / Namedtensor

Licence: mit
Named Tensor implementation for Torch

Projects that are alternatives of or similar to Namedtensor

User Machine Learning Tutorial
useR! 2016 Tutorial: Machine Learning Algorithmic Deep Dive http://user2016.org/tutorials/10.html
Stars: ✭ 393 (-2.48%)
Mutual labels:  jupyter-notebook
Icnet Tensorflow
TensorFlow-based implementation of "ICNet for Real-Time Semantic Segmentation on High-Resolution Images".
Stars: ✭ 396 (-1.74%)
Mutual labels:  jupyter-notebook
Trainyourownyolo
Train a state-of-the-art yolov3 object detector from scratch!
Stars: ✭ 399 (-0.99%)
Mutual labels:  jupyter-notebook
Ijcai 2018
ijcai-2018 top1 solution
Stars: ✭ 395 (-1.99%)
Mutual labels:  jupyter-notebook
Jupyter Renderers
Renderers and renderer extensions for JupyterLab
Stars: ✭ 395 (-1.99%)
Mutual labels:  jupyter-notebook
Pandas
Data & Code for my video on the Pandas library of Python
Stars: ✭ 397 (-1.49%)
Mutual labels:  jupyter-notebook
Megvii Pku Dl Course
Homepage for the joint course of Megvii Inc. and Peking University on Deep Learning.
Stars: ✭ 393 (-2.48%)
Mutual labels:  jupyter-notebook
Tensorflow 101
《TensorFlow 快速入门与实战》和《TensorFlow 2 项目进阶实战》课程代码与课件
Stars: ✭ 402 (-0.25%)
Mutual labels:  jupyter-notebook
Notes On Dirichlet Processes
🎲 Notes explaining Dirichlet Processes, HDPs, and Latent Dirichlet Allocation
Stars: ✭ 396 (-1.74%)
Mutual labels:  jupyter-notebook
Vcdb
VERIS Community Database
Stars: ✭ 398 (-1.24%)
Mutual labels:  jupyter-notebook
Ephemera Miscellany
Ephemera and other documentation associated with the 1337list project.
Stars: ✭ 395 (-1.99%)
Mutual labels:  jupyter-notebook
Pytorch classification
利用pytorch实现图像分类的一个完整的代码,训练,预测,TTA,模型融合,模型部署,cnn提取特征,svm或者随机森林等进行分类,模型蒸馏,一个完整的代码
Stars: ✭ 395 (-1.99%)
Mutual labels:  jupyter-notebook
Automl
Google Brain AutoML
Stars: ✭ 4,795 (+1089.83%)
Mutual labels:  jupyter-notebook
Motion Cosegmentation
Reference code for "Motion-supervised Co-Part Segmentation" paper
Stars: ✭ 393 (-2.48%)
Mutual labels:  jupyter-notebook
Triplet recommendations keras
An example of doing MovieLens recommendations using triplet loss in Keras
Stars: ✭ 400 (-0.74%)
Mutual labels:  jupyter-notebook
Baiduyun deeplearning competition
百度云魅族深度学习应用大赛
Stars: ✭ 393 (-2.48%)
Mutual labels:  jupyter-notebook
Bloom Contrib
Making carbon footprint data available to everyone.
Stars: ✭ 398 (-1.24%)
Mutual labels:  jupyter-notebook
Deepsvg
[NeurIPS 2020] Official code for the paper "DeepSVG: A Hierarchical Generative Network for Vector Graphics Animation". Includes a PyTorch library for deep learning with SVG data.
Stars: ✭ 403 (+0%)
Mutual labels:  jupyter-notebook
Anlp19
Course repo for Applied Natural Language Processing (Spring 2019)
Stars: ✭ 402 (-0.25%)
Mutual labels:  jupyter-notebook
Face specific augm
Face Renderer to perform Domain (Face) Specific Data Augmentation
Stars: ✭ 398 (-1.24%)
Mutual labels:  jupyter-notebook

This draft implementation should now be considered completed. If you are interested in using Named Tensor check out the core PyTorch implementation:

https://pytorch.org/docs/stable/named_tensor.html

Thanks for everyone who contributed to this version.

Named Tensor for Torch

Build Status Coverage Status

Introduction

A proposal for a named tensor for Torch described here:

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

NamedTensor is an thin-wrapper on Torch tensor that makes three changes to the API:

  1. Naming: Dimension access and reduction use a named dim argument instead of an index. Constructing and adding dimensions use a name argument. Axis-based indexing [ ] is replaced by named indexing.
  2. Broadcasting: All functions broadcast based on set-operations not through heuristic ordering rules, e.g. if z = x + y then z has the union of the dimension in x and y.
  3. Lifting: Order-based functions can be lifted by providing name annotations through .spec methods. For instance, convolution requires the user to name the channel and kernel dims, e.g .conv2d.spec("channel", ("x", "y")). This provides dynamic checks, better error messages, and consistent documentation.

Setup

pip install git+https://github.com/harvardnlp/namedtensor

Usage

from namedtensor import ntorch

Building tensors.

All pytorch builders have an extra keyword argument names.

x = ntorch.randn(10, 10, 20, names=("batch", "h", "w"))
x = ntorch.ones(10, 10, 20, names=("batch", "h", "w"))

Standard functions

All functions that keep dimensionality work in the same way.

x = x.log()
x = x.float()
x = ntorch.exp(x)

Named Indexing

Indexing and masking operation work by name as opposed to absolute position.

first_batch = x[{"batch": 1}]
three_examples = x[{"batch": slice(1, 4)}]
masked = x[ x > 0.5 ]

Advanced indexing by named tensors.

select = ntorch.tensor([1, 4, 5], names=("rows",))
y = x[{"h": select}] 
# y shape ("batch", "rows", "w")

No view or unsqueeze

View, tranpose, and friends are deprecated in favor of named access and movement.

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

# Roundtrip

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

There is no need to ever have unsqueeze since broadcasting is done by name overlap.

Similar notation can be used for setting values.

All methods take named args

Any function with a dim argument now can be accessed based on the dimension name.

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

This is true of reductions functions as well, where the named dimension is eliminated.

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

Tensor contractions

Matrix operations also use the dimension arguments. We can replace einsum based on persistent names.

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

This also makes indexing much easier to read.

x = ntorch.ones(10, 10, 20, names=("batch", "time", "vocab"))
y = ntorch.randn(20, 30, names=("vocab", "embsize"))
y.index_select("vocab", x)

Removed Functions

The following functions are removed from the stdlib.

  • view, expand, squeeze, unsqueeze, transpose

NN Modules

NN units no longer take ordered tensors. They now have a required additional method spec that lets the user set the the input and output dimensions of the object.

Examples

  conv = ntorch.nn.Conv1d(5, 10, 2).spec("input", "time", "output")
  n = ntorch.randn(20, 30, 5, names=("batch", "time", "input"))
  out = conv(n)
  drop = ntorch.nn.Dropout()
  n = ntorch.randn(4, 20, names=("batch", "target"))
  out = drop(n)
  loss = ntorch.nn.NLLLoss().spec("target")
  predict = ntorch.randn(20, 4, names=("target", "batch"))
  target = ntorch.tensor([2, 2, 3, 4], names=("batch",))
  out = loss(predict, target)

Distributions

# Univariate
mu = ntorch.randn(10, names=("batch"))
sigma = ntorch.randn(10, names=("batch"))
dist = ntorch.distributions.Normal(mu, sigma)
sample = dist.sample((30, 40), names=("sample1", "sample2"))

# Discrete
params = ntorch.randn(10, 20, 30, names=("batch1", "batch2", "logits"))
dist = ntorch.distributions.Categorical(logits=params, logit_dim="logits")

Documentation

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

Author

Contributors

(NamedTensor is being collectively developed by Harvard CS 287)

  • Yuntian Deng
  • Justin Chiu
  • Francisco Rivera
  • Jiafeng Chen
  • Celine Liang
  • Miro Furtado
  • Roshan Padaki
  • Mirac Suzgun
  • Belén Saldías
  • Jason Ren
  • Josh Feldman
  • Jambay Kinley
  • Ian Kivlichan
  • Sanyuan Chen
  • Simon Shen
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].