Merge pull request #2358 from mozilla/rename-probability-confidence

Rename metadata probability field to confidence
This commit is contained in:
Reuben Morais 2019-09-23 12:41:51 +02:00 committed by GitHub
commit 7995e4230b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 18 deletions

View File

@ -350,7 +350,7 @@ JSONOutput(Metadata* metadata)
std::vector<meta_word> words = WordsFromMetadata(metadata); std::vector<meta_word> words = WordsFromMetadata(metadata);
std::ostringstream out_string; std::ostringstream out_string;
out_string << R"({"metadata":{"confidence":)" << metadata->probability << R"(},"words":[)"; out_string << R"({"metadata":{"confidence":)" << metadata->confidence << R"(},"words":[)";
for (int i = 0; i < words.size(); i++) { for (int i = 0; i < words.size(); i++) {
meta_word w = words[i]; meta_word w = words[i];

View File

@ -51,14 +51,14 @@ def ctc_beam_search_decoder(probs_seq,
:param scorer: External scorer for partially decoded sentence, e.g. word :param scorer: External scorer for partially decoded sentence, e.g. word
count or language model. count or language model.
:type scorer: Scorer :type scorer: Scorer
:return: List of tuples of log probability and sentence as decoding :return: List of tuples of confidence and sentence as decoding
results, in descending order of the probability. results, in descending order of the confidence.
:rtype: list :rtype: list
""" """
beam_results = swigwrapper.ctc_beam_search_decoder( beam_results = swigwrapper.ctc_beam_search_decoder(
probs_seq, alphabet.config_file(), beam_size, cutoff_prob, cutoff_top_n, probs_seq, alphabet.config_file(), beam_size, cutoff_prob, cutoff_top_n,
scorer) scorer)
beam_results = [(res.probability, alphabet.decode(res.tokens)) for res in beam_results] beam_results = [(res.confidence, alphabet.decode(res.tokens)) for res in beam_results]
return beam_results return beam_results
@ -93,15 +93,15 @@ def ctc_beam_search_decoder_batch(probs_seq,
:param scorer: External scorer for partially decoded sentence, e.g. word :param scorer: External scorer for partially decoded sentence, e.g. word
count or language model. count or language model.
:type scorer: Scorer :type scorer: Scorer
:return: List of tuples of log probability and sentence as decoding :return: List of tuples of confidence and sentence as decoding
results, in descending order of the probability. results, in descending order of the confidence.
:rtype: list :rtype: list
""" """
batch_beam_results = swigwrapper.ctc_beam_search_decoder_batch( batch_beam_results = swigwrapper.ctc_beam_search_decoder_batch(
probs_seq, seq_lengths, alphabet.config_file(), beam_size, num_processes, probs_seq, seq_lengths, alphabet.config_file(), beam_size, num_processes,
cutoff_prob, cutoff_top_n, scorer) cutoff_prob, cutoff_top_n, scorer)
batch_beam_results = [ batch_beam_results = [
[(res.probability, alphabet.decode(res.tokens)) for res in beam_results] [(res.confidence, alphabet.decode(res.tokens)) for res in beam_results]
for beam_results in batch_beam_results for beam_results in batch_beam_results
] ]
return batch_beam_results return batch_beam_results

View File

@ -46,7 +46,7 @@ std::vector<Output> get_beam_search_result(
for (size_t i = 0; i < top_paths && i < prefixes.size(); ++i) { for (size_t i = 0; i < top_paths && i < prefixes.size(); ++i) {
Output output; Output output;
prefixes[i]->get_path_vec(output.tokens, output.timesteps); prefixes[i]->get_path_vec(output.tokens, output.timesteps);
output.probability = -prefixes[i]->approx_ctc; output.confidence = -prefixes[i]->approx_ctc;
output_vecs.push_back(output); output_vecs.push_back(output);
} }

View File

@ -7,7 +7,7 @@
* for each token in the beam search output * for each token in the beam search output
*/ */
struct Output { struct Output {
double probability; double confidence;
std::vector<int> tokens; std::vector<int> tokens;
std::vector<int> timesteps; std::vector<int> timesteps;
}; };

View File

@ -30,8 +30,10 @@ typedef struct MetadataItem {
typedef struct Metadata { typedef struct Metadata {
MetadataItem* items; MetadataItem* items;
int num_items; int num_items;
// Approximated probability (confidence value) for this transcription. // Approximated confidence value for this transcription. This is roughly the
double probability; // sum of the acoustic model logit values for each timestep/character that
// contributed to the creation of this transcription.
double confidence;
} Metadata; } Metadata;
enum DeepSpeech_Error_Codes enum DeepSpeech_Error_Codes

View File

@ -36,7 +36,7 @@ namespace DeepSpeechClient.Extensions
var metaData = (Metadata)Marshal.PtrToStructure(intPtr, typeof(Metadata)); var metaData = (Metadata)Marshal.PtrToStructure(intPtr, typeof(Metadata));
managedMetaObject.Items = new Models.MetadataItem[metaData.num_items]; managedMetaObject.Items = new Models.MetadataItem[metaData.num_items];
managedMetaObject.Probability = metaData.probability; managedMetaObject.Confidence = metaData.confidence;
//we need to manually read each item from the native ptr using its size //we need to manually read each item from the native ptr using its size

View File

@ -6,9 +6,9 @@
public class Metadata public class Metadata
{ {
/// <summary> /// <summary>
/// Approximated probability (confidence value) for this transcription. /// Approximated confidence value for this transcription.
/// </summary> /// </summary>
public double Probability { get; set; } public double Confidence { get; set; }
/// <summary> /// <summary>
/// List of metada items containing char, timespet, and time offset. /// List of metada items containing char, timespet, and time offset.
/// </summary> /// </summary>

View File

@ -15,8 +15,8 @@ namespace DeepSpeechClient.Structs
/// </summary> /// </summary>
internal unsafe int num_items; internal unsafe int num_items;
/// <summary> /// <summary>
/// Approximated probability (confidence value) for this transcription. /// Approximated confidence value for this transcription.
/// </summary> /// </summary>
internal unsafe double probability; internal unsafe double confidence;
} }
} }

View File

@ -26,7 +26,7 @@ namespace CSharpExamples
var nl = Environment.NewLine; var nl = Environment.NewLine;
string retval = string retval =
Environment.NewLine + $"Recognized text: {string.Join("", meta?.Items?.Select(x => x.Character))} {nl}" Environment.NewLine + $"Recognized text: {string.Join("", meta?.Items?.Select(x => x.Character))} {nl}"
+ $"Prob: {meta?.Probability} {nl}" + $"Confidence: {meta?.Confidence} {nl}"
+ $"Item count: {meta?.Items?.Length} {nl}" + $"Item count: {meta?.Items?.Length} {nl}"
+ string.Join(nl, meta?.Items?.Select(x => $"Timestep : {x.Timestep} TimeOffset: {x.StartTime} Char: {x.Character}")); + string.Join(nl, meta?.Items?.Select(x => $"Timestep : {x.Timestep} TimeOffset: {x.StartTime} Char: {x.Character}"));
return retval; return retval;

View File

@ -49,7 +49,7 @@ ModelState::decode_metadata(const DecoderState& state)
std::unique_ptr<Metadata> metadata(new Metadata()); std::unique_ptr<Metadata> metadata(new Metadata());
metadata->num_items = out[0].tokens.size(); metadata->num_items = out[0].tokens.size();
metadata->probability = out[0].probability; metadata->confidence = out[0].confidence;
std::unique_ptr<MetadataItem[]> items(new MetadataItem[metadata->num_items]()); std::unique_ptr<MetadataItem[]> items(new MetadataItem[metadata->num_items]());