forked from kaldi-asr/kaldi
-
Notifications
You must be signed in to change notification settings - Fork 14
xvector: Objf and Deriv #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,10 +206,11 @@ void Copy(const CuMatrixBase<Real> &src, const CuArray<int32> ©_from_indices | |
| } | ||
| } | ||
|
|
||
| template<typename Real> | ||
| void ComputeXvectorObjfFromScores(const CuMatrixBase<Real> &scores, | ||
| CuMatrixBase<Real> *objf_terms, | ||
| CuMatrixBase<Real> *objf_derivs) { | ||
| void ComputeXvectorObjfFromScores(const CuMatrixBase<BaseFloat> &scores, | ||
| CuMatrixBase<BaseFloat> *objf_terms, | ||
| CuMatrixBase<BaseFloat> *objf_derivs) { | ||
| KALDI_ASSERT(SameDim(*objf_terms, *objf_derivs) | ||
| && SameDim(*objf_terms, scores)); | ||
| #if HAVE_CUDA == 1 | ||
| if (CuDevice::Instantiate().Enabled()) { | ||
| Timer tim; | ||
|
|
@@ -226,8 +227,19 @@ void ComputeXvectorObjfFromScores(const CuMatrixBase<Real> &scores, | |
| } else | ||
| #endif | ||
| { | ||
| // TODO: Add the CPU version. | ||
| KALDI_LOG << "NOT USING CUDA"; | ||
| int32 num_rows = scores.NumRows(); | ||
| BaseFloat K = 1.0 / (num_rows - 2.0); | ||
| for (int32 i = 0; i < num_rows; i++) { | ||
| for (int32 j = i + 1; j < num_rows; j++) { | ||
| if (i + 1 == j && i % 2 == 0) { | ||
| (*objf_terms)(i, j) = log(1.0 + exp(-scores(i, j))); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you'll need to be a little more careful about the possibility of overflow. I suggest using something like |
||
| (*objf_derivs)(i, j) = 1.0 / (1.0 + exp(scores(i, j))); | ||
| } else { | ||
| (*objf_terms)(i, j) = K * log(1.0 + exp(scores(i, j))); | ||
| (*objf_derivs)(i, j) = -K / (1.0 + exp(-scores(i, j))); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -259,16 +271,6 @@ void Randomize(const CuMatrixBase<double> &src, | |
| const CuArray<int32> ©_from_idx, | ||
| CuMatrixBase<double> *tgt); | ||
|
|
||
| template | ||
| void ComputeXvectorObjfFromScores(const CuMatrixBase<float> &scores, | ||
| CuMatrixBase<float> *objf_terms, | ||
| CuMatrixBase<float> *objf_derivs); | ||
| template | ||
| void ComputeXvectorObjfFromScores(const CuMatrixBase<double> &scores, | ||
| CuMatrixBase<double> *objf_terms, | ||
| CuMatrixBase<double> *objf_derivs); | ||
|
|
||
|
|
||
|
|
||
| } //namespace cu | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I were you I'd do at this point
else {
objf_terms[scores_index] = 0.0;
objf_derivs[scores_index] = 0.0;
}
this will save you from having to initialize those to zero (i.e. you can size them with kUndefined)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please don't assume that the stride of objf_deriv is the same as that of objf. It's against the interface.