def testLineExample(): "example which decodes a RNN output of a text line. Taken from IAM dataset. RNN output produced by TensorFlow model." # chars of IAM dataset classes = ' !"#&\'()*+,-./0123456789:;?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' # matrix containing TxC RNN output. C=len(classes)+1 because of blank label. mat = softmax(loadRNNOutput('../data/line/rnnOutput.csv')) # language model: used for token passing (word list) and beam search (char bigrams) lm = LanguageModel.LanguageModel('../data/line/corpus.txt', classes) # decode RNN output with different decoding algorithms gt = 'the fake friend of the family, like the' print('TARGET :', '"' + gt + '"') print('BEST PATH :', '"' + BestPath.ctcBestPath(mat, classes) + '"') print('PREFIX SEARCH :', '"' + PrefixSearch.ctcPrefixSearchHeuristicSplit(mat, classes) + '"') print('BEAM SEARCH :', '"' + BeamSearch.ctcBeamSearch(mat, classes, None) + '"') print('BEAM SEARCH LM:', '"' + BeamSearch.ctcBeamSearch(mat, classes, lm) + '"') print( 'TOKEN :', '"' + TokenPassing.ctcTokenPassing(mat, classes, lm.getWordList()) + '"') print('PROB(TARGET) :', Loss.ctcLabelingProb(mat, gt, classes)) print('LOSS(TARGET) :', Loss.ctcLoss(mat, gt, classes))
def testMiniExample(): "example which shows difference between taking most probable path and most probable labelling. No language model used." classes = "ab" mat = np.array([[0.4, 0, 0.6], [0.4, 0, 0.6]]) print('TARGET :', '"a"') print('BEST PATH :', '"' + BestPath.ctcBestPath(mat, classes) + '"') print('PREFIX SEARCH:', '"' + PrefixSearch.ctcPrefixSearch(mat, classes) + '"') print('BEAM SEARCH :', '"' + BeamSearch.ctcBeamSearch(mat, classes, None) + '"') print( 'TOKEN :', '"' + TokenPassing.ctcTokenPassing(mat, classes, ['a', 'b', 'ab', 'ba']) + '"')
def testMiniExample(): "example which shows difference between taking most probable path and most probable labeling. No language model used." # chars and input matrix classes = 'ab' mat = np.array([[0.4, 0, 0.6], [0.4, 0, 0.6]]) # decode gt = 'a' print('TARGET :', '"' + gt + '"') print('BEST PATH :', '"' + BestPath.ctcBestPath(mat, classes) + '"') print('PREFIX SEARCH:', '"' + PrefixSearch.ctcPrefixSearch(mat, classes) + '"') print('BEAM SEARCH :', '"' + BeamSearch.ctcBeamSearch(mat, classes, None) + '"') print('TOKEN :', '"' + TokenPassing.ctcTokenPassing(mat, classes, ['a', 'b', 'ab', 'ba']) + '"') print('PROB(TARGET) :', Loss.ctcLabelingProb(mat, gt, classes)) print('LOSS(TARGET) :', Loss.ctcLoss(mat, gt, classes))