PolyTorch 0.1.4__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,27 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: PolyTorch
3
- Version: 0.1.4
3
+ Version: 0.2.2
4
4
  Summary: Embeddings and loss functions for different data types.
5
- License: Apache-2.0
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
6
7
  Keywords: pytorch,deep learning,command-line interface
7
8
  Author: Robert Turnbull
8
9
  Author-email: robert.turnbull@unimelb.edu.au
9
10
  Requires-Python: >=3.10,<4.0
10
11
  Classifier: Intended Audience :: Science/Research
11
- Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
17
18
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
19
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
20
  Requires-Dist: attrs (>=19)
20
21
  Requires-Dist: hierarchicalsoftmax (>=1.4.1)
21
- Requires-Dist: kaleido (==0.2.1)
22
- Requires-Dist: plotly (>=5.15.0)
22
+ Requires-Dist: kaleido (>=1.0.0,<2)
23
+ Requires-Dist: pandas (>=2.3.3,<3.0.0)
24
+ Requires-Dist: plotly (>=6.1.1)
23
25
  Requires-Dist: scikit-learn (>=1.0.2)
24
26
  Requires-Dist: torch (>=1.10.2)
25
27
  Project-URL: Documentation, https://rbturnbull.github.io/polytorch
@@ -60,7 +62,7 @@ Embeddings and loss functions for different data types.
60
62
  Installation
61
63
  ==================================
62
64
 
63
- Install using pip:
65
+ Requires Python 3.10 or later. Install using pip:
64
66
 
65
67
  .. code-block:: bash
66
68
 
@@ -73,10 +75,17 @@ Or install the latest version from GitHub:
73
75
  pip install git+https://github.com/rbturnbull/polytorch.git
74
76
 
75
77
 
78
+ Static image export uses Kaleido 1.x and requires Chrome or Chromium.
79
+ If no compatible browser is installed, install one with:
80
+
81
+ .. code-block:: bash
82
+
83
+ plotly_get_chrome
84
+
76
85
  Data Types
77
86
  ==================================
78
87
 
79
- This package allow you to input and output different data types in PyTorch models.
88
+ This package allows you to input and output different data types in PyTorch models.
80
89
 
81
90
  Binary Data
82
91
  ----------------------------------------
@@ -88,7 +97,7 @@ Binary Data
88
97
  binary_data = BinaryData()
89
98
 
90
99
  # Or with labels and colors
