зеркало из https://github.com/mozilla/kaldi.git
sandbox/language_id: some changed defaults.
git-svn-id: https://svn.code.sf.net/p/kaldi/code/sandbox/language_id@3687 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
This commit is contained in:
Родитель
8728d35d9a
Коммит
e5189ebb81
|
@ -1,3 +1,3 @@
|
||||||
--max-steps=10
|
--max-steps=20
|
||||||
--normalizer=0.002
|
--normalizer=0.002
|
||||||
--verbose=2
|
--verbose=2
|
||||||
|
|
|
@ -132,16 +132,17 @@ BaseFloat LogisticRegression::DoStep(const Matrix<BaseFloat> &xs,
|
||||||
return objf;
|
return objf;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseFloat LogisticRegression::GetObjfAndGrad(const Matrix<BaseFloat> &xs,
|
BaseFloat LogisticRegression::GetObjfAndGrad(
|
||||||
const std::vector<int32> &ys, const Matrix<BaseFloat> &xw,
|
const Matrix<BaseFloat> &xs,
|
||||||
Matrix<BaseFloat> *grad, BaseFloat normalizer) {
|
const std::vector<int32> &ys, const Matrix<BaseFloat> &xw,
|
||||||
BaseFloat objf = 0.0;
|
Matrix<BaseFloat> *grad, BaseFloat normalizer) {
|
||||||
|
BaseFloat raw_objf = 0.0;
|
||||||
// For each training example class
|
// For each training example class
|
||||||
for (int32 i = 0; i < ys.size(); i++) {
|
for (int32 i = 0; i < ys.size(); i++) {
|
||||||
Vector<BaseFloat> row(xw.NumCols());
|
Vector<BaseFloat> row(xw.NumCols());
|
||||||
row.CopyFromVec(xw.Row(i));
|
row.CopyFromVec(xw.Row(i));
|
||||||
row.ApplySoftMax();
|
row.ApplySoftMax();
|
||||||
objf += std::log(std::max<BaseFloat>(row(ys[i]), 1.0e-20));
|
raw_objf += std::log(std::max<BaseFloat>(row(ys[i]), 1.0e-20));
|
||||||
SubVector<BaseFloat> x = xs.Row(i);
|
SubVector<BaseFloat> x = xs.Row(i);
|
||||||
// Iterate over the class labels
|
// Iterate over the class labels
|
||||||
for (int32 k = 0; k < weights_.NumRows(); k++) {
|
for (int32 k = 0; k < weights_.NumRows(); k++) {
|
||||||
|
@ -157,9 +158,11 @@ BaseFloat LogisticRegression::GetObjfAndGrad(const Matrix<BaseFloat> &xs,
|
||||||
// Scale and add regularization term.
|
// Scale and add regularization term.
|
||||||
grad->Scale(1.0/ys.size());
|
grad->Scale(1.0/ys.size());
|
||||||
grad->AddMat(-1.0 * normalizer, weights_);
|
grad->AddMat(-1.0 * normalizer, weights_);
|
||||||
objf /= ys.size();
|
raw_objf /= ys.size();
|
||||||
objf -= 0.5 * normalizer * TraceMatMat(weights_, weights_, kTrans);
|
BaseFloat regularizer = - 0.5 * normalizer * TraceMatMat(weights_, weights_, kTrans);
|
||||||
return objf;
|
KALDI_VLOG(2) << "Objf is " << raw_objf << " + " << regularizer
|
||||||
|
<< " = " << (raw_objf + regularizer);
|
||||||
|
return raw_objf + regularizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogisticRegression::SetWeights(const Matrix<BaseFloat> &weights) {
|
void LogisticRegression::SetWeights(const Matrix<BaseFloat> &weights) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace kaldi {
|
||||||
struct LogisticRegressionConfig {
|
struct LogisticRegressionConfig {
|
||||||
int32 max_steps;
|
int32 max_steps;
|
||||||
double normalizer;
|
double normalizer;
|
||||||
LogisticRegressionConfig(): max_steps(20), normalizer(0.01) { }
|
LogisticRegressionConfig(): max_steps(20), normalizer(0.002) { }
|
||||||
void Register(OptionsItf *po) {
|
void Register(OptionsItf *po) {
|
||||||
po->Register("max-steps", &max_steps,
|
po->Register("max-steps", &max_steps,
|
||||||
"Maximum steps in L-BFGS.");
|
"Maximum steps in L-BFGS.");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче