{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/16044","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/16044/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/16044/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/16044/events","html_url":"https://github.com/tensorflow/tensorflow/issues/16044","id":287836724,"number":16044,"title":"Feature Request: tf.multi_one_hot that is one-hot encoding multiple columns of a Tensor","user":{"login":"squall-1002","id":19616286,"avatar_url":"https://avatars1.githubusercontent.com/u/19616286?v=4","gravatar_id":"","url":"https://api.github.com/users/squall-1002","html_url":"https://github.com/squall-1002","followers_url":"https://api.github.com/users/squall-1002/followers","following_url":"https://api.github.com/users/squall-1002/following{/other_user}","gists_url":"https://api.github.com/users/squall-1002/gists{/gist_id}","starred_url":"https://api.github.com/users/squall-1002/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squall-1002/subscriptions","organizations_url":"https://api.github.com/users/squall-1002/orgs","repos_url":"https://api.github.com/users/squall-1002/repos","events_url":"https://api.github.com/users/squall-1002/events{/privacy}","received_events_url":"https://api.github.com/users/squall-1002/received_events","type":"User","site_admin":false},"labels":[{"id":299643928,"url":"https://api.github.com/repos/tensorflow/tensorflow/labels/stat:contributions%20welcome","name":"stat:contributions welcome","color":"009800","default":false},{"id":473173272,"url":"https://api.github.com/repos/tensorflow/tensorflow/labels/type:feature","name":"type:feature","color":"c2e0c6","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-01-11T16:12:08Z","updated_at":"2018-02-17T12:16:36Z","closed_at":null,"author_association":"NONE","body":"Hi there,\r\n\r\nI just wrote a function that creates multiple one-hot-encodings for a tensor and concatenates them. I was curious whether this might serve some others and contribute this feature.\r\n\r\n\r\n```\r\ndef multiple_one_hot(cat_tensor, depth_list):\r\n    \"\"\"Creates one-hot-encodings for multiple categorical attributes and\r\n    concatenates the resulting encodings\r\n\r\n    Args:\r\n        cat_tensor (tf.Tensor): tensor with mutiple columns containing categorical features\r\n        depth_list (list): list of the no. of values (depth) for each categorical\r\n\r\n    Returns:\r\n        one_hot_enc_tensor (tf.Tensor): concatenated one-hot-encodings of cat_tensor\r\n    \"\"\"\r\n    one_hot_enc_tensor = tf.one_hot(cat_int_tensor[:,0], depth_list[0], axis=1)\r\n    for col in range(1, len(depth_list)):\r\n        add = tf.one_hot(cat_int_tensor[:,col], depth_list[col], axis=1)\r\n        one_hot_enc_tensor = tf.concat([one_hot_enc_tensor, add], axis=1)\r\n\r\n    return one_hot_enc_tensor\r\n\r\n```\r\nI am happy for your feedback. Tell me if you think others might profit and I would enjoy to create a pull request ;)"},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/366437521","html_url":"https://github.com/tensorflow/tensorflow/issues/16044#issuecomment-366437521","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/16044","id":366437521,"user":{"login":"squall-1002","id":19616286,"avatar_url":"https://avatars1.githubusercontent.com/u/19616286?v=4","gravatar_id":"","url":"https://api.github.com/users/squall-1002","html_url":"https://github.com/squall-1002","followers_url":"https://api.github.com/users/squall-1002/followers","following_url":"https://api.github.com/users/squall-1002/following{/other_user}","gists_url":"https://api.github.com/users/squall-1002/gists{/gist_id}","starred_url":"https://api.github.com/users/squall-1002/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squall-1002/subscriptions","organizations_url":"https://api.github.com/users/squall-1002/orgs","repos_url":"https://api.github.com/users/squall-1002/repos","events_url":"https://api.github.com/users/squall-1002/events{/privacy}","received_events_url":"https://api.github.com/users/squall-1002/received_events","type":"User","site_admin":false},"created_at":"2018-02-17T12:16:36Z","updated_at":"2018-02-17T12:16:36Z","author_association":"NONE","body":"@wileeam Of course: Recommender Systems ;)\r\nIn RecSys I am dealing with lots of features of varying modalities, among them many categorical features. Assume we work on vehicle recommendations for an online market, I have colors, fuel types, maker IDs, model IDs, etc. The way we treat those features is to one-hot encode them. But, where colors or fuel types may have tens of possible values, we may have thousands of model IDs which is why I can't include this as a test as I would be way too much.\r\nIn this case and I assume in others where people deal with multiple categorical features, one could profit from a higher abstraction of **tf.one_hot** which is why I propose **tf.multi_one_hot**.\r\nHope that helps you to understand the practical use of it."}}
{"actor":{"display_login":"squall-1002"}}