neuralmonkey.runners.tensor_runner module

class neuralmonkey.runners.tensor_runner.RepresentationRunner(output_series: str, encoder: neuralmonkey.model.model_part.ModelPart, attribute: str = 'output', select_session: int = None) → None

Bases: neuralmonkey.runners.tensor_runner.TensorRunner

Runner printing out representation from an encoder.

Use this runner to get input / other data representation out from one of Neural Monkey encoders.

__init__(output_series: str, encoder: neuralmonkey.model.model_part.ModelPart, attribute: str = 'output', select_session: int = None) → None

Initialize the representation runner.

Parameters:
  • output_series – Name of the output series with vectors.
  • encoder – The encoder to use. This can be any ModelPart object.
  • attribute – The name of the encoder attribute that contains the data.
  • used_session – Id of the TensorFlow session used in case of model ensembles.
class neuralmonkey.runners.tensor_runner.TensorExecutable(all_coders: Set[neuralmonkey.model.model_part.ModelPart], fetches: Dict[tensorflow.python.framework.ops.Tensor, Union[int, float, numpy.ndarray]], batch_dims: Dict[str, int], select_session: Union[int, NoneType], single_tensor: bool) → None

Bases: neuralmonkey.runners.base_runner.Executable

__init__(all_coders: Set[neuralmonkey.model.model_part.ModelPart], fetches: Dict[tensorflow.python.framework.ops.Tensor, Union[int, float, numpy.ndarray]], batch_dims: Dict[str, int], select_session: Union[int, NoneType], single_tensor: bool) → None

Initialize self. See help(type(self)) for accurate signature.

collect_results(results: List[Dict]) → None
next_to_execute() → Tuple[Set[neuralmonkey.model.model_part.ModelPart], Union[Dict, List], List[Dict[tensorflow.python.framework.ops.Tensor, Union[int, float, numpy.ndarray]]]]
class neuralmonkey.runners.tensor_runner.TensorRunner(output_series: str, toplevel_modelpart: neuralmonkey.model.model_part.ModelPart, toplevel_tensors: List[tensorflow.python.framework.ops.Tensor], tensors_by_name: List[str], tensors_by_ref: List[tensorflow.python.framework.ops.Tensor], batch_dims_by_name: List[int], batch_dims_by_ref: List[int], select_session: int = None, single_tensor: bool = False) → None

Bases: neuralmonkey.runners.base_runner.BaseRunner

Runner class for printing tensors from a model.

Use this runner if you want to retrieve a specific tensor from the model using a given dataset. The runner generates an output data series which will contain the tensors in a dictionary of numpy arrays.

__init__(output_series: str, toplevel_modelpart: neuralmonkey.model.model_part.ModelPart, toplevel_tensors: List[tensorflow.python.framework.ops.Tensor], tensors_by_name: List[str], tensors_by_ref: List[tensorflow.python.framework.ops.Tensor], batch_dims_by_name: List[int], batch_dims_by_ref: List[int], select_session: int = None, single_tensor: bool = False) → None

Construct a new TensorRunner object.

Note that at this time, one must specify the toplevel objects so that it is ensured that the graph is built. The reason for this behavior is that the graph is constructed lazily and therefore if the tensors to store are provided by indirect reference (name), the system does not know early enough that it needs to create them.

Parameters:
  • output_series – The name of the generated output data series.
  • toplevel_modelpart – A ModelPart object that is used as the top-level component of the model. This object should depend on values of all the wanted tensors.
  • toplevel_tensors – A list of tensors that should be constructed. Use this when the toplevel model part does not depend on this tensor. The tensors are constructed during running this constructor method which prints them out.
  • tensors_by_name – A list of tensor names to fetch. If a tensor is not in the graph, a warning is generated and the tensor is ignored.
  • tensors_by_ref – A list of tensor objects to fetch.
  • batch_dims_by_name – A list of integers that correspond to the batch dimension in each wanted tensor specified by name.
  • batch_dims_by_ref – A list of integers that correspond to the batch dimension in each wanted tensor specified by reference.
  • select_session – An optional integer specifying the session to use in case of ensembling. When not used, tensors from all sessions are stored. In case of a single session, this option has no effect.
  • single_tensor – If True, it is assumed that only one tensor is to be fetched, and the execution result will consist of this tensor only. If False, the result will be a dict mapping tensor names to NumPy arrays.
get_executable(compute_losses: bool, summaries: bool, num_sessions: int) → neuralmonkey.runners.tensor_runner.TensorExecutable
loss_names