辞書と言語モデル (LM) を備えたコネクショニスト時間分類 (CTC) デコーダー。
pip install .
tests/
に移動し、 pytest
実行して、インストールが機能したかどうかを確認します次のおもちゃの例は、ワード ビーム検索の使用方法を示しています。仮説モデル (テキスト認識モデルなど) は、「a」、「b」、「」 (空白) という 3 つの異なる文字を認識できます。このおもちゃの例の単語には、文字 "a" と "b" を含めることができます (ただし、単語の区切り文字である " " は含めることができません)。言語モデルは、「a」と「ba」の 2 つの単語のみを含むテキスト コーパスからトレーニングされます。
このコード スニペットでは、ワード ビーム検索のインスタンスが作成され、TxBx(C+1) 形状の numpy 配列がデコードされます。
import numpy as np
from word_beam_search import WordBeamSearch
corpus = 'a ba' # two words "a" and "ba", separated by whitespace
chars = 'ab ' # the characters that can be recognized (in this order)
word_chars = 'ab' # characters that form words
# RNN output
# 3 time-steps and 4 characters per time time ("a", "b", " ", CTC-blank)
mat = np . array ([[[ 0.9 , 0.1 , 0.0 , 0.0 ]],
[[ 0.0 , 0.0 , 0.0 , 1.0 ]],
[[ 0.6 , 0.4 , 0.0 , 0.0 ]]])
# initialize word beam search (only do this once in your code)
wbs = WordBeamSearch ( 25 , 'Words' , 0.0 , corpus . encode ( 'utf8' ), chars . encode ( 'utf8' ), word_chars . encode ( 'utf8' ))
# compute label string
label_str = wbs . compute ( mat )
デコーダは、各バッチ要素のデコードされたラベル文字列を含むリストを返します。最終的に文字列を取得するには、各ラベルを対応する文字にマップします。
char_str = [] # decoded texts for batch
for curr_label_str in label_str :
s = '' . join ([ chars [ label ] for label in curr_label_str ])
char_str . append ( s )
例:
tests/test_word_beam_search.py
にあります。WordBeamSearch
クラスのコンストラクターのパラメーター:
0<len(wordChars)<len(chars)
。単一の単語のみを検出する必要がある場合、区切り文字は必要ないため、2 つのパラメータが等しくてもよい: 0<len(wordChars)<=len(chars)
WordBeamSearch.compute
メソッドへの入力:
ワード ビーム サーチは、CTC デコード アルゴリズムです。手書きテキスト認識や自動音声認識などのシーケンス認識タスクに使用されます。
ワードビーム検索の 4 つの主なプロパティは次のとおりです。
次のサンプルは、ワード ビーム検索の典型的な使用例と、5 つの異なるデコーダーによって得られる結果を示しています。ベスト パス デコーディングとバニラ ビーム サーチは、これらのデコーダーが光学モデルのノイズの多い出力のみを使用するため、単語を間違えます。文字レベルの LM によるバニラ ビーム検索を拡張すると、可能性の高い文字シーケンスのみが許可されるため、結果が向上します。トークン パッシングでは辞書と単語レベルの LM が使用されるため、すべての単語が正しく取得されます。ただし、数字などの任意の文字列は認識できません。単語ビーム検索は、辞書を使用して単語を認識できますが、単語以外の文字も正確に識別できます。
詳細情報:
extras/prototype/
extras/tf/
研究活動でワードビーム検索を使用している場合は、次の論文を引用してください。
@inproceedings{scheidl2018wordbeamsearch,
title = {Word Beam Search: A Connectionist Temporal Classification Decoding Algorithm},
author = {Scheidl, H. and Fiel, S. and Sablatnig, R.},
booktitle = {16th International Conference on Frontiers in Handwriting Recognition},
pages = {253--258},
year = {2018},
organization = {IEEE}
}