Skip to content

Commit

Permalink
fix(nlu): native-NLU values should be in 0..1 interval (resolve #865)
Browse files Browse the repository at this point in the history
  • Loading branch information
epaminond committed Sep 28, 2018
1 parent 0043fee commit 82acb3a
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/functionals/botpress-nlu/src/providers/native.js
Expand Up @@ -144,19 +144,24 @@ export default class NativeProvider extends Provider {

let allScores = zscore(classifications.map(c => parseFloat(c.value)))

allScores = allScores.map((s, i) => {
const delta = Math.abs(s - allScores[i + 1] / s)
if (delta >= threshold) {
return s
}

return (
s -
Math.max(0, allScores[i + 1] || 0) * 0.5 -
Math.max(0, allScores[i + 2] || 0) * 0.75 -
Math.max(0, allScores[i + 3] || 0)
)
})
const SIGMOID_ADJUSTMENT = -3.5
const sigmoid = t => 1 / (1 + Math.pow(Math.E, -(t + SIGMOID_ADJUSTMENT)))

allScores = allScores
.map((s, i) => {
const delta = Math.abs(s - allScores[i + 1] / s)
if (delta >= threshold) {
return s
}

return (
s -
Math.max(0, allScores[i + 1] || 0) * 0.5 -
Math.max(0, allScores[i + 2] || 0) * 0.75 -
Math.max(0, allScores[i + 3] || 0)
)
})
.map(sigmoid)

const intents = _.orderBy(
classifications.map((c, i) => ({
Expand Down

0 comments on commit 82acb3a

Please sign in to comment.