neuralmonkey.model package

Submodules

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

Name of the model part and its variable scope.

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

Save model part to a checkpoint file.

use_scope()

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).

data

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

dimension

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

embedding_matrices

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.

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

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

input_factors

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

mask

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/readthedocs.org/user_builds/neural-monkey/envs/0.2.2/lib/python3.5/site-packages/tensorflow/contrib/tensorboard/plugins/projector/__init__.py'>)

Links embeddings with vocabulary wordlist for tensorboard visualization

Parameters:
  • 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)

data_id

The input data series indentifier

embedding_matrix

The embedding matrix for the sequence

inputs

A 2D placeholder for the sequence inputs.

vocabulary

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.

data

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

dimension

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

lengths

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

mask

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

max_length

The maximum length of sequences in the data tensor.

Module contents