Git Product home page Git Product logo

fast-ctc-decode's Introduction

fast-ctc-decode

test-fast-ctc-decode PyPI version

Blitzing fast CTC decoding library.

$ pip install fast-ctc-decode
$ npm i @nanopore/fast-ctc-decode

Usage

Python

>>> from fast_ctc_decode import beam_search, viterbi_search
>>>
>>> alphabet = "NACGT"
>>> posteriors = np.random.rand(100, len(alphabet)).astype(np.float32)
>>>
>>> seq, path = viterbi_search(posteriors, alphabet)
>>> seq
'ACACTCGCAGCGCGATACGACTGATCGAGATATACTCAGTGTACACAGT'
>>>
>>> seq, path = beam_search(posteriors, alphabet, beam_size=5, beam_cut_threshold=0.1)
>>> seq
'ACACTCGCAGCGCGATACGACTGATCGAGATATACTCAGTGTACACAGT'

Node / Web

import init, { beam_search, viterbi_search } from 'fast-ctc';

const floatArr = [0.0, 0.4, 0.6, 0.0, 0.3, 0.7, 0.3, 0.3, 0.4, 0.4, 0.3, 0.3, 0.4, 0.3, 0.3, 0.3, 0.3, 0.4, 0.1, 0.4, 0.5, 0.1, 0.5, 0.4, 0.8, 0.1, 0.1, 0.1, 0.1, 0.8];
const alphabet = ["N","A","G"];
const beamSize = 5;
const beamCutThreshold = Number(0.0).toPrecision(2);
const collapseRepeats = true;
const shape = [10, 3];
const string = false;
const qBias = Number(0.0).toPrecision(2);
const qScale = Number(1.0).toPrecision(2);

// On web, note the base path will be your public folder
init('fast_ctc_decode_wasm_bg.wasm');

const viterbisearch = await beam_search(floatArr, alphabet, string, qScale, qBias, collapseRepeats, shape);

const beamsearch = await beam_search(floatArr, alphabet, beamSize, beamCutThreshold, collapseRepeats, shape);

console.log(viterbisearch); // GGAG
console.log(beamsearch); // GAGAG

Benchmark

Implementation Time (s) URL
Viterbi (Rust) 0.0003 nanoporetech/fast-ctc-decode
Viterbi (Python) 0.0022
Beam Search (Rust) 0.0033 nanoporetech/fast-ctc-decode
Beam Search (C++) 0.1034 parlance/ctcdecode
Beam Search (Python) 3.3337 githubharald/CTCDecoder

Developer Quickstart

Python

$ git clone https://github.com/nanoporetech/fast-ctc-decode.git
$ cd fast-ctc-decode
$ pip install --user maturin
$ make test

JavaScript / Node

npm i
npm test

Note: You'll need a recent rust compiler on your path to build the project.

By default, a fast (and less accurate) version of exponentiation is used for the 2D search. This can be disabled by passing --cargo-extra-args="--no-default-features" to maturin, which provides more accurate calculations but makes the 2D search take about twice as long.

Credits

The original 1D beam search implementation was developed by @usamec for deepnano-blitz.

The 2D beam search is based on @jordisr and @ihh work in their pair consensus decoding paper.

Licence and Copyright

(c) 2019 Oxford Nanopore Technologies Ltd.

fast-ctc-decode is distributed under the terms of the MIT License. If a copy of the License was not distributed with this file, You can obtain one at https://github.com/nanoporetech/fast-ctc-decode/

Research Release

Research releases are provided as technology demonstrators to provide early access to features or stimulate Community development of tools. Support for this software will be minimal and is only provided directly by the developers. Feature requests, improvements, and discussions are welcome and can be implemented by forking and pull requests. However much as we would like to rectify every issue and piece of feedback users may have, the developers may have limited resource for support of this software. Research releases may be unstable and subject to rapid iteration by Oxford Nanopore Technologies.

fast-ctc-decode's People

Contributors

