Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecated example on categorical embeddings #190

Open
heyitskoma opened this issue Dec 14, 2017 · 0 comments
Open

deprecated example on categorical embeddings #190

heyitskoma opened this issue Dec 14, 2017 · 0 comments

Comments

@heyitskoma
Copy link

Hi, this comes from: https://github.com/fastai/courses/blob/master/deeplearning2/rossman.ipynb

the below code doesn't work using keras 2.0. Would anyone know what are the needed changes to get this to work?

def my_init(scale):
    return lambda shape, name=None: initializations.uniform(shape, scale=scale, name=name)

def emb_init(shape, name=None): 
    return initializations.uniform(shape, scale=2/(shape[1]+1), name=name)

def get_emb(feat):
    name, c = cat_map_info(feat)
    #c2 = cat_var_dict[name]
    c2 = (c+1)//2
    if c2>50: c2=50
    inp = Input((1,), dtype='int64', name=name+'_in')
    # , W_regularizer=l2(1e-6)
    u = Flatten(name=name+'_flt')(Embedding(c, c2, input_length=1, init=emb_init)(inp))
#     u = Flatten(name=name+'_flt')(Embedding(c, c2, input_length=1)(inp))
    return inp,u

def get_contin(feat):
    name = feat[0][0]
    inp = Input((1,), name=name+'_in')
    return inp, Dense(1, name=name+'_d', init=my_init(1.))(inp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant