def __init__(self,
                 output_series: str,
                 decoder: Decoder) -> None:
        check_argument_types()
        BaseRunner.__init__(self, output_series, decoder)

        self._decoder_xent = cast(Decoder, self._decoder).train_xents
Esempio n. 2
0
    def __init__(self,
                 output_series: str,
                 decoder: SequenceRegressor,
                 postprocess: Callable[[float], float] = None) -> None:
        check_argument_types()
        BaseRunner.__init__(self, output_series, decoder)

        self._postprocess = postprocess
Esempio n. 3
0
    def __init__(self,
                 output_series: str,
                 decoder: Any,
                 normalize: bool = True,
                 pick_index: int = None,
                 pick_value: str = None) -> None:
        """Initializes the logits runner.

        Args:
            output_series: Name of the series produces by the runner.
            decoder: A decoder having logits.
            normalize: Flag whether the logits should be normalized with
                softmax.
            pick_index: If not None, it specifies the index of the logit or the
                probability that should be on output.
            pick_value: If not None, it specifies a value from the decoder's
                vocabulary whose logit or probability should be on output.
        """
        check_argument_types()
        BaseRunner.__init__(self, output_series, decoder)

        if not hasattr(self._decoder, "vocabulary"):
            raise TypeError("Decoder for logits runner should have the "
                            "'vocabulary' attribute")

        if not hasattr(self._decoder, "decoded_logits"):
            raise TypeError("Decoder for logits runner should have the "
                            "'decoded_logits' attribute")

        # TODO why these two?
        if not hasattr(self._decoder, "train_loss"):
            raise TypeError("Decoder for logits runner should have the "
                            "'train_loss' attribute")

        if not hasattr(self._decoder, "runtime_loss"):
            raise TypeError("Decoder for logits runner should have the "
                            "'runtime_loss' attribute")

        self._decoder_vocab = getattr(self._decoder, "vocabulary")
        self._decoder_train_loss = getattr(self._decoder, "train_loss")
        self._decoder_runtime_loss = getattr(self._decoder, "runtime_loss")
        self._decoder_logits = getattr(self._decoder, "decoded_logits")

        if pick_index is not None and pick_value is not None:
            raise ValueError("Either a pick index or a vocabulary value can "
                             "be specified, not both at the same time.")

        self._normalize = normalize
        if pick_value is not None:
            if pick_value in self._decoder_vocab:
                vocab_map = self._decoder_vocab.word_to_index
                self._pick_index = vocab_map[pick_value]
            else:
                raise ValueError(
                    "Value '{}' is not in vocabulary of decoder '{}'".format(
                        pick_value, decoder.name))
        else:
            self._pick_index = pick_index
    def __init__(self,
                 output_series: str,
                 decoder: BeamSearchDecoder,
                 rank: int = 1,
                 postprocess: Callable[[List[str]], List[str]] = None) -> None:
        check_argument_types()
        BaseRunner.__init__(self, output_series, decoder)

        if rank < 1 or rank > decoder.beam_size:
            raise ValueError(
                ("Rank of output hypothesis must be between 1 and the beam "
                 "size ({}), was {}.").format(decoder.beam_size, rank))

        self._rank = rank
        self._postprocess = postprocess
    def __init__(self,
                 output_series: str,
                 encoder: ModelPart,
                 attribute: str = "output",
                 used_session: int = 0) -> None:
        """Initialize the representation runner.

        Args:
            output_series: Name of the output series with vectors.
            encoder: The encoder to use.
            attribute: The name of the encoder attribute that contains the
                data.
            used_session: Id of the TensorFlow session used in case of model
                ensembles.
        """
        check_argument_types()
        BaseRunner.__init__(self, output_series, cast(ModelPart, encoder))

        self._used_session = used_session  # type: int
        self._encoded = getattr(encoder, attribute)  # type: tf.Tensor
Esempio n. 6
0
    def __init__(self,
                 output_series: str,
                 encoder: Stateful,
                 used_session: int = 0) -> None:
        """Initialize the representation runner.

        Args:
            output_series: Name of the output seriesi with vectors.
            encoder: Used encoder.
            used_session: Id of the TensorFlow session used in case of model
                ensembles.
        """
        check_argument_types()

        if not isinstance(encoder, ModelPart):
            raise TypeError("The encoder of the representation runner has to "
                            "be an instance of 'ModelPart'")

        BaseRunner.__init__(self, output_series, cast(ModelPart, encoder))

        self._used_session = used_session  # type: int
        self._encoded = encoder.output  # type: Stateful
Esempio n. 7
0
 def __init__(self, output_series: str, decoder: BeamSearchDecoder,
              attention: BaseAttention) -> None:
     check_argument_types()
     BaseRunner.__init__(self, output_series, decoder)