Skip to content

Commit 098a07f

Browse files
authored
feat: infer input size of forward and LSTM layers (#808)
### Summary of Changes * Users no longer need to specify input sizes of forward and LSTM layers. * The constructor parameter `output_size` of these two layers has been renamed to `neuron_count`.
1 parent 69a780c commit 098a07f

26 files changed

+504
-648
lines changed

docs/tutorials/classification.ipynb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"metadata": {
3333
"collapsed": false
3434
},
35-
"outputs": [],
36-
"execution_count": null
35+
"execution_count": null,
36+
"outputs": []
3737
},
3838
{
3939
"cell_type": "markdown",
@@ -55,8 +55,8 @@
5555
"metadata": {
5656
"collapsed": false
5757
},
58-
"outputs": [],
59-
"execution_count": null
58+
"execution_count": null,
59+
"outputs": []
6060
},
6161
{
6262
"cell_type": "markdown",
@@ -80,8 +80,8 @@
8080
"metadata": {
8181
"collapsed": false
8282
},
83-
"outputs": [],
84-
"execution_count": null
83+
"execution_count": null,
84+
"outputs": []
8585
},
8686
{
8787
"cell_type": "markdown",
@@ -98,8 +98,8 @@
9898
"metadata": {
9999
"collapsed": false
100100
},
101-
"outputs": [],
102-
"execution_count": null
101+
"execution_count": null,
102+
"outputs": []
103103
},
104104
{
105105
"cell_type": "markdown",
@@ -118,8 +118,8 @@
118118
"metadata": {
119119
"collapsed": false
120120
},
121-
"outputs": [],
122-
"execution_count": null
121+
"execution_count": null,
122+
"outputs": []
123123
},
124124
{
125125
"cell_type": "markdown",
@@ -139,8 +139,8 @@
139139
"metadata": {
140140
"collapsed": false
141141
},
142-
"outputs": [],
143-
"execution_count": null
142+
"execution_count": null,
143+
"outputs": []
144144
},
145145
{
146146
"cell_type": "markdown",
@@ -166,8 +166,8 @@
166166
"metadata": {
167167
"collapsed": false
168168
},
169-
"outputs": [],
170-
"execution_count": null
169+
"execution_count": null,
170+
"outputs": []
171171
},
172172
{
173173
"cell_type": "markdown",
@@ -189,8 +189,8 @@
189189
"metadata": {
190190
"collapsed": false
191191
},
192-
"outputs": [],
193-
"execution_count": null
192+
"execution_count": null,
193+
"outputs": []
194194
}
195195
],
196196
"metadata": {

docs/tutorials/convolutional_neural_network_for_image_classification.ipynb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
"metadata": {
5353
"collapsed": true
5454
},
55-
"outputs": [],
5655
"source": [
5756
"from safeds.data.image.containers import ImageList\n",
5857
"\n",
5958
"images, filepaths = ImageList.from_files(\"data/shapes\", return_filenames=True)"
60-
]
59+
],
60+
"outputs": []
6161
},
6262
{
6363
"cell_type": "markdown",
@@ -71,7 +71,6 @@
7171
},
7272
{
7373
"cell_type": "code",
74-
"outputs": [],
7574
"source": [
7675
"import re\n",
7776
"from safeds.data.tabular.containers import Column\n",
@@ -85,7 +84,8 @@
8584
"collapsed": false
8685
},
8786
"id": "66dcf95a3fa51f23",
88-
"execution_count": null
87+
"execution_count": null,
88+
"outputs": []
8989
},
9090
{
9191
"cell_type": "markdown",
@@ -99,7 +99,6 @@
9999
},
100100
{
101101
"cell_type": "code",
102-
"outputs": [],
103102
"source": [
104103
"from safeds.data.labeled.containers import ImageDataset\n",
105104
"\n",
@@ -109,7 +108,8 @@
109108
"collapsed": false
110109
},
111110
"id": "32056ddf5396e070",
112-
"execution_count": null
111+
"execution_count": null,
112+
"outputs": []
113113
},
114114
{
115115
"cell_type": "markdown",
@@ -131,7 +131,6 @@
131131
},
132132
{
133133
"cell_type": "code",
134-
"outputs": [],
135134
"source": [
136135
"from safeds.ml.nn.layers import (Convolutional2DLayer, FlattenLayer,\n",
137136
" ForwardLayer, MaxPooling2DLayer)\n",
@@ -142,15 +141,16 @@
142141
" Convolutional2DLayer(output_channel=32, kernel_size=3, padding=1),\n",
143142
" MaxPooling2DLayer(kernel_size=2, stride=2),\n",
144143
" FlattenLayer(),\n",
145-
" ForwardLayer(output_size=128),\n",
146-
" ForwardLayer(output_size=3),\n",
144+
" ForwardLayer(neuron_count=128),\n",
145+
" ForwardLayer(neuron_count=3),\n",
147146
"]"
148147
],
149148
"metadata": {
150149
"collapsed": false
151150
},
152151
"id": "806a8091249d533a",
153-
"execution_count": null
152+
"execution_count": null,
153+
"outputs": []
154154
},
155155
{
156156
"cell_type": "markdown",
@@ -162,7 +162,6 @@
162162
},
163163
{
164164
"cell_type": "code",
165-
"outputs": [],
166165
"source": [
167166
"from safeds.ml.nn import NeuralNetworkClassifier\n",
168167
"from safeds.ml.nn.converters import InputConversionImageToColumn\n",
@@ -176,7 +175,8 @@
176175
"collapsed": false
177176
},
178177
"id": "af68cc0d32655d32",
179-
"execution_count": null
178+
"execution_count": null,
179+
"outputs": []
180180
},
181181
{
182182
"cell_type": "markdown",
@@ -198,15 +198,15 @@
198198
},
199199
{
200200
"cell_type": "code",
201-
"outputs": [],
202201
"source": [
203202
"cnn_fitted = cnn.fit(dataset, epoch_size=32, batch_size=16)"
204203
],
205204
"metadata": {
206205
"collapsed": false
207206
},
208207
"id": "381627a94d500675",
209-
"execution_count": null
208+
"execution_count": null,
209+
"outputs": []
210210
},
211211
{
212212
"cell_type": "markdown",
@@ -220,15 +220,15 @@
220220
},
221221
{
222222
"cell_type": "code",
223-
"outputs": [],
224223
"source": [
225224
"prediction = cnn_fitted.predict(dataset.get_input())"
226225
],
227226
"metadata": {
228227
"collapsed": false
229228
},
230229
"id": "62f63dd68362c8b7",
231-
"execution_count": null
230+
"execution_count": null,
231+
"outputs": []
232232
},
233233
{
234234
"cell_type": "markdown",
@@ -242,15 +242,15 @@
242242
},
243243
{
244244
"cell_type": "code",
245-
"outputs": [],
246245
"source": [
247246
"shuffled_prediction = prediction.shuffle()"
248247
],
249248
"metadata": {
250249
"collapsed": false
251250
},
252251
"id": "779277d73e30554d",
253-
"execution_count": null
252+
"execution_count": null,
253+
"outputs": []
254254
},
255255
{
256256
"cell_type": "markdown",
@@ -264,15 +264,15 @@
264264
},
265265
{
266266
"cell_type": "code",
267-
"outputs": [],
268267
"source": [
269268
"shuffled_prediction.get_input().remove_image_by_index(list(range(9, len(prediction))))"
270269
],
271270
"metadata": {
272271
"collapsed": false
273272
},
274273
"id": "a5ddbbfba41aa7f",
275-
"execution_count": null
274+
"execution_count": null,
275+
"outputs": []
276276
},
277277
{
278278
"cell_type": "markdown",
@@ -286,15 +286,15 @@
286286
},
287287
{
288288
"cell_type": "code",
289-
"outputs": [],
290289
"source": [
291290
"shuffled_prediction.get_output().to_list()[0:9]"
292291
],
293292
"metadata": {
294293
"collapsed": false
295294
},
296295
"id": "7081595d7100fb42",
297-
"execution_count": null
296+
"execution_count": null,
297+
"outputs": []
298298
}
299299
],
300300
"metadata": {

docs/tutorials/machine_learning.ipynb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"metadata": {
3636
"collapsed": false
3737
},
38-
"outputs": [],
39-
"execution_count": null
38+
"execution_count": null,
39+
"outputs": []
4040
},
4141
{
4242
"cell_type": "markdown",
@@ -60,8 +60,8 @@
6060
"metadata": {
6161
"collapsed": false
6262
},
63-
"outputs": [],
64-
"execution_count": null
63+
"execution_count": null,
64+
"outputs": []
6565
},
6666
{
6767
"cell_type": "markdown",
@@ -87,8 +87,8 @@
8787
"metadata": {
8888
"collapsed": false
8989
},
90-
"outputs": [],
91-
"execution_count": null
90+
"execution_count": null,
91+
"outputs": []
9292
},
9393
{
9494
"cell_type": "markdown",
@@ -158,8 +158,8 @@
158158
"metadata": {
159159
"collapsed": false
160160
},
161-
"outputs": [],
162-
"execution_count": null
161+
"execution_count": null,
162+
"outputs": []
163163
},
164164
{
165165
"cell_type": "markdown",
@@ -199,8 +199,8 @@
199199
"metadata": {
200200
"collapsed": false
201201
},
202-
"outputs": [],
203-
"execution_count": null
202+
"execution_count": null,
203+
"outputs": []
204204
},
205205
{
206206
"cell_type": "markdown",
@@ -240,8 +240,8 @@
240240
"metadata": {
241241
"collapsed": false
242242
},
243-
"outputs": [],
244-
"execution_count": null
243+
"execution_count": null,
244+
"outputs": []
245245
},
246246
{
247247
"cell_type": "markdown",
@@ -281,8 +281,8 @@
281281
"metadata": {
282282
"collapsed": false
283283
},
284-
"outputs": [],
285-
"execution_count": null
284+
"execution_count": null,
285+
"outputs": []
286286
},
287287
{
288288
"cell_type": "markdown",

src/safeds/data/labeled/containers/_tabular_dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ def _into_dataloader_with_classes(self, batch_size: int, num_of_classes: int) ->
196196
if num_of_classes <= 2:
197197
return DataLoader(
198198
dataset=_create_dataset(
199-
torch.Tensor(self.features._data_frame.to_numpy()).to(_get_device()),
200-
torch.Tensor(self.target._series.to_numpy()).to(_get_device()).unsqueeze(dim=-1),
199+
self.features._data_frame.to_torch().to(_get_device()),
200+
self.target._series.to_torch().to(_get_device()).unsqueeze(dim=-1),
201201
),
202202
batch_size=batch_size,
203203
shuffle=True,
@@ -206,9 +206,9 @@ def _into_dataloader_with_classes(self, batch_size: int, num_of_classes: int) ->
206206
else:
207207
return DataLoader(
208208
dataset=_create_dataset(
209-
torch.Tensor(self.features._data_frame.to_numpy()).to(_get_device()),
209+
self.features._data_frame.to_torch().to(_get_device()),
210210
torch.nn.functional.one_hot(
211-
torch.LongTensor(self.target._series.to_numpy()).to(_get_device()),
211+
self.target._series.to_torch().to(_get_device()),
212212
num_classes=num_of_classes,
213213
),
214214
),

src/safeds/data/tabular/transformation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
__name__,
1919
{
2020
"Discretizer": "._discretizer:Discretizer",
21-
"InvertibleTableTransformer": "._table_transformer:InvertibleTableTransformer",
21+
"InvertibleTableTransformer": "._invertible_table_transformer:InvertibleTableTransformer",
2222
"LabelEncoder": "._label_encoder:LabelEncoder",
2323
"OneHotEncoder": "._one_hot_encoder:OneHotEncoder",
2424
"RangeScaler": "._range_scaler:RangeScaler",

src/safeds/data/tabular/transformation/_discretizer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ def __hash__(self) -> int:
6363

6464
@property
6565
def is_fitted(self) -> bool:
66+
"""Whether the transformer is fitted."""
6667
return self._wrapped_transformer is not None
6768

6869
@property
6970
def bin_count(self) -> int:
71+
"""The number of bins to be created."""
7072
return self._bin_count
7173

7274
# ------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)