amerry avatar anddigital-jh avatar davnn avatar dependabot[bot] avatar iiseymour avatar tadas-subonis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fast-ctc-decode's Issues

Unable to compile code

I could not get the package to build using the latest versions of Rust and maturin.

Here is the build log:

   Compiling autocfg v1.0.1
   Compiling proc-macro2 v1.0.27
   Compiling unicode-xid v0.2.2
   Compiling libc v0.2.98
   Compiling syn v1.0.73
   Compiling cfg-if v1.0.0
   Compiling proc-macro-hack v0.5.19
   Compiling rawpointer v0.2.1
   Compiling getrandom v0.1.16
   Compiling inventory v0.1.10
   Compiling unindent v0.1.7
   Compiling smallvec v1.6.1
   Compiling scopeguard v1.1.0
   Compiling ppv-lite86 v0.2.10
   Compiling ndarray v0.14.0
   Compiling pyo3 v0.13.2
   Compiling blas-src v0.6.1
   Compiling either v1.6.1
   Compiling hashbrown v0.11.2
   Compiling cfg-if v0.1.10
   Compiling fast_ctc_decode v0.3.0 (/home/noam/code/fast-ctc-decode)
   Compiling instant v0.1.10
   Compiling matrixmultiply v0.3.1
   Compiling matrixmultiply v0.2.4
   Compiling lock_api v0.4.4
   Compiling num-traits v0.2.14
   Compiling num-integer v0.1.44
   Compiling indexmap v1.7.0
   Compiling itertools v0.9.0
   Compiling quote v1.0.9
   Compiling parking_lot_core v0.8.3
   Compiling cblas-sys v0.1.4
   Compiling rand_core v0.5.1
   Compiling parking_lot v0.11.1
   Compiling rand_chacha v0.2.2
   Compiling num-complex v0.3.1
   Compiling num-complex v0.4.0
   Compiling noisy_float v0.1.15
   Compiling paste-impl v0.1.18
   Compiling rand v0.7.3
   Compiling ndarray v0.15.3
   Compiling paste v0.1.18
   Compiling ndarray-stats v0.4.0
   Compiling pyo3-macros-backend v0.13.2
   Compiling ghost v0.1.2
   Compiling indoc-impl v0.3.6
   Compiling ctor v0.1.20
   Compiling inventory-impl v0.1.10
   Compiling pyo3-macros v0.13.2
   Compiling indoc v0.3.6
   Compiling numpy v0.13.2
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> src/lib.rs:1:1
  |
1 | #![feature(static_nobundle)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> src/lib.rs:2:1
  |
2 | #![feature(test)] // benchmarking
  | ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> src/lib.rs:106:21
    |
106 |                     &network_output,
    |                     ^^^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 2]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 2]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:143:21
    |
143 |                     &network_output,
    |                     ^^^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 3]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 3]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:144:21
    |
144 |                     &init_state,
    |                     ^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 1]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 1]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:179:21
    |
179 |                     &network_output,
    |                     ^^^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 3]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 3]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:180:21
    |
180 |                     &init_state,
    |                     ^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 1]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 1]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:255:21
    |
255 |                     &network_output,
    |                     ^^^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 2]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 2]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: `match` arms have incompatible types
   --> src/lib.rs:364:21
    |
