Esempio n. 1
0
    ]

    for i in range(len(SENT2VEC)):
        s2vsingle[i].load_state(SENT2VEC[i])
        s2vsingle[i].set_w2v_path(PATH_TO_W2V)
        s2vsingle[i] = s2vsingle[i].cuda()

    sent2vec = Sent2Vec(s2vsingle, 'concat')

    params_model = {'bsize': 64, 'pool_type': 'mean',
                    'which_layer': 'all',
                    'optfile': ELMO_OPTIONS,
                    'wgtfile': ELMO_WEIGHT}

    elmo = ELMo(params_model)
    elmo = elmo.cuda()

    gensen_1 = GenSenSingle(
        model_folder=FOLDER_PATH,
        filename_prefix=PREFIX1,
        pretrained_emb=PRETRAIN_EMB,
        cuda=True
    )
    gensen_2 = GenSenSingle(
        model_folder=FOLDER_PATH,
        filename_prefix=PREFIX2,
        pretrained_emb=PRETRAIN_EMB,
        cuda=True
    )
    gensen = GenSen(gensen_1, gensen_2)
}
# Set up logger
logging.basicConfig(format='%(asctime)s : %(message)s', level=logging.DEBUG)

if __name__ == "__main__":
    # Load InferSent model
    params_model = {
        'bsize': 64,
        'pool_type': 'mean',
        'which_layer': 'all',
        'optfile': OPT_PATH,
        'wgtfile': MODEL_PATH
    }

    model = ELMo(params_model)
    params_senteval['elmo'] = model.cuda()

    se = senteval.engine.SE(params_senteval, batcher, prepare)
    transfer_tasks = [
        'STS12', 'STS13', 'STS14', 'STS15', 'STS16', 'MR', 'CR', 'MPQA',
        'SUBJ', 'SST2', 'SST5', 'TREC', 'MRPC', 'SICKEntailment',
        'SICKRelatedness', 'STSBenchmark', 'Length', 'WordContent', 'Depth',
        'TopConstituents', 'BigramShift', 'Tense', 'SubjNumber', 'ObjNumber',
        'OddManOut', 'CoordinationInversion'
    ]
    results_transfer = se.eval(transfer_tasks)

    print('--------------------------------------------')
    print('MR                [Dev:%.1f/Test:%.1f]' %
          (results_transfer['MR']['devacc'], results_transfer['MR']['acc']))
    print('CR                [Dev:%.1f/Test:%.1f]' %