857e36921ab5ca51c919839ec0b6e87585160d0c,onmt/decoders/ensemble.py,,load_test_model,#Any#Any#,119

Before Change


    shared_fields = None
    shared_model_opt = None
    models = []
    for model_path in opt.models:
        fields, model, model_opt = \
            onmt.model_builder.load_test_model(opt,
                                               dummy_opt,
                                               model_path=model_path)
        if shared_fields is None:
            shared_fields = fields
        else:
            for key, field in fields.items():
                if field is not None and "vocab" in field.__dict__:
                    assert field.vocab.stoi == shared_fields[key].vocab.stoi, \
                        "Ensemble models must use the same preprocessed data"
        models.append(model)
        if shared_model_opt is None:
            shared_model_opt = model_opt
    ensemble_model = EnsembleModel(models, opt.avg_raw_probs)
    return shared_fields, ensemble_model, shared_model_opt

After Change


    def init_state(self, src, memory_bank, enc_hidden):
         See :obj:`RNNDecoderBase.init_state()` 
        for i, model_decoder in enumerate(self.model_decoders):
            model_decoder.init_state(src, memory_bank[i], enc_hidden[i])

    def map_state(self, fn):
        for model_decoder in self.model_decoders:
            model_decoder.map_state(fn)


class EnsembleGenerator(nn.Module):
    
    Dummy Generator that delegates to individual real Generators,
    and then averages the resulting target distributions.
    
    def __init__(self, model_generators, raw_probs=False):
        super(EnsembleGenerator, self).__init__()
        self.model_generators = nn.ModuleList(model_generators)
        self._raw_probs = raw_probs

    def forward(self, hidden, attn=None, src_map=None):
        
        Compute a distribution over the target dictionary
        by averaging distributions from models in the ensemble.
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: OpenNMT/OpenNMT-py
Commit Name: 857e36921ab5ca51c919839ec0b6e87585160d0c
Time: 2019-02-14
Author: dylan.flaute@gmail.com
File Name: onmt/decoders/ensemble.py
Class Name:
Method Name: load_test_model


Project Name: OpenNMT/OpenNMT-py
Commit Name: bc1351d47d9fe83bc6c7830a8563ddb874953ed4
Time: 2019-01-09
Author: benzurdopeters@gmail.com
File Name: onmt/train_single.py
Class Name:
Method Name: main


Project Name: hanxiao/bert-as-service
Commit Name: 2bfe5bfcec7759ae022b1a479411aa7d1b8401f1
Time: 2019-05-06
Author: zyn2122@gmail.com
File Name: example/example7.py
Class Name:
Method Name: