Exemplo n.º 1
0
                state_vec = [ [PhoneIdx[PhoneState[i] ] ] for i in mem_label[start:end] ]
                extended_out = [[0]]*(mask_max-utter_len)
                utter_mask = [ np.ones((utter_len,1)),
                           np.zeros((mask_max-utter_len,1)) ]

                val_inputs.append( np.vstack(extended_in) )
                val_outputs.append(state_vec+extended_out)
                masks.append( np.vstack(utter_mask) )

            x_seq = np.dstack(val_inputs)
            x_seq = np.asarray([ x.T for x in x_seq ],'float32')
            y_hat_seq = np.hstack(val_outputs)
            mask_seq  = np.dstack(masks)
            mask_seq  = np.asarray([ m.T for m in mask_seq ],'float32')

            val_result = nn.test(x_seq,mask_seq)

            nequal = (np.argmax(val_result, axis=2) != y_hat_seq[:,0,:])
            total_count += nequal.shape[0] * nequal.shape[1]
            val_error_count += np.sum(nequal)

            #val_maxpositions = np.ravel(np.argmax(val_result,axis=2).T)
            #total_count += val_maxpositions.shape[0]
            #val_error_count += len([ i \
            #    for i,j in zip(val_maxpositions,y_hat_seq) if i!=j])
        valerror = float(val_error_count)/total_count

    tStartR = time.time()
    if VAL_SET_RATIO != 1:
        prev_3, prev_2, prev_err = prev_2, prev_err, 100*valerror
        print "Epoch:",epoch+1,"| Cost:",cost,"| Val Error:", 100*valerror,'%', "| Epoch time:",tEnd-tStart
Exemplo n.º 2
0
        zeros = np.zeros((mask_max-utter_len, mem_pgram.shape[1]))
        extended_in  = [ i for i in mem_pgram[start:end,:], zeros]

        utter_mask = [ np.ones((utter_len,1)),
                       np.zeros((mask_max-utter_len,1)) ]

        batched_inputs.append( np.vstack(extended_in) )
        masks.append( np.vstack(utter_mask) )

    x_seq = np.dstack(batched_inputs)
    x_seq = np.asarray([ x.T for x in x_seq ],'float32')
    mask_seq  = np.dstack(masks)
    mask_seq  = np.asarray([ m.T for m in mask_seq ],'float32')

    y_seq = nn.test(x_seq, mask_seq)

    y_seq = np.argmax(y_seq, axis=2)
    
    for one_seq, one_mask, utter_idx \
        in zip(y_seq.T, mask_seq[:,:,0].T, pickList[p_s:p_e]) :

        utter_len = IDs_utter[utter_idx][1]
        one_seq = [ PhoneMap48to39[ PhoneMapIdxtoPh48[ph]] \
            for ph in one_seq[:utter_len] ]
        final_seq = []
        if FIX:
            # open a window of size 3, a|b|c 
            # if a == c and b != a, then directly change b to a :P
            final_seq.append( one_seq[0] )
            for i in xrange(1,len(one_seq)-1):
Exemplo n.º 3
0
        zeros = np.zeros((mask_max-utter_len, mem_pgram.shape[1]))
        extended_in  = [ i for i in mem_pgram[start:end,:], zeros]

        utter_mask = [ np.ones((utter_len,1)),
                       np.zeros((mask_max-utter_len,1)) ]

        batched_inputs.append( np.vstack(extended_in) )
        masks.append( np.vstack(utter_mask) )

    x_seq = np.dstack(batched_inputs)
    x_seq = np.asarray([ x.T for x in x_seq ],'float32')
    mask_seq  = np.dstack(masks)
    mask_seq  = np.asarray([ m.T for m in mask_seq ],'float32')

    y_seq = nn.test(x_seq, mask_seq)

    y_seq = np.argmax(y_seq, axis=2)
    
    for one_seq, one_mask, utter_idx \
        in zip(y_seq.T, mask_seq[:,:,0].T, pickList[p_s:p_e]) :

        utter_len = IDs_utter[utter_idx][1]
        one_seq = [ PhoneMap48to39[ PhoneMapIdxtoPh48[ph]] \
            for ph in one_seq[:utter_len] ]
        final_seq = []
        if FIX:
            # open a window of size 3, a|b|c 
            # if a == c and b != a, then directly change b to a :P
            final_seq.append( one_seq[0] )
            for i in xrange(1,len(one_seq)-1):
