def test_generator(self):
        model = Seq2SeqModel.from_config(
            Seq2SeqModel.Config(
                source_embedding=WordEmbedding.Config(embed_dim=512),
                target_embedding=WordEmbedding.Config(embed_dim=512),
            ),
            self._get_tensorizers(),
        )
        sample, _ = get_example_and_check()
        repacked_inputs = {
            "src_tokens": sample[0].t(),
            "src_lengths": sample[1]
        }

        scripted_generator = ScriptedSequenceGenerator(
            [model.model], model.trg_eos_index,
            ScriptedSequenceGenerator.Config())
        scripted_preds = scripted_generator.generate_hypo(repacked_inputs)

        self.assertIsNotNone(scripted_preds)
Пример #2
0
    class Config(Model.Config):
        class ModelInput(Model.Config.ModelInput):
            src_seq_tokens: TokenTensorizer.Config = TokenTensorizer.Config()
            trg_seq_tokens: TokenTensorizer.Config = TokenTensorizer.Config()
            dict_feat: Optional[GazetteerTensorizer.Config] = None

        inputs: ModelInput = ModelInput()
        encoder_decoder: RNNModel.Config = RNNModel.Config()
        source_embedding: WordEmbedding.Config = WordEmbedding.Config()
        target_embedding: WordEmbedding.Config = WordEmbedding.Config()
        dict_embedding: Optional[DictEmbedding.Config] = None
        output_layer: Seq2SeqOutputLayer.Config = Seq2SeqOutputLayer.Config()
        sequence_generator: ScriptedSequenceGenerator.Config = (
            ScriptedSequenceGenerator.Config())