neuralmonkey.encoders package

Submodules

neuralmonkey.encoders.attentive module

class neuralmonkey.encoders.attentive.Attentive(attention_type, **kwargs)

Bases: object

A base class fro an attentive part of graph (typically encoder).

Objects inheriting this class are able to generate an attention object that allows a decoder to perform attention over an attention_object provided by the encoder (e.g., input word representations in case of MT or convolutional maps in case of image captioning).

create_attention_object()

Attention object that can be used in decoder.

neuralmonkey.encoders.cnn_encoder module

CNN for image processing.

class neuralmonkey.encoders.cnn_encoder.CNNEncoder(name: str, data_id: str, convolutions: typing.List[typing.Tuple[int, int, typing.Union[int, NoneType]]], image_height: int, image_width: int, pixel_dim: int, fully_connected: typing.Union[typing.List[int], NoneType] = None, batch_normalization: bool = True, local_response_normalization: bool = True, dropout_keep_prob: float = 0.5, attention_type: typing.Type = <class 'neuralmonkey.decoding_function.Attention'>, save_checkpoint: typing.Union[str, NoneType] = None, load_checkpoint: typing.Union[str, NoneType] = None) → None

Bases: neuralmonkey.model.model_part.ModelPart, neuralmonkey.encoders.attentive.Attentive

An image encoder.

It projects the input image through a serie of convolutioal operations. The projected image is vertically cut and fed to stacked RNN layers which encode the image into a single vector.

input_op

Placeholder for the batch of input images

padding_masks

Placeholder for matrices capturing telling where the image has been padded.

image_processing_layers

List of TensorFlow operator that are visualizable image transformations.

encoded

Operator that returns a batch of ecodede image (intended as an input for the decoder).

attention_tensor

Tensor computing a batch of attention matrices for the decoder.

train_mode

Placeholder for boolean telleing whether the training is running.

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

neuralmonkey.encoders.factored_encoder module

class neuralmonkey.encoders.factored_encoder.FactoredEncoder(name: str, max_input_len: int, vocabularies: typing.List[neuralmonkey.vocabulary.Vocabulary], data_ids: typing.List[str], embedding_sizes: typing.List[int], rnn_size: int, dropout_keep_prob: float = 1.0, attention_type: typing.Any = None, save_checkpoint: typing.Union[str, NoneType] = None, load_checkpoint: typing.Union[str, NoneType] = None) → None

Bases: neuralmonkey.model.model_part.ModelPart, neuralmonkey.encoders.attentive.Attentive

Generic encoder processing an arbitrary number of input sequences.

feed_dict(dataset, train=False)

neuralmonkey.encoders.imagenet_encoder module

Pre-trained ImageNet networks.

class neuralmonkey.encoders.imagenet_encoder.ImageNet(name: str, data_id: str, network_type: str, attention_layer: typing.Union[str, NoneType], attention_state_size: int, attention_type: typing.Type = <class 'neuralmonkey.decoding_function.Attention'>, fine_tune: bool = False, encoded_layer: typing.Union[str, NoneType] = None, load_checkpoint: typing.Union[str, NoneType] = None, save_checkpoint: typing.Union[str, NoneType] = None) → None

Bases: neuralmonkey.model.model_part.ModelPart, neuralmonkey.encoders.attentive.Attentive

Pre-trained ImageNet network.

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

neuralmonkey.encoders.numpy_encoder module

class neuralmonkey.encoders.numpy_encoder.PostCNNImageEncoder(name: str, input_shape: typing.List[int], output_shape: int, data_id: str, attention_type: typing.Callable = None, save_checkpoint: typing.Union[str, NoneType] = None, load_checkpoint: typing.Union[str, NoneType] = None) → None

Bases: neuralmonkey.model.model_part.ModelPart, neuralmonkey.encoders.attentive.Attentive

feed_dict(dataset: neuralmonkey.dataset.Dataset, train: bool = False) → typing.Dict[tensorflow.python.framework.ops.Tensor, typing.Any]
class neuralmonkey.encoders.numpy_encoder.VectorEncoder(name: str, dimension: int, data_id: str, output_shape: typing.Union[int, NoneType] = None, save_checkpoint: typing.Union[str, NoneType] = None, load_checkpoint: typing.Union[str, NoneType] = None) → None

Bases: neuralmonkey.model.model_part.ModelPart

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

neuralmonkey.encoders.sentence_encoder module

class neuralmonkey.encoders.sentence_encoder.SentenceEncoder(name: str, vocabulary: neuralmonkey.vocabulary.Vocabulary, data_id: str, embedding_size: int, rnn_size: int, max_input_len: typing.Union[int, NoneType] = None, dropout_keep_prob: float = 1.0, attention_type: typing.Any = None, attention_fertility: int = 3, use_noisy_activations: bool = False, parent_encoder: typing.Union[typing.SentenceEncoder, NoneType] = None, save_checkpoint: typing.Union[str, NoneType] = None, load_checkpoint: typing.Union[str, NoneType] = None) → None

Bases: neuralmonkey.model.model_part.ModelPart, neuralmonkey.encoders.attentive.Attentive

A class that manages parts of the computation graph that are used for encoding of input sentences. It uses a bidirectional RNN.

This version of the encoder does not support factors. Should you want to use them, use FactoredEncoder instead.

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

Populate the feed dictionary with the encoder inputs.

Encoder input placeholders:
encoder_input: Stores indices to the vocabulary,
shape (batch, time)
encoder_padding: Stores the padding (ones and zeros,
indicating valid words and positions after the end of sentence, shape (batch, time)
train_mode: Boolean scalar specifying the mode (train
vs runtime)
Parameters:
  • dataset – The dataset to use
  • train – Boolean flag telling whether it is training time
rnn_cells() → typing.Tuple[tensorflow.python.ops.rnn_cell.RNNCell, tensorflow.python.ops.rnn_cell.RNNCell]

Return the graph template to for creating RNN memory cells

vocabulary_size

neuralmonkey.encoders.sequence_cnn_encoder module

class neuralmonkey.encoders.sequence_cnn_encoder.SequenceCNNEncoder(name: str, vocabulary: neuralmonkey.vocabulary.Vocabulary, data_id: str, embedding_size: int, filters: typing.List[typing.Tuple[int, int]], max_input_len: typing.Union[int, NoneType] = None, dropout_keep_prob: float = 1.0, save_checkpoint: typing.Union[str, NoneType] = None, load_checkpoint: typing.Union[str, NoneType] = None) → None

Bases: neuralmonkey.model.model_part.ModelPart

Encoder processing a sequence using a CNN.

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

Populate the feed dictionary with the encoder inputs.

Encoder input placeholders:
encoder_input: Stores indices to the vocabulary,
shape (batch, time)
encoder_padding: Stores the padding (ones and zeros,
indicating valid words and positions after the end of sentence, shape (batch, time)
train_mode: Boolean scalar specifying the mode (train
vs runtime)
Parameters:
  • dataset – The dataset to use
  • train – Boolean flag telling whether it is training time

Module contents