neuralmonkey.model package


neuralmonkey.model.model_part module

Basic functionality of all model parts.

class neuralmonkey.model.model_part.ModelPart(name: str, save_checkpoint: typing.Union[str, NoneType] = None, load_checkpoint: typing.Union[str, NoneType] = None) → None

Bases: object

Base class of all model parts.

feed_dict(dataset: neuralmonkey.dataset.Dataset, train: bool) → typing.Dict[tensorflow.python.framework.ops.Tensor, typing.Any]

Prepare feed dicts for part’s placeholders from a dataset.

load(session: tensorflow.python.client.session.Session) → None

Load model part from a checkpoint file.


Name of the model part and its variable scope.

save(session: tensorflow.python.client.session.Session) → None

Save model part to a checkpoint file.


Return a context manager that (re)opens the model part’s variable and name scope.

neuralmonkey.model.sequence module

This module impements the sequence class and a few of its subclasses

class neuralmonkey.model.sequence.EmbeddedFactorSequence(name: str, vocabularies: typing.List[neuralmonkey.vocabulary.Vocabulary], data_ids: typing.List[str], embedding_sizes: typing.List[int], max_length: int = None, save_checkpoint: str = None, load_checkpoint: str = None) → None

Bases: neuralmonkey.model.sequence.Sequence

A Sequence that stores one or more embedded inputs (factors).


The sequence data. A 3D Tensor of shape (batch, time, dimension), where dimension is the sum of the embedding sizes supplied to the constructor.


The sequence dimension. The sum of the embedding sizes supplied to the constructor.


A list of embedding matrices for each factor

feed_dict(dataset: neuralmonkey.dataset.Dataset, train: bool = False) → typing.Dict[tensorflow.python.framework.ops.Tensor, typing.Any]

Feed the placholders with the data.

  • dataset – The dataset.
  • train – A flag whether the train mode is enabled.

The constructed feed dictionary that contains the factor data and the mask.


A list of 2D placeholders for each factor. Each placeholder has shape (batch size, time).


A 2D placeholder for the sequence mask. This is shared across factors and must be the same for each of them.

tb_embedding_visualization(logdir: str, prj: <module 'tensorflow.contrib.tensorboard.plugins.projector' from '/home/docs/checkouts/'>)

Links embeddings with vocabulary wordlist for tensorboard visualization

  • logdir – directory where model is stored
  • projector – TensorBoard projector for storing linking info.
class neuralmonkey.model.sequence.EmbeddedSequence(name: str, vocabulary: neuralmonkey.vocabulary.Vocabulary, data_id: str, embedding_size: int, max_length: int = None, save_checkpoint: str = None, load_checkpoint: str = None) → None

Bases: neuralmonkey.model.sequence.EmbeddedFactorSequence

A sequence of embedded inputs (for a single factor)


The input data series indentifier


The embedding matrix for the sequence


A 2D placeholder for the sequence inputs.


The input vocabulary

class neuralmonkey.model.sequence.Sequence(name: str, max_length: int = None, save_checkpoint: str = None, load_checkpoint: str = None) → None

Bases: neuralmonkey.model.model_part.ModelPart

Base class for a data sequence.

This class represents a batch of sequences of Tensors of possibly different lengths.


A Tensor representing the data in the sequence. The first and second dimension correspond to batch size and time respectively.


The dimension of the sequence. For 3D sequences, this is the size of the last dimension of the data tensor.


A 1D Tensor of type int32 that stores the lengths of the sequences in the batch


A 2D Tensor of type float32 and shape (batch size, time) that masks the sequences in the batch.


The maximum length of sequences in the data tensor.

Module contents