You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 15, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+42-12Lines changed: 42 additions & 12 deletions
Original file line number
Diff line number
Diff 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
2
2
3
-
# Motivation
3
+
NOTE: PLEASE NOTE, NESTEDTENSOR IS UNDER ACTIVE DEVELOPMENT AND EVERYTHING HERE IS SUBJECT TO CHANGE.
4
+
5
+
## Motivation
4
6
5
7
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.
6
8
@@ -71,14 +73,43 @@ If given a NestedTensor or Tensor it will return a detached copy, which is consi
71
73
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.
72
74
73
75
```
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]]))
82
113
```
83
114
84
115
### Other Ops
@@ -89,8 +120,7 @@ We currently lack detailed documentation for all supported ops. Please see the e
89
120
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.
0 commit comments