Skip to content

Commit

Permalink
update test - loss fn
Browse files Browse the repository at this point in the history
  • Loading branch information
albho committed Feb 2, 2024
1 parent 4467884 commit 94f4db7
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions binding/nodejs/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ import { getSystemLibraryPath } from '../src/platforms';
import { getAudioFile } from './test_utils';

const WAV_PATH = 'sample.wav';
const EXPECTED_VOICE_PROBABILITY_SCORES = [
0.00350041501224041, 0.017226237803697586, 0.022328782826662064,
0.024964014068245888, 0.017900168895721436, 0.028114058077335358,
0.1203354075551033, 0.11426965147256851, 0.0626743733882904,
0.028843538835644722, 0.9569169282913208, 0.9879112839698792,
0.9837538003921509, 0.9286680221557617, 0.9479621648788452,
0.9499486684799194, 0.9634374976158142, 0.9786311388015747,
0.9836912155151367, 0.9827406406402588, 0.9849273562431335,
0.9784052968025208, 0.9812748432159424, 0.9742639660835266,
0.9664738178253174, 0.9518184661865234, 0.9407353401184082, 0.814495861530304,
0.118283212184906, 0.01206541433930397, 0.014447852969169617,
0.015830140560865402, 0.012734980322420597, 0.01062167901545763,
0.010828903876245022, 0.00736008258536458, 0.014871003106236458,
0.00925009697675705, 0.009878940880298615, 0.008195844478905201,
0.008736720308661461, 0.01084984466433525,
];

const libraryPath = getSystemLibraryPath();

Expand Down Expand Up @@ -76,14 +60,24 @@ describe('successful processes', () => {
it('testing process', () => {
let cobraEngine = new Cobra(ACCESS_KEY);

let res = cobraProcessWaveFile(cobraEngine, WAV_PATH);
let probs = cobraProcessWaveFile(cobraEngine, WAV_PATH);
const labels = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];

res.forEach((voiceProbabilityScore, i) => {
expect(voiceProbabilityScore).toBeCloseTo(
EXPECTED_VOICE_PROBABILITY_SCORES[i],
3
);
});
expect(labels.length).toBe(probs.length);

let error = 0;

for (let i = 0; i < probs.length; i++) {
error -=
labels[i] * Math.log(probs[i]) +
(1 - labels[i]) * Math.log(1 - probs[i]);
}

error /= probs.length;
expect(error).toBeLessThan(0.1);

cobraEngine.release();
});
Expand Down

0 comments on commit 94f4db7

Please sign in to comment.