{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tfjs/issues/783","repository_url":"https://api.github.com/repos/tensorflow/tfjs","labels_url":"https://api.github.com/repos/tensorflow/tfjs/issues/783/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tfjs/issues/783/comments","events_url":"https://api.github.com/repos/tensorflow/tfjs/issues/783/events","html_url":"https://github.com/tensorflow/tfjs/issues/783","id":369126418,"node_id":"MDU6SXNzdWUzNjkxMjY0MTg=","number":783,"title":"Trying to use tf.layers.embedding as starting layer results in expected embedding_Embedding1 to have 3 dimension(s)","user":{"login":"Lokesh-K-Haralakatta","id":18327888,"node_id":"MDQ6VXNlcjE4MzI3ODg4","avatar_url":"https://avatars1.githubusercontent.com/u/18327888?v=4","gravatar_id":"","url":"https://api.github.com/users/Lokesh-K-Haralakatta","html_url":"https://github.com/Lokesh-K-Haralakatta","followers_url":"https://api.github.com/users/Lokesh-K-Haralakatta/followers","following_url":"https://api.github.com/users/Lokesh-K-Haralakatta/following{/other_user}","gists_url":"https://api.github.com/users/Lokesh-K-Haralakatta/gists{/gist_id}","starred_url":"https://api.github.com/users/Lokesh-K-Haralakatta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lokesh-K-Haralakatta/subscriptions","organizations_url":"https://api.github.com/users/Lokesh-K-Haralakatta/orgs","repos_url":"https://api.github.com/users/Lokesh-K-Haralakatta/repos","events_url":"https://api.github.com/users/Lokesh-K-Haralakatta/events{/privacy}","received_events_url":"https://api.github.com/users/Lokesh-K-Haralakatta/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-11T13:39:53Z","updated_at":"2018-10-12T14:43:43Z","closed_at":null,"author_association":"NONE","body":"To get help from the community, check out our [Google group](https://groups.google.com/a/tensorflow.org/forum/#!forum/tfjs).\r\n\r\n#### TensorFlow.js version\r\nhttps://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.13.0\r\n#### Browser version\r\nN/A\r\n#### Describe the problem\r\nTrying to use tf.layers.embedding as a starting layer for a simple example but always results with the error while trying to train the model as pasted below:\r\n\r\nUncaught (in promise) Error: Error when checking target: expected embedding_Embedding1 to have 3 dimension(s). but got array with shape 6,1\r\n    at new t (tfjs@0.13.0:2)\r\n    at standardizeInputData (tfjs@0.13.0:2)\r\n    at t.standardizeUserData (tfjs@0.13.0:2)\r\n    at t.<anonymous> (tfjs@0.13.0:2)\r\n    at tfjs@0.13.0:2\r\n    at Object.next (tfjs@0.13.0:2)\r\n    at tfjs@0.13.0:2\r\n    at new Promise (<anonymous>)\r\n    at __awaiter$1 (tfjs@0.13.0:2)\r\n    at t.fit (tfjs@0.13.0:2)\r\n\r\n\r\n#### Code to reproduce the bug:\r\n\r\n//Sample data to train\r\nconst xs = tf.tensor2d([[1],[2],[3],[4],[5],[6]]);\r\nconst ys = tf.tensor2d([[1],[0],[1],[0],[1],[0]]);\r\n\r\n// Define a model\r\nconst model = tf.sequential();\r\n\r\n//Add layers to model\r\nmodel.add(tf.layers.embedding({\r\n                                    inputDim: xs.shape[0],\r\n                                    outputDim: xs.shape[1],\r\n                                    trainable: false\r\n                                  }));\r\n\r\nmodel.add(tf.layers.dense({units: 1, activation: 'sigmoid'}));\r\n\r\n// Train the model using the data\r\nawait model.fit(xs, ys, { batchSize: 2,epochs: 20 });\r\n\r\nPlease have a look and let me know anything is missed in the above given code sample due to which the error is being thrown."},"comment":{"url":"https://api.github.com/repos/tensorflow/tfjs/issues/comments/429350114","html_url":"https://github.com/tensorflow/tfjs/issues/783#issuecomment-429350114","issue_url":"https://api.github.com/repos/tensorflow/tfjs/issues/783","id":429350114,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTM1MDExNA==","user":{"login":"bileschi","id":547150,"node_id":"MDQ6VXNlcjU0NzE1MA==","avatar_url":"https://avatars1.githubusercontent.com/u/547150?v=4","gravatar_id":"","url":"https://api.github.com/users/bileschi","html_url":"https://github.com/bileschi","followers_url":"https://api.github.com/users/bileschi/followers","following_url":"https://api.github.com/users/bileschi/following{/other_user}","gists_url":"https://api.github.com/users/bileschi/gists{/gist_id}","starred_url":"https://api.github.com/users/bileschi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bileschi/subscriptions","organizations_url":"https://api.github.com/users/bileschi/orgs","repos_url":"https://api.github.com/users/bileschi/repos","events_url":"https://api.github.com/users/bileschi/events{/privacy}","received_events_url":"https://api.github.com/users/bileschi/received_events","type":"User","site_admin":false},"created_at":"2018-10-12T14:43:43Z","updated_at":"2018-10-12T14:43:43Z","author_association":"COLLABORATOR","body":"The API for tf.layers.embedding requires inputs be rank-2 (rank-3 including the batch).  What happened here is the layer received an input (xs) which is rank 2.\r\n\r\ninputDIm should be the size of the vocabulary\r\noutputDim should be the dimensionality of the vectorspace produced.\r\n\r\nIf you consider the inputs as sequences of length 1, this code should work: (note the additional square brackets)\r\n\r\n//Sample data to train\r\nconst xs = tf.tensor3d([[[1]],[[2]],[[3]],[[4]],[[5]],[[6]]]);\r\nconst ys = tf.tensor2d([[1],[0],[1],[0],[1],[0]]);\r\n\r\n// Define a model\r\nconst model = tf.sequential();\r\n\r\n//Add layers to model\r\nmodel.add(tf.layers.embedding({\r\ninputDim: 6,\r\noutputDim: 1,\r\ntrainable: true\r\n}));\r\nmodel.add(tf.layers.dense({units: 1, activation: 'sigmoid'}));\r\n\r\n// print out model summary\r\nmodel.summary():\r\n\r\n// compile\r\nmodel.compile({loss: \"meanSquaredError\", optimizer: \"sgd\"});\r\n// fit\r\n\r\nmodel.fit(xs, ys);\r\n```________________________________________________________________\r\ntfjs@0.13.0:2 Layer (type)                 Output shape              Param #   \r\ntfjs@0.13.0:2 =================================================================\r\ntfjs@0.13.0:2 embedding_Embedding1 (Embedd [null,null,1]             6         \r\ntfjs@0.13.0:2 _________________________________________________________________\r\ntfjs@0.13.0:2 dense_Dense1 (Dense)         [null,null,1]             2         \r\ntfjs@0.13.0:2 =================================================================\r\ntfjs@0.13.0:2 Total params: 8\r\ntfjs@0.13.0:2 Trainable params: 2\r\ntfjs@0.13.0:2 Non-trainable params: 6\r\ntfjs@0.13.0:2 \r\n```\r\n"}}
{"actor":{"display_login":"bileschi"}}