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

Add optimized decoder for the deployment of DS2 #139

Merged
merged 48 commits into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
724b0fb
add initial files for deployment
Jun 29, 2017
348d6bb
add deploy.py
Jun 29, 2017
59b4b87
Merge branch 'develop' into ctc_decoder_deploy
Jun 29, 2017
a506198
fix bugs
Jul 4, 2017
903c300
Merge branch 'develop' into ctc_decoder_deploy
Jul 5, 2017
1ca3814
code cleanup for the deployment decoder
Jul 6, 2017
34f98e0
add setup and README for deployment
Jul 6, 2017
ae05535
enable loading language model in multiple format
Jul 10, 2017
4e5b345
change probs' computation into log scale & add best path decoder
Jul 27, 2017
908932f
refine the interface of decoders in swig
Aug 3, 2017
ac3a49c
Delete swig_decoder.py
kuke Aug 3, 2017
9ff48b0
reorganize cpp files
Aug 22, 2017
32047c7
refine wrapper for swig and simplify setup
Aug 22, 2017
f41375b
add the support of parallel beam search decoding in deployment
Aug 23, 2017
a96c650
Refactor scorer and move utility functions to decoder_util.h
pkuyym Aug 23, 2017
3441148
Merge branch 'ctc_decoder_deploy' of https://github.com/kuke/models i…
pkuyym Aug 23, 2017
89c4a96
Make setup.py to support parallel processing.
pkuyym Aug 23, 2017
bbbc988
adapt to the last three commits
Aug 23, 2017
d68732b
convert data structure for prefix from map to trie tree
Aug 24, 2017
955d293
enable finite-state transducer in beam search decoding
Aug 29, 2017
20d13a4
streamline source code
Aug 29, 2017
09f4c6e
remove unused functions in Scorer
Aug 29, 2017
b5c4d83
add min cutoff & top n cutoff
Aug 30, 2017
202a06a
Merge branch 'develop' of https://github.com/PaddlePaddle/models into…
Aug 30, 2017
beb0c07
clean up code & update README for decoder in deployment
Aug 30, 2017
103a6ac
format C++ source code
Sep 6, 2017
efc5d9b
Merge branch 'develop' of https://github.com/PaddlePaddle/models into…
Sep 7, 2017
5a318e9
adapt to the new folder structure of DS2
Sep 8, 2017
f8c7d46
format header includes & update setup info
Sep 8, 2017
e49f505
resolve conflicts in model.py
Sep 8, 2017
d75f27d
Merge branch 'develop' of https://github.com/PaddlePaddle/models into…
Sep 8, 2017
41e9e59
append some comments
Sep 8, 2017
c4bc822
adapt to the new structure
Sep 13, 2017
52a862d
add __init__.py in decoders/swig
Sep 13, 2017
552dd52
move deprecated decoders
Sep 14, 2017
0bda37c
refine by following review comments
Sep 15, 2017
902c35b
append some changes
Sep 15, 2017
bb35363
Merge branch 'develop' of upstream into ctc_decoder_deploy
Sep 16, 2017
15728d0
expose param cutoff_top_n
Sep 16, 2017
e6740af
adjust scorer's init & add logging for scorer & separate long functions
Sep 17, 2017
8c5576d
format varabiables' name & add more comments
Sep 17, 2017
bcc236e
Merge branch 'develop' of upstream into ctc_decoder_deploy
Sep 18, 2017
98d35b9
adjust to pass ci
Sep 18, 2017
d7a9752
specify clang_format to ver3.9
Sep 18, 2017
cc2f91f
disable the make output of libsndfile in setup
Sep 18, 2017
f1cd672
use cd instead of pushd in setup.sh
Sep 18, 2017
cfecaa8
Merge branch 'develop' of upstream into ctc_decoder_deploy
Sep 18, 2017
9db0d25
pass unittest for deprecated decoders
Sep 18, 2017
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
1 change: 1 addition & 0 deletions deep_speech_2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Data augmentation has often been a highly effective technique to boost the deep

Six optional augmentation components are provided to be selected, configured and inserted into the processing pipeline.

### Inference
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to add L191-192?

