Using an embedding as a feature in a seperate model

1,197 views
Skip to first unread message

Marla Willemse

unread,
May 19, 2021, 5:50:42 AM5/19/21
to Keras-users
I am attempting to reduce the dimensionality of a categorical feature by extracting an embedding layer from a neural net and using it as an input feature in a seperate XGBoost model. 

An embedding layer has the dimensions (nr. unique categories, chosen output size). How can it be concatenated to the continuous variables in the original training data with the dimensions (nr. observations, nr. features)? Since each row in the embedding array represents a category, I assume that we can inner join the embedding array to our training observations on category, but how can we be certain which category is represented by a given row in the embedding array?

If the embedding output size is 10, will this constitute 10 different features when used as input data in a separate model? 

Does anyone perhaps know of a code example where embeddings are used as inputs to a seperate model of a different type?

Thanks in advance!

Yaoshiang Ho

unread,
May 19, 2021, 2:57:48 PM5/19/21
to Marla Willemse, Keras-users
One of the winners of this kaggle competition took the output of a convnet and put it into xgboost, which may be helpful


The basic solution to what you want would be to take an intermediate featuremap of shape NHWC (maybe N 64 64 128) and flatten it to NF where F = HxWxC. Now you have F features per image. 

(If it's the final featuremap before passing into the final dense classifier, a more modern solution would be to do a globalaveragepool along the H and W dims, resulting in a featuremap of NF where F=C).

Forward prop on that, unbatch, and now you have F features per image to pass to your GBDT. 

Y

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/24179c86-3e03-4973-aaaa-f450a5bf1cdcn%40googlegroups.com.

Marla Willemse

unread,
May 19, 2021, 4:30:07 PM5/19/21
to Yaoshiang Ho, Keras-users
Much thanks for your answer, Yaoshiang!

I am still not sure how to map rows in the embedding layer back to categories/ labels in the categorical column from which the embedding layer was derived. I am attempting to train a simple regression model. 

Yaoshiang Ho

unread,
May 19, 2021, 4:36:56 PM5/19/21
to Marla Willemse, Keras-users
Ah, sorry, I made the assumption you were training an XGBoost layer on top of a convnet. What I suggested above doesn't apply to your problem of ... sorry for misleading you here!

Y

Nguyễn Anh Hải

unread,
May 19, 2021, 10:39:18 PM5/19/21
to Yaoshiang Ho, Marla Willemse, Keras-users
Zalo_ScreenShot_20_5_2021_233949.png
Please help I am getting this error when running speaker_identification


Vào Th 5, 20 thg 5, 2021 vào lúc 03:36 Yaoshiang Ho <yaos...@gmail.com> đã viết:

Lance Norskog

unread,
May 20, 2021, 2:48:08 AM5/20/21
to Marla Willemse, Keras-users
Added an answer. 



--
Lance Norskog
lance....@gmail.com
Redwood City, CA

Madiouni Mohsen

unread,
May 24, 2021, 6:55:06 PM5/24/21
to Keras-users
Hi 
i am working with a dataset that have multitarget.
can one single MLP predict all the outputs or should i make for every target a custom  NN ?

morteza mohammady

unread,
May 24, 2021, 7:34:04 PM5/24/21
to Madiouni Mohsen, Keras-users
When you have multi target, you need to add multiple output layer for each target.

For example, you want to recognize face skin color and hair color. Assume you have 3 conv layers and two parallel softmax layers; one for skin color and another hair color.  The input of both softmax layers is the output of the last convolution layer

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages