Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove normalization of confidence scores in intent classification #782

Merged
merged 2 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ All notable changes to this project will be documented in this file.
- Improved failed linking error message after download of resources [#774](https://github.com/snipsco/snips-nlu/pull/774)
- Improve handling of ambiguous utterances in DeterministicIntentParser [#773](https://github.com/snipsco/snips-nlu/pull/773)

### Changed
- Remove normalization of confidence scores in intent classification [#782](https://github.com/snipsco/snips-nlu/pull/782)

### Fixed
- Fixed a crash due to missing resources when refitting the `CRFSlotFiller` [#771](https://github.com/snipsco/snips-nlu/pull/771)
- Fixed issue with egg fragments in download cli [#769](https://github.com/snipsco/snips-nlu/pull/769)
Expand Down
19 changes: 3 additions & 16 deletions snips_nlu/intent_classifier/log_reg_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _get_intents(self, text, intents_filter):
# pylint: disable=C0103
X = self.featurizer.transform([text_to_utterance(text)])
# pylint: enable=C0103
proba_vec = self._predict_proba(X, intents_filter=intents_filter)
proba_vec = self._predict_proba(X)
logger.debug(
"%s", DifferedLoggingMessage(self.log_activation_weights, text, X))
results = [
Expand All @@ -163,30 +163,17 @@ def _get_intents(self, text, intents_filter):

return sorted(results, key=lambda res: -res[RES_PROBA])

def _predict_proba(self, X, intents_filter): # pylint: disable=C0103
def _predict_proba(self, X): # pylint: disable=C0103
self.classifier._check_proba() # pylint: disable=W0212

filtered_out_indexes = None
if intents_filter is not None:
filtered_out_indexes = [
i for i, intent in enumerate(self.intent_list)
if intent not in intents_filter and intent is not None]

prob = self.classifier.decision_function(X)
prob *= -1
np.exp(prob, prob)
prob += 1
np.reciprocal(prob, prob)
if prob.ndim == 1:
return np.vstack([1 - prob, prob]).T
else:
if filtered_out_indexes: # not None and not empty
prob[:, filtered_out_indexes] = 0.
# OvR normalization, like LibLinear's predict_probability
prob /= prob.sum(axis=1).reshape((prob.shape[0], -1))
# We do not normalize when there is no intents filter, to keep the
# probabilities calibrated
return prob
return prob

@check_persisted_path
def persist(self, path):
Expand Down