{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-singa/pulls/comments/74688743","id":74688743,"diff_hunk":"@@ -0,0 +1,132 @@\n+# Licensed to the Apache Software Foundation (ASF) under one\r\n+# or more contributor license agreements.  See the NOTICE file\r\n+# distributed with this work for additional information\r\n+# regarding copyright ownership.  The ASF licenses this file\r\n+# to you under the Apache License, Version 2.0 (the\r\n+# \"License\"); you may not use this file except in compliance\r\n+# with the License.  You may obtain a copy of the License at\r\n+#\r\n+#   http://www.apache.org/licenses/LICENSE-2.0\r\n+#\r\n+# Unless required by applicable law or agreed to in writing, software\r\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\r\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n+# See the License for the specific language governing permissions and\r\n+# limitations under the License.\r\n+# =============================================================================\r\n+\r\n+import cPickle\r\n+import numpy as np\r\n+import numpy.matlib\r\n+import os\r\n+import sys\r\n+import gzip, numpy\r\n+\r\n+\r\n+sys.path.append(os.path.join(os.path.dirname(__file__),\r\n+                             '../../build/python'))\r\n+sys.path.append(os.path.join(os.path.dirname(__file__),\r\n+                             '../../build/lib'))\r\n+sys.path.append(os.path.join(os.path.dirname(__file__),'../../build/src'))\r\n+from singa import initializer\r\n+from singa import utils\r\n+from singa import optimizer\r\n+from singa import device\r\n+from singa import tensor\r\n+from singa.proto import core_pb2\r\n+\r\n+\r\n+\r\n+def load_train_data(dir_path):\r\n+    f = gzip.open(dir_path, 'rb')\r\n+    train_set, valid_set, test_set = cPickle.load(f)\r\n+    traindata = train_set[0].astype(np.float32)\r\n+    validdata = valid_set[0].astype(np.float32)\r\n+    return traindata, validdata\r\n+\r\n+\r\n+\r\n+def train(data_dir, num_epoch=10, batch_size=100):\r\n+    print 'Start intialization............'\r\n+    lr = 0.1   # Learning rate\r\n+    weight_decay  = 0.0002\r\n+    hdim = 1000\r\n+    vdim = 784\r\n+    opt = optimizer.SGD(momentum=0.8, weight_decay=weight_decay)\r\n+    \r\n+    shape = (vdim, hdim)\r\n+    tweight = tensor.Tensor(shape)\r\n+    initializer.gaussian(tweight, 0.0, 0.1)\r\n+    tvbias = tensor.from_numpy(np.zeros(vdim, dtype = np.float32))\r\n+    thbias = tensor.from_numpy(np.zeros(hdim, dtype = np.float32))\r\n+    opt = optimizer.SGD(momentum=0.5, weight_decay=weight_decay)\r\n+\r\n+    print 'Loading data ..................'\r\n+    train_x, valid_x = load_train_data(data_dir)\r\n+\r\n+    num_train_batch = train_x.shape[0]/batch_size\r\n+    print \"num_train_batch = \\n\", num_train_batch\r\n+    for epoch in range(num_epoch):\r\n+        trainerrorsum = 0.0\r\n+        validerrorsum = 0.0\r\n+        print 'Epoch %d' % epoch\r\n+        for b in range(num_train_batch):\r\n+            # positive phase\r\n+            if b % 100 == 0:\r\n+                print \"batch: \\n\", b\r\n+\r\n+\r\n+            tdata = tensor.from_numpy(train_x[ (b * batch_size): ((b + 1) * batch_size), : ])\r\n+            tposhidprob = tensor.mult(tdata, tweight)\r\n+            tposhidprob.add_row(thbias)\r\n+            tposhidprob = tensor.sigmoid(tposhidprob)\r\n+            tposhidrandom = tensor.Tensor(tposhidprob.shape)\r\n+            initializer.uniform(tposhidrandom, 0.0, 1.0)\r\n+            tposhidsample = tensor.gt(tposhidprob, tposhidrandom)\r\n+\r\n+            tvaliddata = tensor.from_numpy(valid_x[ (b * batch_size / (train_x.shape[0] / valid_x.shape[0])): ((b + 1) * batch_size / (train_x.shape[0] / valid_x.shape[0])), : ])\r","path":"examples/mnist/train.py","position":87,"original_position":87,"commit_id":"dfd248796e899fc8a7c91dd2acaf05048ffe70a8","original_commit_id":"dfd248796e899fc8a7c91dd2acaf05048ffe70a8","user":{"login":"nudles","id":3797447,"avatar_url":"https://avatars.githubusercontent.com/u/3797447?v=3","gravatar_id":"","url":"https://api.github.com/users/nudles","html_url":"https://github.com/nudles","followers_url":"https://api.github.com/users/nudles/followers","following_url":"https://api.github.com/users/nudles/following{/other_user}","gists_url":"https://api.github.com/users/nudles/gists{/gist_id}","starred_url":"https://api.github.com/users/nudles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nudles/subscriptions","organizations_url":"https://api.github.com/users/nudles/orgs","repos_url":"https://api.github.com/users/nudles/repos","events_url":"https://api.github.com/users/nudles/events{/privacy}","received_events_url":"https://api.github.com/users/nudles/received_events","type":"User","site_admin":false},"body":"what is tvaliddata?\r\ndo you do validation for every mini-batch for your experiment?","created_at":"2016-08-13T16:12:28Z","updated_at":"2016-08-13T16:12:28Z","html_url":"https://github.com/apache/incubator-singa/pull/240#discussion_r74688743","pull_request_url":"https://api.github.com/repos/apache/incubator-singa/pulls/240","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-singa/pulls/comments/74688743"},"html":{"href":"https://github.com/apache/incubator-singa/pull/240#discussion_r74688743"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-singa/pulls/240"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-singa/pulls/240","id":81091979,"html_url":"https://github.com/apache/incubator-singa/pull/240","diff_url":"https://github.com/apache/incubator-singa/pull/240.diff","patch_url":"https://github.com/apache/incubator-singa/pull/240.patch","issue_url":"https://api.github.com/repos/apache/incubator-singa/issues/240","number":240,"state":"open","locked":false,"title":"SINGA-238 RBM on mnist","user":{"login":"lzjpaul","id":8807719,"avatar_url":"https://avatars.githubusercontent.com/u/8807719?v=3","gravatar_id":"","url":"https://api.github.com/users/lzjpaul","html_url":"https://github.com/lzjpaul","followers_url":"https://api.github.com/users/lzjpaul/followers","following_url":"https://api.github.com/users/lzjpaul/following{/other_user}","gists_url":"https://api.github.com/users/lzjpaul/gists{/gist_id}","starred_url":"https://api.github.com/users/lzjpaul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lzjpaul/subscriptions","organizations_url":"https://api.github.com/users/lzjpaul/orgs","repos_url":"https://api.github.com/users/lzjpaul/repos","events_url":"https://api.github.com/users/lzjpaul/events{/privacy}","received_events_url":"https://api.github.com/users/lzjpaul/received_events","type":"User","site_admin":false},"body":"Implement RBM python version on mnist data set\r\n1. The model is following: http://www.cs.toronto.edu/~hinton/science.pdf\r\n2. This model is implemented using python tensors\r\n3. Users should first download mnist.pkl.gz","created_at":"2016-08-12T09:36:39Z","updated_at":"2016-08-13T16:12:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6d46ee6a818b4573b42e8ba68a087b7c9f7b2edb","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-singa/pulls/240/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-singa/pulls/240/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-singa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-singa/issues/240/comments","statuses_url":"https://api.github.com/repos/apache/incubator-singa/statuses/dfd248796e899fc8a7c91dd2acaf05048ffe70a8","head":{"label":"lzjpaul:rbm-python-PR","ref":"rbm-python-PR","sha":"dfd248796e899fc8a7c91dd2acaf05048ffe70a8","user":{"login":"lzjpaul","id":8807719,"avatar_url":"https://avatars.githubusercontent.com/u/8807719?v=3","gravatar_id":"","url":"https://api.github.com/users/lzjpaul","html_url":"https://github.com/lzjpaul","followers_url":"https://api.github.com/users/lzjpaul/followers","following_url":"https://api.github.com/users/lzjpaul/following{/other_user}","gists_url":"https://api.github.com/users/lzjpaul/gists{/gist_id}","starred_url":"https://api.github.com/users/lzjpaul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lzjpaul/subscriptions","organizations_url":"https://api.github.com/users/lzjpaul/orgs","repos_url":"https://api.github.com/users/lzjpaul/repos","events_url":"https://api.github.com/users/lzjpaul/events{/privacy}","received_events_url":"https://api.github.com/users/lzjpaul/received_events","type":"User","site_admin":false},"repo":{"id":35958925,"name":"incubator-singa","full_name":"lzjpaul/incubator-singa","owner":{"login":"lzjpaul","id":8807719,"avatar_url":"https://avatars.githubusercontent.com/u/8807719?v=3","gravatar_id":"","url":"https://api.github.com/users/lzjpaul","html_url":"https://github.com/lzjpaul","followers_url":"https://api.github.com/users/lzjpaul/followers","following_url":"https://api.github.com/users/lzjpaul/following{/other_user}","gists_url":"https://api.github.com/users/lzjpaul/gists{/gist_id}","starred_url":"https://api.github.com/users/lzjpaul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lzjpaul/subscriptions","organizations_url":"https://api.github.com/users/lzjpaul/orgs","repos_url":"https://api.github.com/users/lzjpaul/repos","events_url":"https://api.github.com/users/lzjpaul/events{/privacy}","received_events_url":"https://api.github.com/users/lzjpaul/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lzjpaul/incubator-singa","description":"Mirror of Apache Singa (Incubating)","fork":true,"url":"https://api.github.com/repos/lzjpaul/incubator-singa","forks_url":"https://api.github.com/repos/lzjpaul/incubator-singa/forks","keys_url":"https://api.github.com/repos/lzjpaul/incubator-singa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lzjpaul/incubator-singa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lzjpaul/incubator-singa/teams","hooks_url":"https://api.github.com/repos/lzjpaul/incubator-singa/hooks","issue_events_url":"https://api.github.com/repos/lzjpaul/incubator-singa/issues/events{/number}","events_url":"https://api.github.com/repos/lzjpaul/incubator-singa/events","assignees_url":"https://api.github.com/repos/lzjpaul/incubator-singa/assignees{/user}","branches_url":"https://api.github.com/repos/lzjpaul/incubator-singa/branches{/branch}","tags_url":"https://api.github.com/repos/lzjpaul/incubator-singa/tags","blobs_url":"https://api.github.com/repos/lzjpaul/incubator-singa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lzjpaul/incubator-singa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lzjpaul/incubator-singa/git/refs{/sha}","trees_url":"https://api.github.com/repos/lzjpaul/incubator-singa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lzjpaul/incubator-singa/statuses/{sha}","languages_url":"https://api.github.com/repos/lzjpaul/incubator-singa/languages","stargazers_url":"https://api.github.com/repos/lzjpaul/incubator-singa/stargazers","contributors_url":"https://api.github.com/repos/lzjpaul/incubator-singa/contributors","subscribers_url":"https://api.github.com/repos/lzjpaul/incubator-singa/subscribers","subscription_url":"https://api.github.com/repos/lzjpaul/incubator-singa/subscription","commits_url":"https://api.github.com/repos/lzjpaul/incubator-singa/commits{/sha}","git_commits_url":"https://api.github.com/repos/lzjpaul/incubator-singa/git/commits{/sha}","comments_url":"https://api.github.com/repos/lzjpaul/incubator-singa/comments{/number}","issue_comment_url":"https://api.github.com/repos/lzjpaul/incubator-singa/issues/comments{/number}","contents_url":"https://api.github.com/repos/lzjpaul/incubator-singa/contents/{+path}","compare_url":"https://api.github.com/repos/lzjpaul/incubator-singa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lzjpaul/incubator-singa/merges","archive_url":"https://api.github.com/repos/lzjpaul/incubator-singa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lzjpaul/incubator-singa/downloads","issues_url":"https://api.github.com/repos/lzjpaul/incubator-singa/issues{/number}","pulls_url":"https://api.github.com/repos/lzjpaul/incubator-singa/pulls{/number}","milestones_url":"https://api.github.com/repos/lzjpaul/incubator-singa/milestones{/number}","notifications_url":"https://api.github.com/repos/lzjpaul/incubator-singa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lzjpaul/incubator-singa/labels{/name}","releases_url":"https://api.github.com/repos/lzjpaul/incubator-singa/releases{/id}","deployments_url":"https://api.github.com/repos/lzjpaul/incubator-singa/deployments","created_at":"2015-05-20T16:06:24Z","updated_at":"2015-07-13T09:00:07Z","pushed_at":"2016-08-13T08:17:11Z","git_url":"git://github.com/lzjpaul/incubator-singa.git","ssh_url":"git@github.com:lzjpaul/incubator-singa.git","clone_url":"https://github.com/lzjpaul/incubator-singa.git","svn_url":"https://github.com/lzjpaul/incubator-singa","homepage":null,"size":35213,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"apache:dev","ref":"dev","sha":"a91bf2a7ef9b8ba86973e579f4e170a0aa816444","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":33294317,"name":"incubator-singa","full_name":"apache/incubator-singa","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-singa","description":"Mirror of Apache Singa (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-singa","forks_url":"https://api.github.com/repos/apache/incubator-singa/forks","keys_url":"https://api.github.com/repos/apache/incubator-singa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-singa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-singa/teams","hooks_url":"https://api.github.com/repos/apache/incubator-singa/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-singa/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-singa/events","assignees_url":"https://api.github.com/repos/apache/incubator-singa/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-singa/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-singa/tags","blobs_url":"https://api.github.com/repos/apache/incubator-singa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-singa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-singa/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-singa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-singa/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-singa/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-singa/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-singa/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-singa/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-singa/subscription","commits_url":"https://api.github.com/repos/apache/incubator-singa/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-singa/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-singa/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-singa/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-singa/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-singa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-singa/merges","archive_url":"https://api.github.com/repos/apache/incubator-singa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-singa/downloads","issues_url":"https://api.github.com/repos/apache/incubator-singa/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-singa/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-singa/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-singa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-singa/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-singa/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-singa/deployments","created_at":"2015-04-02T07:00:05Z","updated_at":"2016-08-10T02:12:03Z","pushed_at":"2016-08-13T09:38:58Z","git_url":"git://github.com/apache/incubator-singa.git","ssh_url":"git@github.com:apache/incubator-singa.git","clone_url":"https://github.com/apache/incubator-singa.git","svn_url":"https://github.com/apache/incubator-singa","homepage":null,"size":10175,"stargazers_count":618,"watchers_count":618,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":214,"mirror_url":"git://git.apache.org/incubator-singa.git","open_issues_count":17,"forks":214,"open_issues":17,"watchers":618,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-singa/pulls/240"},"html":{"href":"https://github.com/apache/incubator-singa/pull/240"},"issue":{"href":"https://api.github.com/repos/apache/incubator-singa/issues/240"},"comments":{"href":"https://api.github.com/repos/apache/incubator-singa/issues/240/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-singa/pulls/240/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-singa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-singa/pulls/240/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-singa/statuses/dfd248796e899fc8a7c91dd2acaf05048ffe70a8"}}}}
{"actor":{"display_login":"nudles"}}