356 |               let envelope_view = match envelope {
    |  _________________________________-
357 | |                 Some(env) => env.as_array(),
    | |                              -------------- this is found to be of type `ndarray::ArrayBase<ndarray::ViewRepr<&usize>, ndarray::dimension::dim::Dim<[usize; 2]>>`
358 | |                 None => {
359 | |                     default_envelope =
...   |
364 | |                     default_envelope.view()
    | |                     ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `ndarray::ArrayBase`, found struct `ArrayBase`
365 | |                 }
366 | |             };
    | |_____________- `match` arms have incompatible types
    |
    = note: expected type `ndarray::ArrayBase<ndarray::ViewRepr<&usize>, ndarray::dimension::dim::Dim<[usize; 2]>>`
	     found struct `ArrayBase<ViewRepr<&usize>, Dim<[usize; 2]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:373:21
    |
373 |                     &network_output_1,
    |                     ^^^^^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 2]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 2]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:374:21
    |
374 |                     &network_output_2,
    |                     ^^^^^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 2]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 2]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: `match` arms have incompatible types
   --> src/lib.rs:448:21
    |
440 |               let envelope_view = match envelope {
    |  _________________________________-
441 | |                 Some(env) => env.as_array(),
    | |                              -------------- this is found to be of type `ndarray::ArrayBase<ndarray::ViewRepr<&usize>, ndarray::dimension::dim::Dim<[usize; 2]>>`
442 | |                 None => {
443 | |                     default_envelope =
...   |
448 | |                     default_envelope.view()
    | |                     ^^^^^^^^^^^^^^^^^^^^^^^ expected struct `ndarray::ArrayBase`, found struct `ArrayBase`
449 | |                 }
450 | |             };
    | |_____________- `match` arms have incompatible types
    |
    = note: expected type `ndarray::ArrayBase<ndarray::ViewRepr<&usize>, ndarray::dimension::dim::Dim<[usize; 2]>>`
	     found struct `ArrayBase<ViewRepr<&usize>, Dim<[usize; 2]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:459:21
    |
459 |                     &network_output_1,
    |                     ^^^^^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 3]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 3]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:460:21
    |
460 |                     &init_state_1,
    |                     ^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 1]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 1]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:461:21
    |
461 |                     &network_output_2,
    |                     ^^^^^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 3]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 3]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error[E0308]: mismatched types
   --> src/lib.rs:462:21
    |
462 |                     &init_state_2,
    |                     ^^^^^^^^^^^^^ expected struct `ArrayBase`, found struct `ndarray::ArrayBase`
    |
    = note: expected reference `&ArrayBase<_, Dim<[usize; 1]>>`
	       found reference `&ndarray::ArrayBase<ndarray::ViewRepr<&f32>, ndarray::dimension::dim::Dim<[usize; 1]>>`
    = note: perhaps two different versions of crate `ndarray` are being used?

error: aborting due to 16 previous errors

Some errors have detailed explanations: E0308, E0554.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `fast_ctc_decode`

To learn more, run the command again with --verbose.

RuntimeError: Ran out of search space (beam_cut_threshold too high)

