@@ -23,18 +23,18 @@ import numpy as np
23
23
from ctc_decoder import best_path, beam_search
24
24
25
25
mat = np.array([[0.4 , 0 , 0.6 ], [0.4 , 0 , 0.6 ]])
26
- labels = ' ab'
26
+ chars = ' ab'
27
27
28
- print (f ' Best path: " { best_path(mat, labels )} " ' )
29
- print (f ' Beam search: " { beam_search(mat, labels )} " ' )
28
+ print (f ' Best path: " { best_path(mat, chars )} " ' )
29
+ print (f ' Beam search: " { beam_search(mat, chars )} " ' )
30
30
````
31
31
32
32
The output ` mat ` (numpy array, softmax already applied) of the CTC-trained neural network is expected to have shape TxC
33
33
and is passed as the first argument to the decoders.
34
34
T is the number of time-steps, and C the number of characters (the CTC-blank is the last element).
35
- The labels predicted by the neural network are passed as the ` labels ` string to the decoder.
35
+ The characters that can be predicted by the neural network are passed as the ` chars ` string to the decoder.
36
36
Decoders return the decoded string.
37
- This should output :
37
+ Running the code outputs :
38
38
39
39
````
40
40
Best path: ""
@@ -48,17 +48,17 @@ please have a look at the scripts in the `tests/` folder.
48
48
49
49
### Language model and BK-tree
50
50
51
- Beam search can use a character-level language model.
51
+ Beam search can optionally integrate a character-level language model.
52
52
Text statistics (bigrams) are used by beam search to improve reading accuracy.
53
53
54
54
```` python
55
55
from ctc_decoder import beam_search, LanguageModel
56
56
57
57
# create language model instance from a (large) text
58
- lm = LanguageModel(' this is some text' , labels )
58
+ lm = LanguageModel(' this is some text' , chars )
59
59
60
60
# and use it in the beam search decoder
61
- res = beam_search(mat, labels , lm = lm)
61
+ res = beam_search(mat, chars , lm = lm)
62
62
````
63
63
64
64
The lexicon search decoder computes a first approximation with best path decoding.
@@ -73,7 +73,7 @@ from ctc_decoder import lexicon_search, BKTree
73
73
bk_tree = BKTree([' words' , ' from' , ' a' , ' dictionary' ])
74
74
75
75
# and use the tree in the lexicon search
76
- res = lexicon_search(mat, labels , bk_tree, tolerance = 2 )
76
+ res = lexicon_search(mat, chars , bk_tree, tolerance = 2 )
77
77
````
78
78
79
79
### Usage with deep learning frameworks
@@ -100,7 +100,7 @@ Other decoders, from my experience not really suited for practical purposes,
100
100
but might be used for experiments or research:
101
101
* ` prefix_search ` : prefix search decoder
102
102
* ` token_passing ` : token passing algorithm
103
- * Best path decoder implementation using OpenCL (see ` extras/ ` folder)
103
+ * Best path decoder implementation in OpenCL (see ` extras/ ` folder)
104
104
105
105
[ This paper] ( ./doc/comparison.pdf ) gives suggestions when to use best path decoding, beam search decoding and token passing.
106
106
0 commit comments