Exemplo n.º 4
0
                utter_mask = [
                    np.ones((utter_len, 1)),
                    np.zeros((mask_max - utter_len, 1))
                ]

                val_inputs.append(np.vstack(extended_in))
                val_outputs.append(state_vec + extended_out)
                masks.append(np.vstack(utter_mask))

            x_seq = np.dstack(val_inputs)
            x_seq = np.asarray([x.T for x in x_seq], 'float32')
            y_hat_seq = np.dstack(val_outputs)
            mask_seq = np.dstack(masks)
            mask_seq = np.asarray([m.T for m in mask_seq], 'float32')

            val_result = nn.test(x_seq, mask_seq)

            nequal = (np.argmax(val_result, axis=2) != y_hat_seq[:, 0, :])
            total_count += nequal.shape[0] * nequal.shape[1]
            val_error_count += np.sum(nequal)
            #pdb.set_trace()
            #val_maxpositions = np.ravel(np.argmax(val_result,axis=2).T)
            #total_count += val_maxpositions.shape[0]
            #val_error_count += len([ i \
            #    for i,j in zip(val_maxpositions,y_hat_seq) if i!=j])
        valerror = float(val_error_count) / total_count

    tStartR = time.time()
    if VAL_SET_RATIO != 1:
        prev_3, prev_2, prev_err = prev_2, prev_err, 100 * valerror
        print "Epoch:", epoch + 1, "| Cost:", cost, "| Val Error:", 100 * valerror, '%', "| Epoch time:", tEnd - tStart
Exemplo n.º 5
0
        zeros = np.zeros((mask_max-utter_len, mem_pgram.shape[1]))
        extended_in  = [ i for i in mem_pgram[start:end,:], zeros]

        utter_mask = [ np.ones((utter_len,1)),
                       np.zeros((mask_max-utter_len,1)) ]

        batched_inputs.append( np.vstack(extended_in) )
        masks.append( np.vstack(utter_mask) )

    x_seq = np.dstack(batched_inputs)
    x_seq = np.asarray([ x.T for x in x_seq ],'float32')
    mask_seq  = np.dstack(masks)
    mask_seq  = np.asarray([ m.T for m in mask_seq ],'float32')

    y1_seq = nn.test(x_seq, mask_seq)
    y2_seq = nn.test(y1_seq, mask_seq)

    y_seq = np.argmax(y2_seq, axis=2)
    
    for one_seq, one_mask, utter_idx \
        in zip(y_seq.T, mask_seq[:,:,0].T, pickList[p_s:p_e]) :

        utter_len = IDs_utter[utter_idx][1]
        one_seq = [ PhoneMap48to39[ PhoneMapIdxtoPh48[ph]] \
            for ph in one_seq[:utter_len] ]
        final_seq = []
        if FIX:
            # open a window of size 3, a|b|c 
            # if a == c and b != a, then directly change b to a :P
            final_seq.append( one_seq[0] )
Exemplo n.º 6
0
        zeros = np.zeros((mask_max - utter_len, mem_pgram.shape[1]))
        extended_in = [i for i in mem_pgram[start:end, :], zeros]

        utter_mask = [
            np.ones((utter_len, 1)),
            np.zeros((mask_max - utter_len, 1))
        ]

        batched_inputs.append(np.vstack(extended_in))
        masks.append(np.vstack(utter_mask))

    x_seq = np.dstack(batched_inputs)
    x_seq = np.asarray([x.T for x in x_seq], 'float32')
    mask_seq = np.dstack(masks)
    mask_seq = np.asarray([m.T for m in mask_seq], 'float32')

    result = nn.test(x_seq, mask_seq)
    result = result.reshape(end - start, 48)
    posteriorgram[start:end] += result[:]

    #posteriorgram[start:end,:] /= phone_map_freq

    # normalize to porb.
    #ph_sum = np.zeros((BATCH_SIZE,1))
    #ph_sum[:,0] = np.sum(posteriorgram[begin:end,:], axis=1)[:]
    #posteriorgram[start:end,:] /= ph_sum

    print result
    #posteriorgram[begin:end,:] = result[:,:].T
    del result