My input is an 2D array(512×6)which looks like:
[[-6.14964533e+00 -4.50301647e+00 -1.26775427e+01 -1.32243423e+01
-1.33028030e-02 -1.57202511e+01]
[-6.09671593e-01 -9.38526917e+00 -1.16878452e+01 -1.45465679e+01
-7.84433842e-01 -1.82103691e+01]
[-2.47001648e-04 -1.24834585e+01 -1.32059736e+01 -1.49093075e+01
-8.33115005e+00 -2.08991814e+01]
...
but I encountered a runtime error when I ran beam_search:
seq, _ = beam_search(probs_row, base_list, beam_size=3, beam_cut_threshold=0.1)
RuntimeError: Ran out of search space (beam_cut_threshold too high)
How to solve the problem?

beam search call result in Killed

Background

There is a single sample which caused a Killed situation when I was using the library with docker. The base image I used is python:3.8. I couldn't find the cause of it. Would you mind have a look and help? Thank you

The data
This the posterior array saved as json after calling the tolist method

A Docker Container with the posterior.json and dependencies installed

docker pull powatsoi/fast-ctc-decode-issue:latest

Steps to reproduce

docker run -it --rm powatsoi/fast-ctc-decode-issue:latest

root@9ce0d0f66ba2:/# ipython
Python 3.8.8 (default, Mar 27 2021, 18:26:41) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import json

In [2]: import numpy as np

In [3]: from fast_ctc_decode import beam_search

In [4]: beam_search(np.asarray(json.load(open("posterior.json")), dtype=np.float32), "a" * 7997)
Killed

pip list output:

root@9ce0d0f66ba2:/# pip list
Package           Version
----------------- -------
backcall          0.2.0
decorator         5.0.9
fast-ctc-decode   0.3.0
ipython           7.25.0
ipython-genutils  0.2.0
jedi              0.18.0
matplotlib-inline 0.1.2
numpy             1.21.1
parso             0.8.2
pexpect           4.8.0
pickleshare       0.7.5
pip               21.0.1
prompt-toolkit    3.0.19
ptyprocess        0.7.0
Pygments          2.9.0
setuptools        54.2.0
traitlets         5.0.5
wcwidth           0.2.5
wheel             0.36.2

blank symbol

Hello!
Do I need to add a blank character to the alphabet for a real problem or should I manually remove blank characters later?

slow running in arm

I install the fast-ctc-decode in arm environment through:
$ git clone https://github.com/nanoporetech/fast-ctc-decode.git
$ cd fast-ctc-decode
$ pip install --user maturin
$ make test

and the rust version: rustc 1.46.0-nightly (0ca7f74db 2020-06-29);
maturin version: maturin 0.8.2

I run the folling code in arm and x86 environment. And the results show beam search and vitebi search in arm are much slower than those in x86, more than 40 times for beam search and 60 times for vitebi search.

from time import time

import numpy as np
from fast_ctc_decode import beam_search, viterbi_search

l = 1000
alphabet = "NACGT"
loop = 1000

posteriors = np.random.rand(l, len(alphabet)).astype(np.float32)

start_time = time()
for lp in range(loop):
    seq, path = beam_search(posteriors, alphabet, beam_size=5, beam_cut_threshold=0.1)
end_time = time()
cost = end_time - start_time

print(f"beam search length of {l} for  {loop} times cost: {cost}s, mean: {cost/loop}")

start_time = time()
for lp in range(loop):
    seq, path = viterbi_search(posteriors, alphabet)
end_time = time()
cost = end_time - start_time

print(f"viterbi search length of {l} for  {loop} times cost: {cost}s, mean: {cost/loop}")

The results:
Arm:
beam search length of 1000 for 1000 times cost: 63.2727427482605s, mean: 0.0632727427482605
viterbi search length of 1000 for 1000 times cost: 2.8806848526000977s, mean: 0.002880684852600098

X86:
beam search length of 1000 for 1000 times cost: 1.4413361549377441s, mean: 0.0014413361549377442
viterbi search length of 1000 for 1000 times cost: 0.04563140869140625s, mean: 4.563140869140625e-05

So why is so slow in arm? How to optimize the speed in arm? And do you have a compiled arm package? Thanks a lot.

How to use on windows?

It seems there are only installation packages for Linux and mac, can you provide windows version?

crf_beam_search

I notice there is a fuction named crf_beam_search, but I found no helping infomation or discribtion of this function, will there be any use demo of it? Is it for bonito crf model decode? I found it different of the input variables between the beamsearch in the kbeam package and here the crf_beam_search

crf_beam_search:
pub fn crf_beam_search<D: Data<Elem = f32>>(
network_output: &ArrayBase<D, Ix3>,
init_state: &ArrayBase<D, Ix1>,
alphabet: &[String],
beam_size: usize,
beam_cut_threshold: f32,
)

kbeam beamsearch:
path, _ = beamsearch(
scores['scores'], scale, seqdist.n_base, beamsize,
guide=scores['betas'], beam_cut=beamcut
)

Install on jetson tx2

Hi guys

I am installing openvino on nvidia jetson tx2 (arm64, ubuntu 18.04) and it is failing when trying to install fast-ctc-decode from pypi.

Pip3 command fails (my python version is 3..6.9) saying no available versions are found. Same issue when trying to install a specific version.

I had a similar issue with rawpy and ended up installing it from source but I do not know how to install fast-ctc-decode from source.

Would someone be able to help?

Thank you!

version published to crates.io

Can there be a version published for use within Rust code, as well as existing python and wasm versions? Seems a bit unfortunate some colleagues can use this in their python projects but I need to fork it to use it in Rust to remove the crate-type cdylib etc.

Compilation error arm64

Hello, I'm trying to build from source (v. 0.3.2), but gettng "The bindings crate pyo3 was not found in the dependencies list" after make build.

  • Ubuntu 20.04
  • rustc 1.62.1
  • pyo3 0.16.5
  • maturin 0.13.1
  • python 3.8

Cargo and pyproject are original from the git

Incorrect path returned for repeated labels

The approach for returning the sequence path in 5e5d9ff fails for repeated labels when the probability for a label in the run extends more than a single time step.

For example, the expected sequence AAA where each A has two contributions {5:6, 12:13, 17:18} should result in the path [6, 13, 18] but produces [13, 17, 18].

   N  A   C   G   T
[[0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]]

The effect is the path is accumulated to the right. In this example if each A has three contributions {4:6, 11:13, 16:18} the resulting path is [16, 17, 18].

If there is a single contribution for each base in the run then the correct path[6, 13, 18] is returned.

   N  A   C   G   T
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]
 [0.  1.  0.  0.  0. ]
 [0.5 0.  0.  0.  0. ]]

