Skip to content
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

Add error training detail #107

Merged
merged 2 commits into from
Feb 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Modify training error details
made nindya committed Jan 8, 2019

Verified

This commit was signed with the committer’s verified signature.
kanadgupta Kanad Gupta
commit effc527865b0617628e992482e58edc4babe3d1d
36 changes: 23 additions & 13 deletions components/nlus/nlu.ts
Original file line number Diff line number Diff line change
@@ -274,24 +274,34 @@ export default class Nlu extends Component {
};
}

const trainResult = await this.helper.toPromise(this.api.nluApi,
const { response: { body } } = await this.helper.toPromise(this.api.nluApi,
this.api.nluApi.projectsProjectIdNlusNluNameTrainPost, projectId, nluName, opts);
const trainResult = body;

// Print result
const count = trainResult.data.count;
const successCount = trainResult.data.rowIds ? trainResult.data.rowIds.length : 0;
const errorCount = trainResult.data.errRows ? trainResult.data.errRows.length : 0;
console.log(`Success: ${successCount} data trained !`);
const count = trainResult.count;
const successCount = trainResult.rowIds ? trainResult.rowIds.length : 0;
if (successCount) {
console.log(`Success: ${successCount} data trained !`);
}

// Write error to file
const errorCount = trainResult.errRows ? trainResult.errRows.length : 0;
if (errorCount) {
const trainingData = opts.file.toString().split("\n");
let errData = "";
for (const i of trainResult.data.errRows) {
errData += trainingData[i] + "\n";
if (options.file) {
const rawData = fs.readFileSync(options.file).toString("utf8");
const trainingData = rawData.split("\n");
let errData = "";
for (const i of trainResult.errRows) {
errData += trainingData[i] + "\n";
}
fs.writeFile(errorFileLog, errData, (err: any) => {
if (err) { throw err; }
console.log(`Error training ${errorCount} data. See details on ${errorFileLog}`);
});
} else if (options.sentence) {
console.log(`Error training data`);
}
fs.writeFile(errorFileLog, errData, (err: any) => {
if (err) { throw err; }
console.log(`Error training ${errorCount} data. See details ${errorFileLog}`);
});
}

} catch (error) {
40 changes: 25 additions & 15 deletions lib/components/nlus/nlu.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.