Skip to content

Commit

Permalink
Specify output dimension more explicitly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Leif Johnson committed Jan 18, 2016
1 parent b17228f commit 7a8f25e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions theanets/feedforward.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,11 @@ class Classifier(graph.Network):
DEFAULT_OUTPUT_ACTIVATION = 'softmax'
'''Default activation for the output layer.'''

OUTPUT_NDIM = 1
'''Number of dimensions for holding output data arrays.'''

def __init__(self, layers, loss='xe', weighted=False, rng=13):
super(Classifier, self).__init__(layers, rng=rng)
self.set_loss(form=loss, target=1, weighted=weighted)
super(Classifier, self).__init__(layers, loss=loss, weighted=weighted, rng=rng)

def monitors(self, **kwargs):
'''Return expressions that should be computed to monitor training.
Expand Down
5 changes: 4 additions & 1 deletion theanets/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class Network(object):
INPUT_NDIM = 2
'''Number of dimensions for holding input data arrays.'''

OUTPUT_NDIM = 2
'''Number of dimensions for holding output data arrays.'''

def __init__(self, layers=(), loss='mse', weighted=False, rng=13):
self._graphs = {} # cache of symbolic computation graphs
self._functions = {} # cache of callable feedforward functions
Expand All @@ -94,7 +97,7 @@ def __init__(self, layers=(), loss='mse', weighted=False, rng=13):
if loss and self.layers:
self.set_loss(loss,
weighted=weighted,
target=self.INPUT_NDIM,
target=self.OUTPUT_NDIM,
output_name=self.layers[-1].output_name())

def add_layer(self, layer=None, is_output=False, **kwargs):
Expand Down
11 changes: 8 additions & 3 deletions theanets/recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ class Autoencoder(feedforward.Autoencoder):
INPUT_NDIM = 3
'''Number of dimensions for holding input data arrays.'''

OUTPUT_NDIM = 3
'''Number of dimensions for holding output data arrays.'''


class Regressor(feedforward.Regressor):
'''A regressor attempts to produce a target output given some inputs.
Expand Down Expand Up @@ -291,6 +294,9 @@ class Regressor(feedforward.Regressor):
INPUT_NDIM = 3
'''Number of dimensions for holding input data arrays.'''

OUTPUT_NDIM = 3
'''Number of dimensions for holding output data arrays.'''


class Classifier(feedforward.Classifier):
'''A classifier computes a distribution over labels, given an input.
Expand Down Expand Up @@ -379,9 +385,8 @@ class Classifier(feedforward.Classifier):
INPUT_NDIM = 3
'''Number of dimensions for holding input data arrays.'''

def __init__(self, layers, loss='xe', weighted=False, rng=13):
super(Classifier, self).__init__(layers, rng=rng)
self.set_loss(loss, target=2, weighted=weighted)
OUTPUT_NDIM = 2
'''Number of dimensions for holding output data arrays.'''

def predict_sequence(self, labels, steps, streams=1, rng=None):
'''Draw a sequential sample of class labels from this network.
Expand Down

0 comments on commit 7a8f25e

Please sign in to comment.