Tests for the previous two case have been added in c3d9707.

could I use the last character/label as the blank label?

Dear developer:
fast-ctc-decode expects the first character/label as the blank label. I use tensorflow to train my model and the number_classes - 1 as the blank label, could I use fast-ctc-decode and how ?
best regards
LianLin

The path returned by beam_search pins to the end of the labels

The path returned by beam_search indicates the last data point where the label applies (because the code is traversing the input backwards). It would seem more sensible to indicate the first data point where the label applies.

This requires caution. Currently, the input data

#  N    A    G
[[1.0, 0.0, 0.0], # 0
 [1.0, 0.0, 0.0],
 [0.0, 1.0, 0.0], # 2
 [0.0, 1.0, 0.0],
 [1.0, 0.0, 0.0], # 4
 [1.0, 0.0, 0.0],
 [0.0, 0.0, 1.0], # 6
 [0.0, 0.0, 1.0],
 [1.0, 0.0, 0.0], # 8
 [1.0, 0.0, 0.0]]

produces the sequence "AG" and the path [3, 7]. I would argue it should produce the path [2, 6], but it would be difficult (with the current reverse-traversal) to obtain this path - it would be much easier to generate the path [0, 4], which is also arguably wrong, as blank/stays are assigned to the following label instead of the preceding one.

That said, as far as I can tell, conceptually you can't really assign precise positions to labels unless you calculate both the forward and backward probabilities (and we're only calculating the backward ones), so perhaps it doesn't matter that much for most data.

how to get text score?

what should I do if I want to get the text score?

I don't know what the return path means.

what's the difference between viterbi and beam search?

I found that the viterbi is really fast, but it's accuracy may a little lower than the beam search decoding. so I'm wondering what's the difference between viterbi and beam search ? is there any paper or reference ?

Is there an easy way to get the probability of the best path?

I'm working on an automatic handwriting transcription system, which uses ctc_decoding to get the final prediction. I was able to take advantage of your fantastic and lightning-fast implementation. I might find it useful to get the probability linked to the best path but I'm not very familiar with rust.

Thanks in advance

Can this work as a replacement for parlance/ctcdecode?

I'm having an impossible time installing the parlance one. My implementation has:

        try:
            from ctcdecode import CTCBeamDecoder
        except ImportError:
            raise ImportError("BeamCTCDecoder requires paddledecoder package.")
        self._decoder = CTCBeamDecoder(labels, lm_path, alpha, beta, cutoff_top_n, cutoff_prob, beam_width,
                                       num_processes, blank_index, log_probs_input=True)

But I'm wondering if I can drop this in instead?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.