Add debugging helpers to PathTrie

This commit is contained in:
Reuben Morais 2019-10-15 12:46:59 +02:00
parent 83a89dcae6
commit 31d81740ee
4 changed files with 40 additions and 3 deletions

View File

@ -33,8 +33,8 @@ bindings: clean-keep-common
bindings-debug: clean-keep-common bindings-debug: clean-keep-common
pip install --quiet $(PYTHON_PACKAGES) wheel==0.31.0 setuptools==39.1.0 pip install --quiet $(PYTHON_PACKAGES) wheel==0.31.0 setuptools==39.1.0
AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS)" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py build_ext --debug --num_processes $(NUM_PROCESSES) $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS) AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS) -DDEBUG" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py build_ext --debug --num_processes $(NUM_PROCESSES) $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS)
$(GENERATE_DEBUG_SYMS) $(GENERATE_DEBUG_SYMS)
find temp_build -type f -name "*.o" -delete find temp_build -type f -name "*.o" -delete
AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS)" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py bdist_wheel $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS) AS=$(AS) CC=$(CC) CXX=$(CXX) LD=$(LD) CFLAGS="$(CFLAGS) $(CXXFLAGS) -DDEBUG" LDFLAGS="$(LDFLAGS_NEEDED)" $(PYTHON_PATH) $(NUMPY_INCLUDE) python ./setup.py bdist_wheel $(PYTHON_PLATFORM_NAME) $(SETUP_FLAGS)
rm -rf temp_build rm -rf temp_build

View File

@ -11,7 +11,7 @@ from multiprocessing.dummy import Pool
ARGS = ['-DKENLM_MAX_ORDER=6', '-std=c++11', '-Wno-unused-local-typedefs', '-Wno-sign-compare'] ARGS = ['-DKENLM_MAX_ORDER=6', '-std=c++11', '-Wno-unused-local-typedefs', '-Wno-sign-compare']
OPT_ARGS = ['-O3', '-DNDEBUG'] OPT_ARGS = ['-O3', '-DNDEBUG']
DBG_ARGS = ['-O0', '-g', '-UNDEBUG'] DBG_ARGS = ['-O0', '-g', '-UNDEBUG', '-DDEBUG']
INCLUDES = [ INCLUDES = [
'..', '..',

View File

@ -174,3 +174,31 @@ void PathTrie::set_dictionary(PathTrie::FstType* dictionary) {
void PathTrie::set_matcher(std::shared_ptr<fst::SortedMatcher<FstType>> matcher) { void PathTrie::set_matcher(std::shared_ptr<fst::SortedMatcher<FstType>> matcher) {
matcher_ = matcher; matcher_ = matcher;
} }
#ifdef DEBUG
void PathTrie::vec(std::vector<PathTrie*>& out) {
if (parent != nullptr) {
parent->vec(out);
}
out.push_back(this);
}
void PathTrie::print(const Alphabet& a) {
std::vector<PathTrie*> chain;
vec(chain);
std::string tr;
printf("characters:\t ");
for (PathTrie* el : chain) {
printf("%X ", el->character);
if (el->character != ROOT_) {
tr.append(a.StringFromLabel(el->character));
}
}
printf("\ntimesteps:\t ");
for (PathTrie* el : chain) {
printf("%d ", el->timestep);
}
printf("\n");
printf("transcript:\t %s\n", tr.c_str());
}
#endif // DEBUG

View File

@ -9,6 +9,10 @@
#include "fst/fstlib.h" #include "fst/fstlib.h"
#ifdef DEBUG
#include "alphabet.h"
#endif
/* Trie tree for prefix storing and manipulating, with a dictionary in /* Trie tree for prefix storing and manipulating, with a dictionary in
* finite-state transducer for spelling correction. * finite-state transducer for spelling correction.
*/ */
@ -44,6 +48,11 @@ public:
// remove current path from root // remove current path from root
void remove(); void remove();
#ifdef DEBUG
void vec(std::vector<PathTrie*>& out);
void print(const Alphabet& a);
#endif // DEBUG
float log_prob_b_prev; float log_prob_b_prev;
float log_prob_nb_prev; float log_prob_nb_prev;
float log_prob_b_cur; float log_prob_b_cur;