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

Normalize path_score as confidence score for utterance? #18

Open
chinshr opened this issue May 5, 2015 · 4 comments
Open

Normalize path_score as confidence score for utterance? #18

chinshr opened this issue May 5, 2015 · 4 comments

Comments

@chinshr
Copy link

chinshr commented May 5, 2015

How can I normalize a path_score (like in Pocketsphinx::Decoder::Hypothesis) of an utterance to a relative confidence probability?

@chinshr chinshr changed the title Normalize path_score for an utterance Normalize path_score as confidence score for utterance? May 5, 2015
@nshmyrev
Copy link
Contributor

nshmyrev commented May 5, 2015

You can not do that. Confidence is available in C api with ps_get_prob call which is not used in bindings.

@watsonbox
Copy link
Owner

I've made it possible to get at this value using Pocketsphinx::Decoder::Hypothesis#posterior_prob. Does this help? Is there some additional normalization calculation that would be worth adding to the hypothesis?

@nshmyrev Does calling ps_get_prob every time I call ps_get_hyp have any negative performance implications?

@chinshr
Copy link
Author

chinshr commented May 13, 2015

@watsonbox IMO a step in the right direction, but the posterior probability is logarithmic and needs to be converted to a decimal probability in order to get to a more meaningful confidence score, e.g. .81 = 81% confidence, etc. According to my investigation, I think an approach worth investigating is the following:

...
# Add inside Pocketsphinx::API::Pocketsphinx
typedef :pointer, :logmath
attach_function :ps_get_logmath, [:decoder], :logmath
attach_function :logmath_get_base, [:logmath], FFI::NativeType::FLOAT64
attach_function :logmath_exp, [:logmath, :int], FFI::NativeType::FLOAT64
...
# Pocketsphinx::Decoder
logmath = ps_api.ps_get_logmath(ps_decoder)
logbase = ps_api.logmath_get_base(logmath)
log_prob = ps_api.ps_get_prob(ps_decoder) # -> -9834
dec_prob = ps_api.logmath_exp(logmath, log_prob) # => 0.83111

Something similar needs to happen per word within an utterance:

# Inside Pocketsphinx::Decoder
def words
  ...
  acoustic_score = FFI::MemoryPointer.new(:int32, 1)
  language_score = FFI::MemoryPointer.new(:int32, 1)
  language_backoff = FFI::MemoryPointer.new(:int32, 1)

  ps_api.ps_seg_prob(seg_iter, acoustic_score, language_score, language_backoff)
  ...

Again, these scores are logarithmic and need to be converted before they are meaningful.

joepestro added a commit to joepestro/pocketsphinx-ruby that referenced this issue Jun 26, 2015
This is based on the comment by @chinshr on
watsonbox#18 (comment)
1506602

This conversion makes posterior_prob a usable confidence value between
0 and 1.
@watsonbox
Copy link
Owner

Sorry for the delay! Please let me know if my commit resolves these issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants