{"action":"created","comment":{"url":"https://api.github.com/repos/fchollet/keras/pulls/comments/37800242","id":37800242,"diff_hunk":"@@ -64,19 +64,24 @@ def slice_X(X, start=None, stop=None):\n \n def weighted_objective(fn):\n     def weighted(y_true, y_pred, weights, mask=None):\n-        # it's important that 0 * Inf == 0, not NaN, so I need to mask first\n-        masked_y_true = y_true[weights.nonzero()[:-1]]\n-        masked_y_pred = y_pred[weights.nonzero()[:-1]]\n-        masked_weights = weights[weights.nonzero()]\n-        obj_output = fn(masked_y_true, masked_y_pred)\n+        '''\n+        y_true dimension:  (sample, timestep, dims)\n+        y_pred dimension:  (sample, timestep, dims)\n+        weights dimension: (sample, timestep, 1)\n+        '''","path":"keras/models.py","position":13,"original_position":13,"commit_id":"9e001ee70cd274fbea1491658a3d35a8dbc264a9","original_commit_id":"9e001ee70cd274fbea1491658a3d35a8dbc264a9","user":{"login":"fchollet","id":710255,"avatar_url":"https://avatars.githubusercontent.com/u/710255?v=3","gravatar_id":"","url":"https://api.github.com/users/fchollet","html_url":"https://github.com/fchollet","followers_url":"https://api.github.com/users/fchollet/followers","following_url":"https://api.github.com/users/fchollet/following{/other_user}","gists_url":"https://api.github.com/users/fchollet/gists{/gist_id}","starred_url":"https://api.github.com/users/fchollet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fchollet/subscriptions","organizations_url":"https://api.github.com/users/fchollet/orgs","repos_url":"https://api.github.com/users/fchollet/repos","events_url":"https://api.github.com/users/fchollet/events{/privacy}","received_events_url":"https://api.github.com/users/fchollet/received_events","type":"User","site_admin":false},"body":"When a mask is provided, it means that the input has time steps. However the input might not necessarily be `(samples, timesteps, dims)`, it should more generally be considered to be `(samples, timesteps, **)` (e.g. sequences of pictures).","created_at":"2015-08-24T20:28:47Z","updated_at":"2015-08-24T20:28:47Z","html_url":"https://github.com/fchollet/keras/pull/592#discussion_r37800242","pull_request_url":"https://api.github.com/repos/fchollet/keras/pulls/592","_links":{"self":{"href":"https://api.github.com/repos/fchollet/keras/pulls/comments/37800242"},"html":{"href":"https://github.com/fchollet/keras/pull/592#discussion_r37800242"},"pull_request":{"href":"https://api.github.com/repos/fchollet/keras/pulls/592"}}},"pull_request":{"url":"https://api.github.com/repos/fchollet/keras/pulls/592","id":43212824,"html_url":"https://github.com/fchollet/keras/pull/592","diff_url":"https://github.com/fchollet/keras/pull/592.diff","patch_url":"https://github.com/fchollet/keras/pull/592.patch","issue_url":"https://api.github.com/repos/fchollet/keras/issues/592","number":592,"state":"open","locked":false,"title":"Fix weight mask interaction in objectives","user":{"login":"wxs","id":326559,"avatar_url":"https://avatars.githubusercontent.com/u/326559?v=3","gravatar_id":"","url":"https://api.github.com/users/wxs","html_url":"https://github.com/wxs","followers_url":"https://api.github.com/users/wxs/followers","following_url":"https://api.github.com/users/wxs/following{/other_user}","gists_url":"https://api.github.com/users/wxs/gists{/gist_id}","starred_url":"https://api.github.com/users/wxs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wxs/subscriptions","organizations_url":"https://api.github.com/users/wxs/orgs","repos_url":"https://api.github.com/users/wxs/repos","events_url":"https://api.github.com/users/wxs/events{/privacy}","received_events_url":"https://api.github.com/users/wxs/received_events","type":"User","site_admin":false},"body":"We used nonzero() on the weights in order to ensure that if there\r\nhappened to be a NaN or an Inf in the output that was going to be masked\r\nabout by the weights anyway, it wouldn't propagate (because 0*inf = NaN)\r\nhowever this was causing interaction issues if you also used a mask,\r\nbecause that wasn't using nonzero() properly.\r\n\r\nThis fixes that, and also fixes what I believe was an issue where I was\r\ncalling mean() instead of dividing by the sum of the sample weights.\r\n\r\nPlease think about this carefully: getting the normalization across both forms of weights right is a bit subtle, and I screwed up a number of times before creating this PR. I *think* it's right now though.","created_at":"2015-08-24T19:37:29Z","updated_at":"2015-08-24T20:28:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1342b25a04cfbe6fe486d2490d03b544335eed0b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fchollet/keras/pulls/592/commits","review_comments_url":"https://api.github.com/repos/fchollet/keras/pulls/592/comments","review_comment_url":"https://api.github.com/repos/fchollet/keras/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/592/comments","statuses_url":"https://api.github.com/repos/fchollet/keras/statuses/9e001ee70cd274fbea1491658a3d35a8dbc264a9","head":{"label":"wxs:fix-weight-mask-interaction","ref":"fix-weight-mask-interaction","sha":"9e001ee70cd274fbea1491658a3d35a8dbc264a9","user":{"login":"wxs","id":326559,"avatar_url":"https://avatars.githubusercontent.com/u/326559?v=3","gravatar_id":"","url":"https://api.github.com/users/wxs","html_url":"https://github.com/wxs","followers_url":"https://api.github.com/users/wxs/followers","following_url":"https://api.github.com/users/wxs/following{/other_user}","gists_url":"https://api.github.com/users/wxs/gists{/gist_id}","starred_url":"https://api.github.com/users/wxs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wxs/subscriptions","organizations_url":"https://api.github.com/users/wxs/orgs","repos_url":"https://api.github.com/users/wxs/repos","events_url":"https://api.github.com/users/wxs/events{/privacy}","received_events_url":"https://api.github.com/users/wxs/received_events","type":"User","site_admin":false},"repo":{"id":37118074,"name":"keras","full_name":"wxs/keras","owner":{"login":"wxs","id":326559,"avatar_url":"https://avatars.githubusercontent.com/u/326559?v=3","gravatar_id":"","url":"https://api.github.com/users/wxs","html_url":"https://github.com/wxs","followers_url":"https://api.github.com/users/wxs/followers","following_url":"https://api.github.com/users/wxs/following{/other_user}","gists_url":"https://api.github.com/users/wxs/gists{/gist_id}","starred_url":"https://api.github.com/users/wxs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wxs/subscriptions","organizations_url":"https://api.github.com/users/wxs/orgs","repos_url":"https://api.github.com/users/wxs/repos","events_url":"https://api.github.com/users/wxs/events{/privacy}","received_events_url":"https://api.github.com/users/wxs/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wxs/keras","description":"Theano-based Deep Learning library (convnets, recurrent neural networks, and more).","fork":true,"url":"https://api.github.com/repos/wxs/keras","forks_url":"https://api.github.com/repos/wxs/keras/forks","keys_url":"https://api.github.com/repos/wxs/keras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wxs/keras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wxs/keras/teams","hooks_url":"https://api.github.com/repos/wxs/keras/hooks","issue_events_url":"https://api.github.com/repos/wxs/keras/issues/events{/number}","events_url":"https://api.github.com/repos/wxs/keras/events","assignees_url":"https://api.github.com/repos/wxs/keras/assignees{/user}","branches_url":"https://api.github.com/repos/wxs/keras/branches{/branch}","tags_url":"https://api.github.com/repos/wxs/keras/tags","blobs_url":"https://api.github.com/repos/wxs/keras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wxs/keras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wxs/keras/git/refs{/sha}","trees_url":"https://api.github.com/repos/wxs/keras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wxs/keras/statuses/{sha}","languages_url":"https://api.github.com/repos/wxs/keras/languages","stargazers_url":"https://api.github.com/repos/wxs/keras/stargazers","contributors_url":"https://api.github.com/repos/wxs/keras/contributors","subscribers_url":"https://api.github.com/repos/wxs/keras/subscribers","subscription_url":"https://api.github.com/repos/wxs/keras/subscription","commits_url":"https://api.github.com/repos/wxs/keras/commits{/sha}","git_commits_url":"https://api.github.com/repos/wxs/keras/git/commits{/sha}","comments_url":"https://api.github.com/repos/wxs/keras/comments{/number}","issue_comment_url":"https://api.github.com/repos/wxs/keras/issues/comments{/number}","contents_url":"https://api.github.com/repos/wxs/keras/contents/{+path}","compare_url":"https://api.github.com/repos/wxs/keras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wxs/keras/merges","archive_url":"https://api.github.com/repos/wxs/keras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wxs/keras/downloads","issues_url":"https://api.github.com/repos/wxs/keras/issues{/number}","pulls_url":"https://api.github.com/repos/wxs/keras/pulls{/number}","milestones_url":"https://api.github.com/repos/wxs/keras/milestones{/number}","notifications_url":"https://api.github.com/repos/wxs/keras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wxs/keras/labels{/name}","releases_url":"https://api.github.com/repos/wxs/keras/releases{/id}","created_at":"2015-06-09T07:46:56Z","updated_at":"2015-06-09T07:46:57Z","pushed_at":"2015-08-24T19:28:10Z","git_url":"git://github.com/wxs/keras.git","ssh_url":"git@github.com:wxs/keras.git","clone_url":"https://github.com/wxs/keras.git","svn_url":"https://github.com/wxs/keras","homepage":"http://keras.io/","size":926,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"fchollet:master","ref":"master","sha":"34999c865896642e25d46d6334200775008e1562","user":{"login":"fchollet","id":710255,"avatar_url":"https://avatars.githubusercontent.com/u/710255?v=3","gravatar_id":"","url":"https://api.github.com/users/fchollet","html_url":"https://github.com/fchollet","followers_url":"https://api.github.com/users/fchollet/followers","following_url":"https://api.github.com/users/fchollet/following{/other_user}","gists_url":"https://api.github.com/users/fchollet/gists{/gist_id}","starred_url":"https://api.github.com/users/fchollet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fchollet/subscriptions","organizations_url":"https://api.github.com/users/fchollet/orgs","repos_url":"https://api.github.com/users/fchollet/repos","events_url":"https://api.github.com/users/fchollet/events{/privacy}","received_events_url":"https://api.github.com/users/fchollet/received_events","type":"User","site_admin":false},"repo":{"id":33015583,"name":"keras","full_name":"fchollet/keras","owner":{"login":"fchollet","id":710255,"avatar_url":"https://avatars.githubusercontent.com/u/710255?v=3","gravatar_id":"","url":"https://api.github.com/users/fchollet","html_url":"https://github.com/fchollet","followers_url":"https://api.github.com/users/fchollet/followers","following_url":"https://api.github.com/users/fchollet/following{/other_user}","gists_url":"https://api.github.com/users/fchollet/gists{/gist_id}","starred_url":"https://api.github.com/users/fchollet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fchollet/subscriptions","organizations_url":"https://api.github.com/users/fchollet/orgs","repos_url":"https://api.github.com/users/fchollet/repos","events_url":"https://api.github.com/users/fchollet/events{/privacy}","received_events_url":"https://api.github.com/users/fchollet/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fchollet/keras","description":"Theano-based Deep Learning library (convnets, recurrent neural networks, and more).","fork":false,"url":"https://api.github.com/repos/fchollet/keras","forks_url":"https://api.github.com/repos/fchollet/keras/forks","keys_url":"https://api.github.com/repos/fchollet/keras/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fchollet/keras/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fchollet/keras/teams","hooks_url":"https://api.github.com/repos/fchollet/keras/hooks","issue_events_url":"https://api.github.com/repos/fchollet/keras/issues/events{/number}","events_url":"https://api.github.com/repos/fchollet/keras/events","assignees_url":"https://api.github.com/repos/fchollet/keras/assignees{/user}","branches_url":"https://api.github.com/repos/fchollet/keras/branches{/branch}","tags_url":"https://api.github.com/repos/fchollet/keras/tags","blobs_url":"https://api.github.com/repos/fchollet/keras/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fchollet/keras/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fchollet/keras/git/refs{/sha}","trees_url":"https://api.github.com/repos/fchollet/keras/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fchollet/keras/statuses/{sha}","languages_url":"https://api.github.com/repos/fchollet/keras/languages","stargazers_url":"https://api.github.com/repos/fchollet/keras/stargazers","contributors_url":"https://api.github.com/repos/fchollet/keras/contributors","subscribers_url":"https://api.github.com/repos/fchollet/keras/subscribers","subscription_url":"https://api.github.com/repos/fchollet/keras/subscription","commits_url":"https://api.github.com/repos/fchollet/keras/commits{/sha}","git_commits_url":"https://api.github.com/repos/fchollet/keras/git/commits{/sha}","comments_url":"https://api.github.com/repos/fchollet/keras/comments{/number}","issue_comment_url":"https://api.github.com/repos/fchollet/keras/issues/comments{/number}","contents_url":"https://api.github.com/repos/fchollet/keras/contents/{+path}","compare_url":"https://api.github.com/repos/fchollet/keras/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fchollet/keras/merges","archive_url":"https://api.github.com/repos/fchollet/keras/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fchollet/keras/downloads","issues_url":"https://api.github.com/repos/fchollet/keras/issues{/number}","pulls_url":"https://api.github.com/repos/fchollet/keras/pulls{/number}","milestones_url":"https://api.github.com/repos/fchollet/keras/milestones{/number}","notifications_url":"https://api.github.com/repos/fchollet/keras/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fchollet/keras/labels{/name}","releases_url":"https://api.github.com/repos/fchollet/keras/releases{/id}","created_at":"2015-03-28T00:35:42Z","updated_at":"2015-08-24T16:37:58Z","pushed_at":"2015-08-24T19:37:29Z","git_url":"git://github.com/fchollet/keras.git","ssh_url":"git@github.com:fchollet/keras.git","clone_url":"https://github.com/fchollet/keras.git","svn_url":"https://github.com/fchollet/keras","homepage":"http://keras.io/","size":3076,"stargazers_count":2576,"watchers_count":2576,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":472,"mirror_url":null,"open_issues_count":77,"forks":472,"open_issues":77,"watchers":2576,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fchollet/keras/pulls/592"},"html":{"href":"https://github.com/fchollet/keras/pull/592"},"issue":{"href":"https://api.github.com/repos/fchollet/keras/issues/592"},"comments":{"href":"https://api.github.com/repos/fchollet/keras/issues/592/comments"},"review_comments":{"href":"https://api.github.com/repos/fchollet/keras/pulls/592/comments"},"review_comment":{"href":"https://api.github.com/repos/fchollet/keras/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fchollet/keras/pulls/592/commits"},"statuses":{"href":"https://api.github.com/repos/fchollet/keras/statuses/9e001ee70cd274fbea1491658a3d35a8dbc264a9"}}}}