src/core/data.py
def embed_data(x, dset):
    '''
    Convenience function: embeds x into the code space using the corresponding
    autoencoder (specified by dset).
    '''
    if not len(x):
        return np.zeros(shape=(0, 10))
    if dset == 'reuters':
        dset = 'reuters10k'

    json_path = '../pretrain_weights/ae_{}.json'.format(dset)
    weights_path = '../pretrain_weights/ae_{}_weights.h5'.format(dset)

    with open(json_path) as f:
        pt_ae = model_from_json(f.read())
    pt_ae.load_weights(weights_path)

    x = x.reshape(-1, np.prod(x.shape[1:]))

    get_embeddings = K.function([pt_ae.input],
                                  [pt_ae.layers[3].output])

    get_reconstruction = K.function([pt_ae.layers[4].input],
                                  [pt_ae.output])
    x_embedded = predict_with_K_fn(get_embeddings, x)[0]
    x_recon = predict_with_K_fn(get_reconstruction, x_embedded)[0]
    reconstruction_mse = np.mean(np.square(x - x_recon))
    print("using pretrained embeddings; sanity check, total reconstruction error:", np.mean(reconstruction_mse))

    del pt_ae

    return x_embedded

    Convenience function: embeds x into the code space using the corresponding
    autoencoder (specified by dset).
    
Convenience function: embeds x into the code space using the corresponding
autoencoder (specified by dset).
Convenience function : embeds x into the code space using the corresponding autoencoder ( specified by dset ) .
def embed_data(x, dset):
    if not len(x):
        return np.zeros(shape=(0, 10))
    if dset == 'reuters':
        dset = 'reuters10k'
    json_path = '../pretrain_weights/ae_{}.json'.format(dset)
    weights_path = '../pretrain_weights/ae_{}_weights.h5'.format(dset)
    with open(json_path) as f:
        pt_ae = model_from_json(f.read())
    pt_ae.load_weights(weights_path)
    x = x.reshape(-1, np.prod(x.shape[1:]))
    get_embeddings = K.function([pt_ae.input],
                                  [pt_ae.layers[3].output])
    get_reconstruction = K.function([pt_ae.layers[4].input],
                                  [pt_ae.output])
    x_embedded = predict_with_K_fn(get_embeddings, x)[0]
    x_recon = predict_with_K_fn(get_reconstruction, x_embedded)[0]
    reconstruction_mse = np.mean(np.square(x - x_recon))
    print("using pretrained embeddings; sanity check, total reconstruction error:", np.mean(reconstruction_mse))
    del pt_ae
    return x_embedded
def embed_data ( x , dset ) : if not len ( x ) : return np . zeros ( shape = ( 0 , 10 ) ) if dset == 'reuters' : dset = 'reuters10k' json_path = '../pretrain_weights/ae_{}.json' . format ( dset ) weights_path = '../pretrain_weights/ae_{}_weights.h5' . format ( dset ) with open ( json_path ) as f : pt_ae = model_from_json ( f . read ( ) ) pt_ae . load_weights ( weights_path ) x = x . reshape ( - 1 , np . prod ( x . shape [ 1 : ] ) ) get_embeddings = K . function ( [ pt_ae . input ] , [ pt_ae . layers [ 3 ] . output ] ) get_reconstruction = K . function ( [ pt_ae . layers [ 4 ] . input ] , [ pt_ae . output ] ) x_embedded = predict_with_K_fn ( get_embeddings , x ) [ 0 ] x_recon = predict_with_K_fn ( get_reconstruction , x_embedded ) [ 0 ] reconstruction_mse = np . mean ( np . square ( x - x_recon ) ) print ( "using pretrained embeddings; sanity check, total reconstruction error:" , np . mean ( reconstruction_mse ) ) del pt_ae return x_embedded
Convenience function: embeds x into the code space using the corresponding
autoencoder (specified by dset).
Convenience function : embeds x into the code space using the corresponding autoencoder ( specified by dset ) .
'''
    Convenience function: embeds x into the code space using the corresponding
    autoencoder (specified by dset).
    '''
x
dset