{"action":"created","comment":{"url":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/comments/53379027","id":53379027,"diff_hunk":"@@ -0,0 +1,266 @@\n+// durmod/kaldi-durmod.h\n+\n+// Copyright 2015, Hossein Hadian\n+\n+// See ../../COPYING for clarification regarding multiple authors\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//  http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\n+// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\n+// MERCHANTABLITY OR NON-INFRINGEMENT.\n+// See the Apache 2 License for the specific language governing permissions and\n+// limitations under the License.\n+#ifndef DURMOD_KALDI_DURMOD_H_\n+#define DURMOD_KALDI_DURMOD_H_\n+\n+#include <iostream>\n+#include <vector>\n+#include <utility>\n+#include <string>\n+\n+#include \"base/kaldi-common.h\"\n+#include \"lat/kaldi-lattice.h\"\n+#include \"nnet3/nnet-example.h\"\n+#include \"nnet3/nnet-nnet.h\"\n+#include \"nnet3/nnet-example-utils.h\"\n+#include \"nnet3/nnet-optimize.h\"\n+#include \"util/common-utils.h\"\n+#include \"util/stl-utils.h\"\n+#include \"fstext/deterministic-fst.h\"\n+\n+namespace kaldi {\n+  using nnet3::Nnet;\n+  using nnet3::NnetExample;\n+  using nnet3::NnetIo;\n+  using nnet3::CachingOptimizingCompiler;\n+  using nnet3::ComputationRequest;\n+  using nnet3::NnetComputation;\n+  using nnet3::NnetComputeOptions;\n+  using nnet3::NnetComputer;\n+\n+struct PhoneDurationModelOptions {\n+  int32 left_context, right_context;\n+  int32 max_duration;\n+\n+  void Register(OptionsItf *po);\n+\n+  PhoneDurationModelOptions():\n+    left_context(4),\n+    right_context(2),\n+    max_duration(60) {}\n+};\n+\n+class PhoneDurationModel {\n+  friend class PhoneDurationFeatureMaker;\n+\n+ public:\n+  void Read(std::istream &is, bool binary);\n+  void Write(std::ostream &os, bool binary) const;\n+\n+  PhoneDurationModel() {}\n+  PhoneDurationModel(const PhoneDurationModelOptions &opts,\n+                     const std::vector<std::vector<int32> > &roots,\n+                     const std::vector<std::vector<int32> > &questions):\n+    left_context_(opts.left_context),\n+    right_context_(opts.right_context),\n+    roots_(roots),\n+    questions_(questions),\n+    max_duration_(opts.max_duration) {}\n+\n+  inline int32 MaxDuration() const { return max_duration_; }\n+  inline int32 RightContext() const { return right_context_; }\n+  inline int32 LeftContext() const { return left_context_; }\n+  inline int32 FullContextSize() const {\n+    return left_context_ + right_context_ + 1;\n+  }\n+  std::string Info() const;\n+\n+ private:\n+  int32 left_context_, right_context_;\n+  std::vector<std::vector<int32> > roots_;\n+  std::vector<std::vector<int32> > questions_;\n+  int32 max_duration_;\n+};\n+\n+class PhoneDurationFeatureMaker {\n+ public:\n+  explicit PhoneDurationFeatureMaker(const PhoneDurationModel &model);\n+\n+  void InitFeatureMaker(const PhoneDurationModel &model);\n+\n+  /// This method extracts features for a phone. The inputs are a\n+  /// phone-duration context and an index into that context which indicates the\n+  /// middle phone (middle in the sense of left/right context).\n+  /// a phone-duration context is a sequence of <phone-ID, duration-in-frames>\n+  /// pairs.\n+  /// The extracted features consist of phone-IDs (which are represented in a\n+  /// 1-of-n encoding, suitable for neural networks), phone durations, and\n+  /// binary features determined from a set of questions\n+  /// (i.e. extra_questions.int)\n+  void MakeFeatureVector(\n+                 const std::vector<std::pair<int32, int32> > &phone_dur_context,\n+                 int phone_index,\n+                 SparseVector<BaseFloat> *feat) const;\n+\n+\n+  int32 FeatureDim() const { return feature_dim_; }\n+  int32 NumBinaryFeatures() const { return num_binary_features_; }\n+  int32 NumPhoneIdentities() const { return num_phone_identities_; }\n+  int32 OutputDim() const { return max_duration_; }\n+\n+  std::string Info() const;\n+\n+ private:\n+  unordered_map<int32, std::vector<int32> > binary_feats_;\n+  unordered_map<int32, int32> phone_id_;","path":"src/durmod/kaldi-durmod.h","position":121,"original_position":121,"commit_id":"25f5bdc6095748975ab9c791c563b81c76d6b5be","original_commit_id":"25f5bdc6095748975ab9c791c563b81c76d6b5be","user":{"login":"danpovey","id":3298747,"avatar_url":"https://avatars.githubusercontent.com/u/3298747?v=3","gravatar_id":"","url":"https://api.github.com/users/danpovey","html_url":"https://github.com/danpovey","followers_url":"https://api.github.com/users/danpovey/followers","following_url":"https://api.github.com/users/danpovey/following{/other_user}","gists_url":"https://api.github.com/users/danpovey/gists{/gist_id}","starred_url":"https://api.github.com/users/danpovey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danpovey/subscriptions","organizations_url":"https://api.github.com/users/danpovey/orgs","repos_url":"https://api.github.com/users/danpovey/repos","events_url":"https://api.github.com/users/danpovey/events{/privacy}","received_events_url":"https://api.github.com/users/danpovey/received_events","type":"User","site_admin":false},"body":"OK, I don't recall that right now.  Regardless, it should be documented.\n and the name should be clearer, e.g. phone_to_id_, so it's clear that it\nmaps phones to ids.\n\nDan\n\n\nOn Thu, Feb 18, 2016 at 3:26 AM, Hossein Hadian <notifications@github.com>\nwrote:\n\n> In src/durmod/kaldi-durmod.h\n> <https://github.com/kaldi-asr/kaldi/pull/414#discussion_r53283307>:\n>\n> > +  void MakeFeatureVector(\n> > +                 const std::vector<std::pair<int32, int32> > &phone_dur_context,\n> > +                 int phone_index,\n> > +                 SparseVector<BaseFloat> *feat) const;\n> > +\n> > +\n> > +  int32 FeatureDim() const { return feature_dim_; }\n> > +  int32 NumBinaryFeatures() const { return num_binary_features_; }\n> > +  int32 NumPhoneIdentities() const { return num_phone_identities_; }\n> > +  int32 OutputDim() const { return max_duration_; }\n> > +\n> > +  std::string Info() const;\n> > +\n> > + private:\n> > +  unordered_map<int32, std::vector<int32> > binary_feats_;\n> > +  unordered_map<int32, int32> phone_id_;\n>\n> The mapping (which is based on roots.int) is done according to the\n> initial discussion that you emailed to me. In fact, the phones in each root\n> set, will have the same id for 1-of-n encoding.\n> Binary features are in fact the extra questions. I will add comments for\n> these.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/kaldi-asr/kaldi/pull/414/files#r53283307>.\n>\n","created_at":"2016-02-18T20:41:12Z","updated_at":"2016-02-18T20:41:12Z","html_url":"https://github.com/kaldi-asr/kaldi/pull/414#discussion_r53379027","pull_request_url":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/414","_links":{"self":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/comments/53379027"},"html":{"href":"https://github.com/kaldi-asr/kaldi/pull/414#discussion_r53379027"},"pull_request":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/414"}}},"pull_request":{"url":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/414","id":54508198,"html_url":"https://github.com/kaldi-asr/kaldi/pull/414","diff_url":"https://github.com/kaldi-asr/kaldi/pull/414.diff","patch_url":"https://github.com/kaldi-asr/kaldi/pull/414.patch","issue_url":"https://api.github.com/repos/kaldi-asr/kaldi/issues/414","number":414,"state":"open","locked":false,"title":"Phone duration modeling using nnet3","user":{"login":"hhadian","id":15056653,"avatar_url":"https://avatars.githubusercontent.com/u/15056653?v=3","gravatar_id":"","url":"https://api.github.com/users/hhadian","html_url":"https://github.com/hhadian","followers_url":"https://api.github.com/users/hhadian/followers","following_url":"https://api.github.com/users/hhadian/following{/other_user}","gists_url":"https://api.github.com/users/hhadian/gists{/gist_id}","starred_url":"https://api.github.com/users/hhadian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hhadian/subscriptions","organizations_url":"https://api.github.com/users/hhadian/orgs","repos_url":"https://api.github.com/users/hhadian/repos","events_url":"https://api.github.com/users/hhadian/events{/privacy}","received_events_url":"https://api.github.com/users/hhadian/received_events","type":"User","site_admin":false},"body":"I would be glad to use any suggestions. Thanks in advance.\r\nSome notes:\r\n1. I have tested this code for generating examples and training using nnet3-merge and nnet3-train and the next step is to prepare the rescoring codes.\r\n2. I'm not sure how to determine max_duration_ (in frames) so that we can make sure there is enough training data for all durations. I think, since the approximate distribution of durations is log-normal, we could use log-normal statistics to find a reasonable max_duration_ using mean and variance for eg.\r\nThe other way is to find the maximum phone duration d such that there is at least 1 training phone for all durations d-1, d-2,... too. \r\n3. Should I put my name as the author for the new source files ? For now I have put no author names (just Johns Hopkins University).\r\n\r\nThank you.\r\n","created_at":"2015-12-23T21:26:45Z","updated_at":"2016-02-18T20:41:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6354cffc99cce179bb028d8a3fa2bcb3f4294189","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/414/commits","review_comments_url":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/414/comments","review_comment_url":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kaldi-asr/kaldi/issues/414/comments","statuses_url":"https://api.github.com/repos/kaldi-asr/kaldi/statuses/25f5bdc6095748975ab9c791c563b81c76d6b5be","head":{"label":"hhadian:duration-model","ref":"duration-model","sha":"25f5bdc6095748975ab9c791c563b81c76d6b5be","user":{"login":"hhadian","id":15056653,"avatar_url":"https://avatars.githubusercontent.com/u/15056653?v=3","gravatar_id":"","url":"https://api.github.com/users/hhadian","html_url":"https://github.com/hhadian","followers_url":"https://api.github.com/users/hhadian/followers","following_url":"https://api.github.com/users/hhadian/following{/other_user}","gists_url":"https://api.github.com/users/hhadian/gists{/gist_id}","starred_url":"https://api.github.com/users/hhadian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hhadian/subscriptions","organizations_url":"https://api.github.com/users/hhadian/orgs","repos_url":"https://api.github.com/users/hhadian/repos","events_url":"https://api.github.com/users/hhadian/events{/privacy}","received_events_url":"https://api.github.com/users/hhadian/received_events","type":"User","site_admin":false},"repo":{"id":44244555,"name":"kaldi","full_name":"hhadian/kaldi","owner":{"login":"hhadian","id":15056653,"avatar_url":"https://avatars.githubusercontent.com/u/15056653?v=3","gravatar_id":"","url":"https://api.github.com/users/hhadian","html_url":"https://github.com/hhadian","followers_url":"https://api.github.com/users/hhadian/followers","following_url":"https://api.github.com/users/hhadian/following{/other_user}","gists_url":"https://api.github.com/users/hhadian/gists{/gist_id}","starred_url":"https://api.github.com/users/hhadian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hhadian/subscriptions","organizations_url":"https://api.github.com/users/hhadian/orgs","repos_url":"https://api.github.com/users/hhadian/repos","events_url":"https://api.github.com/users/hhadian/events{/privacy}","received_events_url":"https://api.github.com/users/hhadian/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hhadian/kaldi","description":"This is now the official location of the Kaldi project.","fork":true,"url":"https://api.github.com/repos/hhadian/kaldi","forks_url":"https://api.github.com/repos/hhadian/kaldi/forks","keys_url":"https://api.github.com/repos/hhadian/kaldi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hhadian/kaldi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hhadian/kaldi/teams","hooks_url":"https://api.github.com/repos/hhadian/kaldi/hooks","issue_events_url":"https://api.github.com/repos/hhadian/kaldi/issues/events{/number}","events_url":"https://api.github.com/repos/hhadian/kaldi/events","assignees_url":"https://api.github.com/repos/hhadian/kaldi/assignees{/user}","branches_url":"https://api.github.com/repos/hhadian/kaldi/branches{/branch}","tags_url":"https://api.github.com/repos/hhadian/kaldi/tags","blobs_url":"https://api.github.com/repos/hhadian/kaldi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hhadian/kaldi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hhadian/kaldi/git/refs{/sha}","trees_url":"https://api.github.com/repos/hhadian/kaldi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hhadian/kaldi/statuses/{sha}","languages_url":"https://api.github.com/repos/hhadian/kaldi/languages","stargazers_url":"https://api.github.com/repos/hhadian/kaldi/stargazers","contributors_url":"https://api.github.com/repos/hhadian/kaldi/contributors","subscribers_url":"https://api.github.com/repos/hhadian/kaldi/subscribers","subscription_url":"https://api.github.com/repos/hhadian/kaldi/subscription","commits_url":"https://api.github.com/repos/hhadian/kaldi/commits{/sha}","git_commits_url":"https://api.github.com/repos/hhadian/kaldi/git/commits{/sha}","comments_url":"https://api.github.com/repos/hhadian/kaldi/comments{/number}","issue_comment_url":"https://api.github.com/repos/hhadian/kaldi/issues/comments{/number}","contents_url":"https://api.github.com/repos/hhadian/kaldi/contents/{+path}","compare_url":"https://api.github.com/repos/hhadian/kaldi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hhadian/kaldi/merges","archive_url":"https://api.github.com/repos/hhadian/kaldi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hhadian/kaldi/downloads","issues_url":"https://api.github.com/repos/hhadian/kaldi/issues{/number}","pulls_url":"https://api.github.com/repos/hhadian/kaldi/pulls{/number}","milestones_url":"https://api.github.com/repos/hhadian/kaldi/milestones{/number}","notifications_url":"https://api.github.com/repos/hhadian/kaldi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hhadian/kaldi/labels{/name}","releases_url":"https://api.github.com/repos/hhadian/kaldi/releases{/id}","deployments_url":"https://api.github.com/repos/hhadian/kaldi/deployments","created_at":"2015-10-14T11:55:09Z","updated_at":"2016-01-23T09:33:53Z","pushed_at":"2016-02-14T19:51:08Z","git_url":"git://github.com/hhadian/kaldi.git","ssh_url":"git@github.com:hhadian/kaldi.git","clone_url":"https://github.com/hhadian/kaldi.git","svn_url":"https://github.com/hhadian/kaldi","homepage":"http://kaldi-asr.org","size":75422,"stargazers_count":0,"watchers_count":0,"language":"C++","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":"kaldi-asr:master","ref":"master","sha":"61a551d8f7d4c7cf8ef30d05ab61956cb3999eed","user":{"login":"kaldi-asr","id":11650082,"avatar_url":"https://avatars.githubusercontent.com/u/11650082?v=3","gravatar_id":"","url":"https://api.github.com/users/kaldi-asr","html_url":"https://github.com/kaldi-asr","followers_url":"https://api.github.com/users/kaldi-asr/followers","following_url":"https://api.github.com/users/kaldi-asr/following{/other_user}","gists_url":"https://api.github.com/users/kaldi-asr/gists{/gist_id}","starred_url":"https://api.github.com/users/kaldi-asr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaldi-asr/subscriptions","organizations_url":"https://api.github.com/users/kaldi-asr/orgs","repos_url":"https://api.github.com/users/kaldi-asr/repos","events_url":"https://api.github.com/users/kaldi-asr/events{/privacy}","received_events_url":"https://api.github.com/users/kaldi-asr/received_events","type":"Organization","site_admin":false},"repo":{"id":34275045,"name":"kaldi","full_name":"kaldi-asr/kaldi","owner":{"login":"kaldi-asr","id":11650082,"avatar_url":"https://avatars.githubusercontent.com/u/11650082?v=3","gravatar_id":"","url":"https://api.github.com/users/kaldi-asr","html_url":"https://github.com/kaldi-asr","followers_url":"https://api.github.com/users/kaldi-asr/followers","following_url":"https://api.github.com/users/kaldi-asr/following{/other_user}","gists_url":"https://api.github.com/users/kaldi-asr/gists{/gist_id}","starred_url":"https://api.github.com/users/kaldi-asr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaldi-asr/subscriptions","organizations_url":"https://api.github.com/users/kaldi-asr/orgs","repos_url":"https://api.github.com/users/kaldi-asr/repos","events_url":"https://api.github.com/users/kaldi-asr/events{/privacy}","received_events_url":"https://api.github.com/users/kaldi-asr/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kaldi-asr/kaldi","description":"This is now the official location of the Kaldi project.","fork":false,"url":"https://api.github.com/repos/kaldi-asr/kaldi","forks_url":"https://api.github.com/repos/kaldi-asr/kaldi/forks","keys_url":"https://api.github.com/repos/kaldi-asr/kaldi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kaldi-asr/kaldi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kaldi-asr/kaldi/teams","hooks_url":"https://api.github.com/repos/kaldi-asr/kaldi/hooks","issue_events_url":"https://api.github.com/repos/kaldi-asr/kaldi/issues/events{/number}","events_url":"https://api.github.com/repos/kaldi-asr/kaldi/events","assignees_url":"https://api.github.com/repos/kaldi-asr/kaldi/assignees{/user}","branches_url":"https://api.github.com/repos/kaldi-asr/kaldi/branches{/branch}","tags_url":"https://api.github.com/repos/kaldi-asr/kaldi/tags","blobs_url":"https://api.github.com/repos/kaldi-asr/kaldi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kaldi-asr/kaldi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kaldi-asr/kaldi/git/refs{/sha}","trees_url":"https://api.github.com/repos/kaldi-asr/kaldi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kaldi-asr/kaldi/statuses/{sha}","languages_url":"https://api.github.com/repos/kaldi-asr/kaldi/languages","stargazers_url":"https://api.github.com/repos/kaldi-asr/kaldi/stargazers","contributors_url":"https://api.github.com/repos/kaldi-asr/kaldi/contributors","subscribers_url":"https://api.github.com/repos/kaldi-asr/kaldi/subscribers","subscription_url":"https://api.github.com/repos/kaldi-asr/kaldi/subscription","commits_url":"https://api.github.com/repos/kaldi-asr/kaldi/commits{/sha}","git_commits_url":"https://api.github.com/repos/kaldi-asr/kaldi/git/commits{/sha}","comments_url":"https://api.github.com/repos/kaldi-asr/kaldi/comments{/number}","issue_comment_url":"https://api.github.com/repos/kaldi-asr/kaldi/issues/comments{/number}","contents_url":"https://api.github.com/repos/kaldi-asr/kaldi/contents/{+path}","compare_url":"https://api.github.com/repos/kaldi-asr/kaldi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kaldi-asr/kaldi/merges","archive_url":"https://api.github.com/repos/kaldi-asr/kaldi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kaldi-asr/kaldi/downloads","issues_url":"https://api.github.com/repos/kaldi-asr/kaldi/issues{/number}","pulls_url":"https://api.github.com/repos/kaldi-asr/kaldi/pulls{/number}","milestones_url":"https://api.github.com/repos/kaldi-asr/kaldi/milestones{/number}","notifications_url":"https://api.github.com/repos/kaldi-asr/kaldi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kaldi-asr/kaldi/labels{/name}","releases_url":"https://api.github.com/repos/kaldi-asr/kaldi/releases{/id}","deployments_url":"https://api.github.com/repos/kaldi-asr/kaldi/deployments","created_at":"2015-04-20T17:23:16Z","updated_at":"2016-02-18T07:24:39Z","pushed_at":"2016-02-18T20:39:01Z","git_url":"git://github.com/kaldi-asr/kaldi.git","ssh_url":"git@github.com:kaldi-asr/kaldi.git","clone_url":"https://github.com/kaldi-asr/kaldi.git","svn_url":"https://github.com/kaldi-asr/kaldi","homepage":"http://kaldi-asr.org","size":112142,"stargazers_count":434,"watchers_count":434,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":282,"mirror_url":null,"open_issues_count":30,"forks":282,"open_issues":30,"watchers":434,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/414"},"html":{"href":"https://github.com/kaldi-asr/kaldi/pull/414"},"issue":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/issues/414"},"comments":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/issues/414/comments"},"review_comments":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/414/comments"},"review_comment":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/pulls/414/commits"},"statuses":{"href":"https://api.github.com/repos/kaldi-asr/kaldi/statuses/25f5bdc6095748975ab9c791c563b81c76d6b5be"}}}}