Skip to content

Commit

Permalink
Merge pull request #992 from rizar/lookup_feedforward
Browse files Browse the repository at this point in the history
Make Lookup a child of Feedforward
  • Loading branch information
rizar committed Feb 17, 2016
2 parents 23ba43c + faceae2 commit 7e9cc74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
19 changes: 17 additions & 2 deletions blocks/bricks/lookup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Introduces Lookup brick."""
from blocks.bricks import Initializable
from blocks.bricks import Initializable, Feedforward
from blocks.bricks.base import application, lazy
from blocks.roles import WEIGHT, add_role
from blocks.utils import check_theano_variable, shared_floatx_nans


class LookupTable(Initializable):
class LookupTable(Initializable, Feedforward):
"""Encapsulates representations of a range of integers.
This brick can be used to embed integers, e.g. word indices,
into a vector space.
Parameters
----------
length : int
Expand Down Expand Up @@ -70,3 +73,15 @@ def get_dim(self, name):
if name == 'indices':
return 0
return super(LookupTable, self).get_dim(name)

@property
def input_dim(self):
return 0

@property
def output_dim(self):
return self.dim

@output_dim.setter
def output_dim(self, dim):
self.dim = dim
10 changes: 10 additions & 0 deletions tests/bricks/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ def test_lookup_table():
assert_equal(lt.get_dim(lt.apply.inputs[0]), 0)
assert_equal(lt.get_dim(lt.apply.outputs[0]), lt.dim)
assert_raises(ValueError, lt.get_dim, 'random_name')

# Test feedforward interface
assert lt.input_dim == 0
assert lt.output_dim == 3
lt.output_dim = 4
assert lt.output_dim == 4

def assign_input_dim():
lt.input_dim = 11
assert_raises(AttributeError, assign_input_dim)

0 comments on commit 7e9cc74

Please sign in to comment.