(labels, nclass=5, ndata=None)
return Y
Label encoding from Tree LSTM paper (Tai, Socher, Manning)
Label encoding from Tree LSTM paper (Tai, Socher, Manning)
Label encoding from Tree LSTM paper ( Tai Socher Manning )
def encode_labels(labels, nclass=5, ndata=None):
    """
    Label encoding from Tree LSTM paper (Tai, Socher, Manning)
    """
    Y = np.zeros((len(labels), nclass)).astype('float32')
    for j, y in enumerate(labels):
        for i in range(nclass):
            if i+1 == np.floor(y) + 1:
                Y[j, i] = y - np.floor(y)
            if i+1 == np.floor(y):
                Y[j, i] = np.floor(y) - y + 1
    if ndata:
        Y = Y[:ndata]

    return Y
def encode_labels ( labels , nclass = 5 , ndata = None ) : Y = np . zeros ( ( len ( labels ) , nclass ) ) . astype ( 'float32' ) for j , y in enumerate ( labels ) : for i in range ( nclass ) : if i + 1 == np . floor ( y ) + 1 : Y [ j , i ] = y - np . floor ( y ) if i + 1 == np . floor ( y ) : Y [ j , i ] = np . floor ( y ) - y + 1 if ndata : Y = Y [ : ndata ] return Y