Skip to content

Commit

Permalink
Fix to doc
Browse files Browse the repository at this point in the history
  • Loading branch information
neubig committed May 30, 2017
1 parent 83fce21 commit a0f4711
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
25 changes: 14 additions & 11 deletions xnmt/embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class Embedder:
"""

def embed(self, word):
"""
Embed a single word.
"""Embed a single word.
:param word: This will generally be an integer word ID, but could also be something like a string.
"""
raise NotImplementedError('embed must be implemented in Embedder subclasses')

def embed_sent(self, sent):
"""
Embed a full sent worth of words.
"""Embed a full sentence worth of words.
:param sent: This will generally be a list of word IDs, but could also be a list of strings or some other format.
"""
raise NotImplementedError('embed_sent must be implemented in Embedder subclasses')
Expand All @@ -33,14 +33,14 @@ def from_spec(input_format, vocab_size, emb_dim, model):
raise RuntimeError("Unknown input type {}".format(input_format))

class ExpressionSequence():
"""
A class to represent a sequence of expressions.
"""A class to represent a sequence of expressions.
Internal representation is either a list of expressions or a single tensor or both.
If necessary, both forms of representation are created from the other on demand.
"""
def __init__(self, **kwargs):
"""
"""Constructor.
:param expr_list: a python list of expressions
:param expr_tensor: a tensor where highest dimension are the sequence items
:raises valueError:
Expand All @@ -56,29 +56,32 @@ def __init__(self, **kwargs):
raise ValueError("expr_list and expr_tensor must be of same length")

def __len__(self):
"""
"""Return length.
:returns: length of sequence
"""
if self.expr_list: return len(self.expr_list)
else: return self.expr_tensor.dim()[0][0]

def __iter__(self):
"""
"""Return iterator.
:returns: iterator over the sequence; results in explicit conversion to list
"""
if self.expr_list is None:
self.expr_list = [self[i] for i in range(len(self))]
return iter(self.expr_list)

def __getitem__(self, key):
"""
"""Get a single item.
:returns: sequence item (expression); does not result in explicit conversion to list
"""
if self.expr_list: return self.expr_list[key]
else: return dy.pick(self.expr_tensor, key)

def as_tensor(self):
"""
"""Get a tensor.
:returns: the whole sequence as a tensor expression.
"""
if self.expr_tensor is None:
Expand Down
8 changes: 4 additions & 4 deletions xnmt/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class Encoder:
"""

def transduce(self, sent):
"""
Encode inputs into outputs.
"""Encode inputs into outputs.
:param sent: The input to be encoded. This is duck-typed, so it is the appropriate input for this particular type of encoder. Frequently it will be a list of word embeddings, but it can be anything else.
:returns: The encoded output. Frequently this will be a list of expressions representing the encoded vectors for each word.
"""
raise NotImplementedError('transduce must be implemented in Encoder subclasses')

@staticmethod
def from_spec(spec, layers, input_dim, output_dim, model, residual_to_output):
"""
Create an encoder from a specification.
"""Create an encoder from a specification.
:param spec: Options include bilstm, residuallstm, residualbylstm, pyramidalbilstm, convbilstm, modular.
:param layers: Number of layers
:param input_dim: Input dimension
Expand Down

0 comments on commit a0f4711

Please sign in to comment.