{"action":"created","comment":{"url":"https://api.github.com/repos/hqzizania/crf-spark/pulls/comments/51980519","id":51980519,"diff_hunk":"@@ -0,0 +1,367 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.intel.nlp\n+\n+import breeze.numerics.{exp, log}\n+import scala.collection.mutable.ArrayBuffer\n+import org.apache.spark.broadcast.Broadcast\n+\n+private[nlp] class Tagger (var ySize: Int,\n+                           mode: Int) extends Serializable {\n+  // mode: LEARN 2, TEST 1\n+  var nBest: Int = 0\n+  var cost: Double = 0.0\n+  var Z: Double = 0.0\n+  var feature_id: Int = 0\n+  var thread_id: Int = 0\n+  var x: ArrayBuffer[Array[String]] = new ArrayBuffer[Array[String]]()\n+  var node: ArrayBuffer[ArrayBuffer[Node]] = new ArrayBuffer[ArrayBuffer[Node]]\n+  var answer: ArrayBuffer[Int] = new ArrayBuffer[Int]()\n+  var result: ArrayBuffer[Int] = new ArrayBuffer[Int]()\n+  val MINUS_LOG_EPSILON = 50\n+  var obj: Double = 0.0\n+  var featureCache = Array[Int]()\n+  var featureCacheH= Array[Int]()\n+  var costFactor: Double = 1.0\n+\n+  def setCostFactor(costFactor: Double) = {\n+    this.costFactor = costFactor\n+    this\n+  }\n+\n+  def read(lines: Array[String], feature_idx: Feature) {\n+    var i: Int = 0\n+    var columns: Array[String] = null\n+    var j: Int = 0\n+    lines.foreach{ t =>\n+      columns = t.split('|')\n+      if (mode == 2) {\n+        for (y <- feature_idx.labels if y.equals(columns(feature_idx.tokensSize)))\n+          answer.append(feature_idx.labels.indexOf(y))\n+        x.append(columns.dropRight(1))\n+      } else {\n+        x.append(columns)\n+        answer.append(0)\n+      }\n+      result.append(0)\n+    }\n+  }\n+\n+  def setFeatureId(id: Int): Unit = {\n+    feature_id = id\n+  }\n+\n+\n+  /**\n+   * Build the matrix to calculate\n+   * cost of each node according to template\n+   */\n+  def buildLattice(bcAlpha: Broadcast[Array[Double]]): Unit = {\n+    require(x.nonEmpty, \"This sentence is null!\")\n+    rebuildFeatures\n+\n+    for (i <- x.indices) {\n+      for (j <- 0 until ySize) {\n+        node(i)(j) = calcCost(node(i)(j), bcAlpha)\n+        var k = 0\n+        while (k < node(i)(j).lPath.length) {\n+          node(i)(j).lPath(k) = calcCost(node(i)(j).lPath(k), bcAlpha)\n+          k += 1\n+        }\n+      }\n+    }\n+\n+  }\n+\n+\n+\n+  def calcCost(n: Node, bcAlpha: Broadcast[Array[Double]]): Node = {","path":"src/main/scala/com/intel/nlp/Tagger.scala","position":92,"original_position":92,"commit_id":"57b0bec956ec34193112eb766e2efbf45784f868","original_commit_id":"57b0bec956ec34193112eb766e2efbf45784f868","user":{"login":"chenghao-intel","id":2367031,"avatar_url":"https://avatars.githubusercontent.com/u/2367031?v=3","gravatar_id":"","url":"https://api.github.com/users/chenghao-intel","html_url":"https://github.com/chenghao-intel","followers_url":"https://api.github.com/users/chenghao-intel/followers","following_url":"https://api.github.com/users/chenghao-intel/following{/other_user}","gists_url":"https://api.github.com/users/chenghao-intel/gists{/gist_id}","starred_url":"https://api.github.com/users/chenghao-intel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenghao-intel/subscriptions","organizations_url":"https://api.github.com/users/chenghao-intel/orgs","repos_url":"https://api.github.com/users/chenghao-intel/repos","events_url":"https://api.github.com/users/chenghao-intel/events{/privacy}","received_events_url":"https://api.github.com/users/chenghao-intel/received_events","type":"User","site_admin":false},"body":"since most of the code is not related with Spark, probably we use `Array[Double]` instead for `bcAlpha`.","created_at":"2016-02-05T05:56:00Z","updated_at":"2016-02-05T05:56:00Z","html_url":"https://github.com/hqzizania/crf-spark/pull/1#discussion_r51980519","pull_request_url":"https://api.github.com/repos/hqzizania/crf-spark/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/hqzizania/crf-spark/pulls/comments/51980519"},"html":{"href":"https://github.com/hqzizania/crf-spark/pull/1#discussion_r51980519"},"pull_request":{"href":"https://api.github.com/repos/hqzizania/crf-spark/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/hqzizania/crf-spark/pulls/1","id":58382118,"html_url":"https://github.com/hqzizania/crf-spark/pull/1","diff_url":"https://github.com/hqzizania/crf-spark/pull/1.diff","patch_url":"https://github.com/hqzizania/crf-spark/pull/1.patch","issue_url":"https://api.github.com/repos/hqzizania/crf-spark/issues/1","number":1,"state":"open","locked":false,"title":"Phase I","user":{"login":"hqzizania","id":9315372,"avatar_url":"https://avatars.githubusercontent.com/u/9315372?v=3","gravatar_id":"","url":"https://api.github.com/users/hqzizania","html_url":"https://github.com/hqzizania","followers_url":"https://api.github.com/users/hqzizania/followers","following_url":"https://api.github.com/users/hqzizania/following{/other_user}","gists_url":"https://api.github.com/users/hqzizania/gists{/gist_id}","starred_url":"https://api.github.com/users/hqzizania/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hqzizania/subscriptions","organizations_url":"https://api.github.com/users/hqzizania/orgs","repos_url":"https://api.github.com/users/hqzizania/repos","events_url":"https://api.github.com/users/hqzizania/events{/privacy}","received_events_url":"https://api.github.com/users/hqzizania/received_events","type":"User","site_admin":false},"body":"Phase I","created_at":"2016-02-05T02:49:09Z","updated_at":"2016-02-05T05:56:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf2bb0444cb74938c94fe9f9ea762139fbdde082","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hqzizania/crf-spark/pulls/1/commits","review_comments_url":"https://api.github.com/repos/hqzizania/crf-spark/pulls/1/comments","review_comment_url":"https://api.github.com/repos/hqzizania/crf-spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hqzizania/crf-spark/issues/1/comments","statuses_url":"https://api.github.com/repos/hqzizania/crf-spark/statuses/57b0bec956ec34193112eb766e2efbf45784f868","head":{"label":"hqzizania:slave","ref":"slave","sha":"57b0bec956ec34193112eb766e2efbf45784f868","user":{"login":"hqzizania","id":9315372,"avatar_url":"https://avatars.githubusercontent.com/u/9315372?v=3","gravatar_id":"","url":"https://api.github.com/users/hqzizania","html_url":"https://github.com/hqzizania","followers_url":"https://api.github.com/users/hqzizania/followers","following_url":"https://api.github.com/users/hqzizania/following{/other_user}","gists_url":"https://api.github.com/users/hqzizania/gists{/gist_id}","starred_url":"https://api.github.com/users/hqzizania/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hqzizania/subscriptions","organizations_url":"https://api.github.com/users/hqzizania/orgs","repos_url":"https://api.github.com/users/hqzizania/repos","events_url":"https://api.github.com/users/hqzizania/events{/privacy}","received_events_url":"https://api.github.com/users/hqzizania/received_events","type":"User","site_admin":false},"repo":{"id":50564341,"name":"crf-spark","full_name":"hqzizania/crf-spark","owner":{"login":"hqzizania","id":9315372,"avatar_url":"https://avatars.githubusercontent.com/u/9315372?v=3","gravatar_id":"","url":"https://api.github.com/users/hqzizania","html_url":"https://github.com/hqzizania","followers_url":"https://api.github.com/users/hqzizania/followers","following_url":"https://api.github.com/users/hqzizania/following{/other_user}","gists_url":"https://api.github.com/users/hqzizania/gists{/gist_id}","starred_url":"https://api.github.com/users/hqzizania/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hqzizania/subscriptions","organizations_url":"https://api.github.com/users/hqzizania/orgs","repos_url":"https://api.github.com/users/hqzizania/repos","events_url":"https://api.github.com/users/hqzizania/events{/privacy}","received_events_url":"https://api.github.com/users/hqzizania/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hqzizania/crf-spark","description":"An Spark-based implementation of Conditional Random Fields (CRFs) for labeling sequential data","fork":false,"url":"https://api.github.com/repos/hqzizania/crf-spark","forks_url":"https://api.github.com/repos/hqzizania/crf-spark/forks","keys_url":"https://api.github.com/repos/hqzizania/crf-spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hqzizania/crf-spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hqzizania/crf-spark/teams","hooks_url":"https://api.github.com/repos/hqzizania/crf-spark/hooks","issue_events_url":"https://api.github.com/repos/hqzizania/crf-spark/issues/events{/number}","events_url":"https://api.github.com/repos/hqzizania/crf-spark/events","assignees_url":"https://api.github.com/repos/hqzizania/crf-spark/assignees{/user}","branches_url":"https://api.github.com/repos/hqzizania/crf-spark/branches{/branch}","tags_url":"https://api.github.com/repos/hqzizania/crf-spark/tags","blobs_url":"https://api.github.com/repos/hqzizania/crf-spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hqzizania/crf-spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hqzizania/crf-spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/hqzizania/crf-spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hqzizania/crf-spark/statuses/{sha}","languages_url":"https://api.github.com/repos/hqzizania/crf-spark/languages","stargazers_url":"https://api.github.com/repos/hqzizania/crf-spark/stargazers","contributors_url":"https://api.github.com/repos/hqzizania/crf-spark/contributors","subscribers_url":"https://api.github.com/repos/hqzizania/crf-spark/subscribers","subscription_url":"https://api.github.com/repos/hqzizania/crf-spark/subscription","commits_url":"https://api.github.com/repos/hqzizania/crf-spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/hqzizania/crf-spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/hqzizania/crf-spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/hqzizania/crf-spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/hqzizania/crf-spark/contents/{+path}","compare_url":"https://api.github.com/repos/hqzizania/crf-spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hqzizania/crf-spark/merges","archive_url":"https://api.github.com/repos/hqzizania/crf-spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hqzizania/crf-spark/downloads","issues_url":"https://api.github.com/repos/hqzizania/crf-spark/issues{/number}","pulls_url":"https://api.github.com/repos/hqzizania/crf-spark/pulls{/number}","milestones_url":"https://api.github.com/repos/hqzizania/crf-spark/milestones{/number}","notifications_url":"https://api.github.com/repos/hqzizania/crf-spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hqzizania/crf-spark/labels{/name}","releases_url":"https://api.github.com/repos/hqzizania/crf-spark/releases{/id}","deployments_url":"https://api.github.com/repos/hqzizania/crf-spark/deployments","created_at":"2016-01-28T07:20:09Z","updated_at":"2016-02-02T12:49:29Z","pushed_at":"2016-02-05T02:54:18Z","git_url":"git://github.com/hqzizania/crf-spark.git","ssh_url":"git@github.com:hqzizania/crf-spark.git","clone_url":"https://github.com/hqzizania/crf-spark.git","svn_url":"https://github.com/hqzizania/crf-spark","homepage":"","size":596,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"hqzizania:slave2","ref":"slave2","sha":"9cf879d2c7e3f85b6736473f25340b2605866039","user":{"login":"hqzizania","id":9315372,"avatar_url":"https://avatars.githubusercontent.com/u/9315372?v=3","gravatar_id":"","url":"https://api.github.com/users/hqzizania","html_url":"https://github.com/hqzizania","followers_url":"https://api.github.com/users/hqzizania/followers","following_url":"https://api.github.com/users/hqzizania/following{/other_user}","gists_url":"https://api.github.com/users/hqzizania/gists{/gist_id}","starred_url":"https://api.github.com/users/hqzizania/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hqzizania/subscriptions","organizations_url":"https://api.github.com/users/hqzizania/orgs","repos_url":"https://api.github.com/users/hqzizania/repos","events_url":"https://api.github.com/users/hqzizania/events{/privacy}","received_events_url":"https://api.github.com/users/hqzizania/received_events","type":"User","site_admin":false},"repo":{"id":50564341,"name":"crf-spark","full_name":"hqzizania/crf-spark","owner":{"login":"hqzizania","id":9315372,"avatar_url":"https://avatars.githubusercontent.com/u/9315372?v=3","gravatar_id":"","url":"https://api.github.com/users/hqzizania","html_url":"https://github.com/hqzizania","followers_url":"https://api.github.com/users/hqzizania/followers","following_url":"https://api.github.com/users/hqzizania/following{/other_user}","gists_url":"https://api.github.com/users/hqzizania/gists{/gist_id}","starred_url":"https://api.github.com/users/hqzizania/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hqzizania/subscriptions","organizations_url":"https://api.github.com/users/hqzizania/orgs","repos_url":"https://api.github.com/users/hqzizania/repos","events_url":"https://api.github.com/users/hqzizania/events{/privacy}","received_events_url":"https://api.github.com/users/hqzizania/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hqzizania/crf-spark","description":"An Spark-based implementation of Conditional Random Fields (CRFs) for labeling sequential data","fork":false,"url":"https://api.github.com/repos/hqzizania/crf-spark","forks_url":"https://api.github.com/repos/hqzizania/crf-spark/forks","keys_url":"https://api.github.com/repos/hqzizania/crf-spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hqzizania/crf-spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hqzizania/crf-spark/teams","hooks_url":"https://api.github.com/repos/hqzizania/crf-spark/hooks","issue_events_url":"https://api.github.com/repos/hqzizania/crf-spark/issues/events{/number}","events_url":"https://api.github.com/repos/hqzizania/crf-spark/events","assignees_url":"https://api.github.com/repos/hqzizania/crf-spark/assignees{/user}","branches_url":"https://api.github.com/repos/hqzizania/crf-spark/branches{/branch}","tags_url":"https://api.github.com/repos/hqzizania/crf-spark/tags","blobs_url":"https://api.github.com/repos/hqzizania/crf-spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hqzizania/crf-spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hqzizania/crf-spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/hqzizania/crf-spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hqzizania/crf-spark/statuses/{sha}","languages_url":"https://api.github.com/repos/hqzizania/crf-spark/languages","stargazers_url":"https://api.github.com/repos/hqzizania/crf-spark/stargazers","contributors_url":"https://api.github.com/repos/hqzizania/crf-spark/contributors","subscribers_url":"https://api.github.com/repos/hqzizania/crf-spark/subscribers","subscription_url":"https://api.github.com/repos/hqzizania/crf-spark/subscription","commits_url":"https://api.github.com/repos/hqzizania/crf-spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/hqzizania/crf-spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/hqzizania/crf-spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/hqzizania/crf-spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/hqzizania/crf-spark/contents/{+path}","compare_url":"https://api.github.com/repos/hqzizania/crf-spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hqzizania/crf-spark/merges","archive_url":"https://api.github.com/repos/hqzizania/crf-spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hqzizania/crf-spark/downloads","issues_url":"https://api.github.com/repos/hqzizania/crf-spark/issues{/number}","pulls_url":"https://api.github.com/repos/hqzizania/crf-spark/pulls{/number}","milestones_url":"https://api.github.com/repos/hqzizania/crf-spark/milestones{/number}","notifications_url":"https://api.github.com/repos/hqzizania/crf-spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hqzizania/crf-spark/labels{/name}","releases_url":"https://api.github.com/repos/hqzizania/crf-spark/releases{/id}","deployments_url":"https://api.github.com/repos/hqzizania/crf-spark/deployments","created_at":"2016-01-28T07:20:09Z","updated_at":"2016-02-02T12:49:29Z","pushed_at":"2016-02-05T02:54:18Z","git_url":"git://github.com/hqzizania/crf-spark.git","ssh_url":"git@github.com:hqzizania/crf-spark.git","clone_url":"https://github.com/hqzizania/crf-spark.git","svn_url":"https://github.com/hqzizania/crf-spark","homepage":"","size":596,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hqzizania/crf-spark/pulls/1"},"html":{"href":"https://github.com/hqzizania/crf-spark/pull/1"},"issue":{"href":"https://api.github.com/repos/hqzizania/crf-spark/issues/1"},"comments":{"href":"https://api.github.com/repos/hqzizania/crf-spark/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/hqzizania/crf-spark/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/hqzizania/crf-spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hqzizania/crf-spark/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/hqzizania/crf-spark/statuses/57b0bec956ec34193112eb766e2efbf45784f868"}}}}