Exemplo n.º 1
0
        fin = open(args.dict, 'r')
        for line in fin:
            tokens = line.split()
            dic[int(tokens[1])] = tokens[0]
    word_dic = None
    if args.word_dict is not None:
        fin = open(args.word_dict, 'r')
        word_dic = {}
        for line in fin:
            tokens = line.split()
            word_dic[''.join(tokens[1:])] = tokens[0]

    device = torch.device('cuda')

    mdic = torch.load(args.model_dic)
    model = Seq2Seq(**mdic['params']).to(device)
    model.load_state_dict(mdic['state'])
    model.eval()

    reader = ScpStreamReader(args.data_scp,
                             mean_sub=args.mean_sub,
                             downsample=args.downsample)
    reader.initialize()

    space, beam_size, max_len = args.space, args.beam_size, args.max_len
    start, win, stable_time = args.start_block, args.incl_block, args.stable_time
    head, padding = args.attn_head, args.attn_padding

    since = time.time()
    fctm = open(args.output, 'w')
    total_latency = 0
Exemplo n.º 2
0
    if args.word_dict is not None:
        fin = open(args.word_dict, 'r')
        word_dic = {}
        for line in fin:
            tokens = line.split()
            word_dic[''.join(tokens[1:])] = tokens[0]

    use_gpu = torch.cuda.is_available()
    device = torch.device('cuda' if use_gpu else 'cpu')

    models = []
    for dic_path in args.model_dic:
        sdic = torch.load(dic_path[0])
        m_params = sdic['params']
        if sdic['type'] == 'lstm':
            model = Seq2Seq(**m_params).to(device)
        elif sdic['type'] == 'tf':
            model = Transformer(**m_params).to(device)
        model.load_state_dict(sdic['state'])
        model.eval()
        models.append(model)
    model = Ensemble(models)

    reader = ScpStreamReader(args.data_scp,
                             mean_sub=args.mean_sub,
                             downsample=args.downsample)
    reader.initialize()

    since = time.time()
    batch_size = args.batch_size
    fout = open(args.output, 'w')
Exemplo n.º 3
0
if __name__ == '__main__':
    args = parser.parse_args()
    print(args)

    use_gpu = torch.cuda.is_available()
    device = torch.device('cuda' if use_gpu else 'cpu')

    model = Seq2Seq(input_size=args.d_input,
                    hidden_size=args.d_model,
                    output_size=args.n_classes,
                    n_enc=args.n_enc,
                    n_dec=args.n_dec,
                    n_head=args.n_head,
                    unidirect=args.unidirect,
                    incl_win=args.incl_win,
                    time_ds=args.time_ds,
                    use_cnn=args.use_cnn,
                    freq_kn=args.freq_kn,
                    freq_std=args.freq_std,
                    lm=not args.no_lm,
                    shared_emb=args.shared_emb,
                    dropout=args.dropout,
                    emb_drop=args.emb_drop).to(device)

    ScpReader = ScpBatchReader if args.batch else ScpStreamReader
    tr_reader = ScpReader(args.train_scp,
                          args.train_target,
                          downsample=args.downsample,
                          sort_src=True,
                          max_len=args.max_len,
                          max_utt=args.max_utt,
Exemplo n.º 4
0
        'input_size': args.d_input,
        'hidden_size': args.d_model,
        'output_size': args.n_classes,
        'n_enc': args.n_enc,
        'n_dec': args.n_dec,
        'n_head': args.n_head,
        'unidirect': args.unidirect,
        'incl_win': args.incl_win,
        'time_ds': args.time_ds,
        'use_cnn': args.use_cnn,
        'freq_kn': args.freq_kn,
        'freq_std': args.freq_std,
        'lm': not args.no_lm,
        'shared_emb': args.shared_emb
    }
    model = Seq2Seq(**m_params)

    ext = copy.deepcopy(model)
    states = args.states.split(',')

    state = "%s/epoch-%s.pt" % (args.model_path, states[0])
    model.load_state_dict(torch.load(state, map_location='cpu'))
    params = list(model.parameters())
    for s in states[1:]:
        state = "%s/epoch-%s.pt" % (args.model_path, s)
        ext.load_state_dict(torch.load(state, map_location='cpu'))
        eparams = list(ext.parameters())
        for i in range(len(params)):
            params[i].data.add_(eparams[i].data)
    scale = 1.0 / len(states)
    for p in params: