Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit 547b3da

Browse files
author
Christian Puhrsch
committed
README.md nits
1 parent 8212f8f commit 547b3da

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
PLEASE NOTE, NESTEDTENSOR IS UNDER ACTIVE DEVELOPMENT AND EVERYTHING HERE IS SUBJECT TO CHANGE.
1+
# The nestedtensor package
22

3-
# Motivation
3+
NOTE: PLEASE NOTE, NESTEDTENSOR IS UNDER ACTIVE DEVELOPMENT AND EVERYTHING HERE IS SUBJECT TO CHANGE.
4+
5+
## Motivation
46

57
We often want to manipulate collections of Tensors of different shapes. For example, paragraphs of text, images of different sizes or audio files of different lengths. We don't have a first class generalization that eases the concurrent manipulation of collections of this type of data. We further often want to batch arbitrary data and operations for efficiency, which then leads us to write awkward workarounds such as padding.
68

@@ -71,14 +73,43 @@ If given a NestedTensor or Tensor it will return a detached copy, which is consi
7173
A user can retrieve the constituent Tensors via unbind. Unbind is currently used by torch to turn Tensors into tuples of Tensors. Unbind always returns a tuple of views.
7274

7375
```
74-
a = [ \
75-
[torch.rand(2, 3), torch.rand(4, 5)], \
76-
[torch.rand(6, 7)] \
77-
]
78-
79-
b = torch.nested_tensor(a)
80-
b1 = b.unbind() # Tuple of 2 NestedTensors
81-
b2 = b1[0].unbind() # Tuple of 2 Tensors
76+
>>> from nestedtensor import torch
77+
>>>
78+
>>> a = [
79+
... [torch.rand(1, 2), torch.rand(2, 1)],
80+
... [torch.rand(3, 2)]
81+
... ]
82+
>>>
83+
>>> b = torch.nested_tensor(a)
84+
>>> print(b)
85+
nested_tensor([
86+
[
87+
tensor([[0.5356, 0.5609]]),
88+
tensor([[0.1567],
89+
[0.8880]])
90+
],
91+
[
92+
tensor([[0.4060, 0.4359],
93+
[0.4069, 0.3802],
94+
[0.0040, 0.3759]])
95+
]
96+
])
97+
>>> b1 = b.unbind() # Tuple of 2 NestedTensors
98+
>>> print(b1)
99+
(nested_tensor([
100+
tensor([[0.5356, 0.5609]]),
101+
tensor([[0.1567],
102+
[0.8880]])
103+
]), nested_tensor([
104+
tensor([[0.4060, 0.4359],
105+
[0.4069, 0.3802],
106+
[0.0040, 0.3759]])
107+
]))
108+
>>> b2 = b1[0].unbind() # Tuple of 2 Tensors
109+
>>> print(b2)
110+
(tensor([[0.5356, 0.5609]]),
111+
tensor([[0.1567],
112+
[0.8880]]))
82113
```
83114

84115
### Other Ops
@@ -89,8 +120,7 @@ We currently lack detailed documentation for all supported ops. Please see the e
89120
The nestedtensor package allows the user to decorate existing functions with a tensorwise decorator. This decorator lifts the given function to check for NestedTensor arguments and recursively apply it to their constituents.
90121

91122
```
92-
>>> import torch
93-
>>> import nestedtensor
123+
>>> from nestedtensor import torch
94124
>>>
95125
>>> @torch.tensorwise()
96126
... def simple_fn(t1, t2):

0 commit comments

Comments
 (0)