91
- binary_data = BinaryData(labels=["no_feature", "with_feature", colors=["red", "blue"])
100
+ binary_data = BinaryData(labels=["no_feature", "with_feature"], colors=["red", "blue"])
92
101
 
93
102
  Categorical Data
94
103
  ----------------------------------------
@@ -115,10 +124,10 @@ Ordinal Data
115
124
 
116
125
  from polytorch import OrdinalData
117
126
 
118
- ordinal_data = OrdinalData()
127
+ ordinal_data = OrdinalData(category_count=5)
119
128
 
120
129
  # Or with color
121
- ordinal_data = OrdinalData(color="pink")
130
+ ordinal_data = OrdinalData(category_count=5, color="pink")
122
131
 
123
132
  Continuous Data
124
133
  ----------------------------------------
@@ -140,7 +149,7 @@ Hierarchical Data
140
149
  .. code-block:: python
141
150
 
142
151
  from polytorch import HierarchicalData
143
- from hiearchicalsoftmax import SoftmaxNode
152
+ from hierarchicalsoftmax import SoftmaxNode
144
153
 
145
154
  root = SoftmaxNode("root")
146
155
  child1 = SoftmaxNode("child1", parent=root)
@@ -152,6 +161,21 @@ Hierarchical Data
152
161
 
153
162
 
154
163
  hierarchical_data = HierarchicalData(root)
164
+
165
+ Build a hierarchy from slash-separated paths with ``from_series``:
166
+
167
+ .. code-block:: python
168
+
169
+ import pandas as pd
170
+
171
+ hierarchical_data, node_ids = HierarchicalData.from_series(
172
+ "taxonomy",
173
+ pd.Series(["Animal/Mammal/Dog", "Animal/Bird/Eagle", " Animal / Mammal / Dog "]),
174
+ )
175
+ assert node_ids[0] == node_ids[2]
176
+
177
+ Whitespace around each path component is stripped. Shared paths reuse nodes.
178
+ Multiple top-level names are joined under a virtual ``__root__`` node.
155
179
 
156
180
  Embedding your data
157
181
  ==================================
@@ -159,7 +183,7 @@ Embedding your data
159
183
  .. code-block:: python
160
184
 
161
185
  from torch import nn
162
- from polytorch import Embedding
186
+ from polytorch import PolyEmbedding
163
187
 
164
188
  class MyModule(nn.Module):
165
189
  def __init__(self, embedding_size:int=128):
@@ -211,17 +235,47 @@ You can also get your model to output to different data types.
211
235
  # Output to different data types
212
236
  return self.output(x)
213
237
 
214
- Then add set this as the loss:
238
+ Use these data types to configure the loss:
215
239
 
216
240
  .. code-block:: python
217
241
 
218
242
  from polytorch import PolyLoss
219
243
 
220
- loss_module = PolyLoss(output_types=output_types)
244
+ loss_module = PolyLoss(data_types=output_types)
221
245
 
222
246
  # In your training loop
223
247
  loss = loss_module(predictions, categorical_target, binary_target, continuous_target)
224
248
 
249
+ DataFrames
250
+ ====================
251
+
252
+ Use ``PolyDataFrame`` with a pandas dataframe or a CSV file supplied as a
253
+ ``pathlib.Path``. Annotate columns as ``name:type``; unannotated columns are
254
+ available by name but are omitted from row tuples and ``data_types``.
255
+
256
+ .. code-block:: python
257
+
258
+ import pandas as pd
259
+ from polytorch import PolyDataFrame
260
+
261
+ frame = PolyDataFrame(pd.DataFrame({
262
+ "id": [100, 101],
263
+ "tree:Hierarchical": ["Animal/Dog", "Animal/Cat"],
264
+ "score:continuous": [0.25, 0.75],
265
+ }))
266
+ tree_id, score = frame[0]
267
+ assert score == 0.25
268
+ assert frame["score", 1] == 0.75
269
+ assert frame["id"][0] == 100
270
+ assert [data_type.name for data_type in frame.data_types] == ["tree", "score"]
271
+
272
+ Types accept an optional ``Data`` suffix (for example, ``ContinuousData``).
273
+ Use ``data_columns={"score"}`` to select annotated columns by name. Row tuples
274
+ and ``data_types`` follow the original column order. Categorical and ordinal
275
+ values are returned unchanged; supply integer category indices for use with
276
+ embeddings and cross-entropy loss.
277
+
278
+
225
279
  .. end-quickstart
226
280
 
227
281
 
@@ -230,10 +284,8 @@ Credits
230
284
 
231
285
  .. start-credits
232
286
 
233
- Robert Turnbull
234
- For more information contact: <robert.turnbull@unimelb.edu.au>
287
+ `Robert Turnbull <https://robturnbull.com>`_ (Melbourne Data Analytics Platform, The University of Melbourne)
235
288
 
236
- Created using torchapp (https://github.com/rbturnbull/torchapp).
237
289
 
238
290
  .. end-credits
239
291
 
@@ -31,7 +31,7 @@ Embeddings and loss functions for different data types.
31
31
  Installation
32
32
  ==================================
33
33
 
34
- Install using pip:
34
+ Requires Python 3.10 or later. Install using pip:
35
35
 
36
36
  .. code-block:: bash
37
37
 
@@ -44,10 +44,17 @@ Or install the latest version from GitHub:
44
44
  pip install git+https://github.com/rbturnbull/polytorch.git
45
45
 
46
46
 
47
+ Static image export uses Kaleido 1.x and requires Chrome or Chromium.
48
+ If no compatible browser is installed, install one with:
49
+
50
+ .. code-block:: bash
51
+
52
+ plotly_get_chrome
53
+
47
54
  Data Types
48
55
  ==================================
49
56
 
50
- This package allow you to input and output different data types in PyTorch models.
57
+ This package allows you to input and output different data types in PyTorch models.
51
58
 
52
59
  Binary Data
53
60
  ----------------------------------------
@@ -59,7 +66,7 @@ Binary Data
59
66
  binary_data = BinaryData()
60
67
 
61
68
  # Or with labels and colors
62
- binary_data = BinaryData(labels=["no_feature", "with_feature", colors=["red", "blue"])
69
+ binary_data = BinaryData(labels=["no_feature", "with_feature"], colors=["red", "blue"])
63
70
 
64
71
  Categorical Data
65
72
  ----------------------------------------
@@ -86,10 +93,10 @@ Ordinal Data
86
93
 
87
94
  from polytorch import OrdinalData
88
95
 
89
- ordinal_data = OrdinalData()
96
+ ordinal_data = OrdinalData(category_count=5)
90
97
 
91
98
  # Or with color
92
- ordinal_data = OrdinalData(color="pink")
99
+ ordinal_data = OrdinalData(category_count=5, color="pink")
93
100
 
94
101
  Continuous Data
95
102
  ----------------------------------------
@@ -111,7 +118,7 @@ Hierarchical Data
111
118
  .. code-block:: python
112
119
 
113
120
  from polytorch import HierarchicalData
114
- from hiearchicalsoftmax import SoftmaxNode
121
+ from hierarchicalsoftmax import SoftmaxNode
115
122
 
116
123
  root = SoftmaxNode("root")
117
124
  child1 = SoftmaxNode("child1", parent=root)
@@ -123,6 +130,21 @@ Hierarchical Data
123
130
 
124
131
 
125
132
  hierarchical_data = HierarchicalData(root)
133
+
134
+ Build a hierarchy from slash-separated paths with ``from_series``:
135
+
136
+ .. code-block:: python
137
+
138
+ import pandas as pd
139
+
140
+ hierarchical_data, node_ids = HierarchicalData.from_series(
141
+ "taxonomy",
142
+ pd.Series(["Animal/Mammal/Dog", "Animal/Bird/Eagle", " Animal / Mammal / Dog "]),
143
+ )
144
+ assert node_ids[0] == node_ids[2]
145
+
146
+ Whitespace around each path component is stripped. Shared paths reuse nodes.
147
+ Multiple top-level names are joined under a virtual ``__root__`` node.
126
148
 
127
149
  Embedding your data
128
150
  ==================================
@@ -130,7 +152,7 @@ Embedding your data
130
152
  .. code-block:: python
131
153
 
132
154
  from torch import nn
133
- from polytorch import Embedding
155
+ from polytorch import PolyEmbedding
134
156
 
135
157
  class MyModule(nn.Module):
136
158
  def __init__(self, embedding_size:int=128):
@@ -182,17 +204,47 @@ You can also get your model to output to different data types.
182
204
  # Output to different data types
183
205
  return self.output(x)
184
206
 
185
- Then add set this as the loss:
207
+ Use these data types to configure the loss:
186
208
 
187
209
  .. code-block:: python
188
210
 
189
211
  from polytorch import PolyLoss
190
212
 
191
- loss_module = PolyLoss(output_types=output_types)
213
+ loss_module = PolyLoss(data_types=output_types)
192
214
 
193
215
  # In your training loop
194
216
  loss = loss_module(predictions, categorical_target, binary_target, continuous_target)
195
217
 
218
+ DataFrames
219
+ ====================
220
+
221
+ Use ``PolyDataFrame`` with a pandas dataframe or a CSV file supplied as a
222
+ ``pathlib.Path``. Annotate columns as ``name:type``; unannotated columns are
223
+ available by name but are omitted from row tuples and ``data_types``.
224
+
225
+ .. code-block:: python
226
+
227
+ import pandas as pd
228
+ from polytorch import PolyDataFrame
229
+
230
+ frame = PolyDataFrame(pd.DataFrame({
231
+ "id": [100, 101],
232
+ "tree:Hierarchical": ["Animal/Dog", "Animal/Cat"],
233
+ "score:continuous": [0.25, 0.75],
234
+ }))
235
+ tree_id, score = frame[0]
236
+ assert score == 0.25
237
+ assert frame["score", 1] == 0.75
238
+ assert frame["id"][0] == 100
239
+ assert [data_type.name for data_type in frame.data_types] == ["tree", "score"]
240
+
241
+ Types accept an optional ``Data`` suffix (for example, ``ContinuousData``).
242
+ Use ``data_columns={"score"}`` to select annotated columns by name. Row tuples
243
+ and ``data_types`` follow the original column order. Categorical and ordinal
244
+ values are returned unchanged; supply integer category indices for use with
245
+ embeddings and cross-entropy loss.
246
+
247
+
196
248
  .. end-quickstart
197
249
 
198
250
 
@@ -201,10 +253,8 @@ Credits
201
253
 
202
254
  .. start-credits
203
255
 
204
- Robert Turnbull
205
- For more information contact: <robert.turnbull@unimelb.edu.au>
256
+ `Robert Turnbull <https://robturnbull.com>`_ (Melbourne Data Analytics Platform, The University of Melbourne)
206
257
 
207
- Created using torchapp (https://github.com/rbturnbull/torchapp).
208
258
 
209
259
  .. end-credits
210
260
 
@@ -0,0 +1,16 @@
1
+ """Embeddings, output layers, losses, and typed dataframes for PyTorch."""
2
+
3
+ from .data import (
4
+ BinaryData,
5
+ CategoricalData,
6
+ ContinuousData,
7
+ OrdinalData,
8
+ HierarchicalData,
9
+ PolyData,
10
+ )
11
+ from .embedding import PolyEmbedding
12
+ from .loss import PolyLoss
13
+ from .enums import ContinuousLossType, CategoricalLossType, BinaryLossType
14
+ from .modules import PolyLinear, PolyLazyLinear
15
+ from .util import split_tensor, total_size
16
+ from .dataframe import PolyDataFrame