Copy link
Collaborator Author

@kuke kuke Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mistake. Removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove L179

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

- Volume Perturbation
- Speed Perturbation
- Shifting Perturbation
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def ctc_greedy_decoder(probs_seq, vocabulary):
def ctc_beam_search_decoder(probs_seq,
beam_size,
vocabulary,
blank_id,
cutoff_prob=1.0,
cutoff_top_n=40,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to add cutoff_top_n?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a param used by Mandarin vocabulary cutoff

ext_scoring_func=None,
nproc=False):
"""CTC Beam search decoder.
Expand All @@ -66,8 +66,6 @@ def ctc_beam_search_decoder(probs_seq,
:type beam_size: int
:param vocabulary: Vocabulary list.
:type vocabulary: list
:param blank_id: ID of blank.
:type blank_id: int
:param cutoff_prob: Cutoff probability in pruning,
default 1.0, no pruning.
:type cutoff_prob: float
Expand All @@ -87,9 +85,8 @@ def ctc_beam_search_decoder(probs_seq,
raise ValueError("The shape of prob_seq does not match with the "
"shape of the vocabulary.")

# blank_id check
if not blank_id < len(probs_seq[0]):
raise ValueError("blank_id shouldn't be greater than probs dimension")
# blank_id assign
blank_id = len(vocabulary)

# If the decoder called in the multiprocesses, then use the global scorer
# instantiated in ctc_beam_search_decoder_batch().
Expand All @@ -114,14 +111,15 @@ def ctc_beam_search_decoder(probs_seq,
prob_idx = list(enumerate(probs_seq[time_step]))
cutoff_len = len(prob_idx)
#If pruning is enabled
if cutoff_prob < 1.0:
if cutoff_prob < 1.0 or cutoff_top_n < cutoff_len:
prob_idx = sorted(prob_idx, key=lambda asd: asd[1], reverse=True)
cutoff_len, cum_prob = 0, 0.0
for i in xrange(len(prob_idx)):
cum_prob += prob_idx[i][1]
cutoff_len += 1
if cum_prob >= cutoff_prob:
break
cutoff_len = min(cutoff_top_n, cutoff_top_n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could move cutoff_len into for loop as a stop condition like if (cum_prob >= cutoff_prob or cutoff_len >= threshold) break.
I think min(cutoff_top_n, cutoff_top_n) should be a typo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It is not necessary.
  2. Corrected

prob_idx = prob_idx[0:cutoff_len]

for l in prefix_set_prev:
Expand Down Expand Up @@ -191,9 +189,9 @@ def ctc_beam_search_decoder(probs_seq,
def ctc_beam_search_decoder_batch(probs_split,
beam_size,
vocabulary,
blank_id,
num_processes,
cutoff_prob=1.0,
cutoff_top_n=40,
ext_scoring_func=None):
"""CTC beam search decoder using multiple processes.

Expand All @@ -204,8 +202,6 @@ def ctc_beam_search_decoder_batch(probs_split,
:type beam_size: int
:param vocabulary: Vocabulary list.
:type vocabulary: list
:param blank_id: ID of blank.
:type blank_id: int
:param num_processes: Number of parallel processes.
:type num_processes: int
:param cutoff_prob: Cutoff probability in pruning,
Expand All @@ -232,8 +228,8 @@ def ctc_beam_search_decoder_batch(probs_split,
pool = multiprocessing.Pool(processes=num_processes)
results = []
for i, probs_list in enumerate(probs_split):
args = (probs_list, beam_size, vocabulary, blank_id, cutoff_prob, None,
nproc)
args = (probs_list, beam_size, vocabulary, blank_id, cutoff_prob,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can comment more to clarify why using global ext_nproc_scorer instead of passing ext_nproc_scorer to ctc_beam_search_decoder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would append the comment in later pr.

cutoff_top_n, None, nproc)
results.append(pool.apply_async(ctc_beam_search_decoder, args))

pool.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np


class LmScorer(object):
class Scorer(object):
"""External scorer to evaluate a prefix or whole sentence in
beam search decoding, including the score from n-gram language
model and word count.
Expand Down
Empty file.
Loading