diff options
author | Ales Tamchyna <tamchyna@ufal.mff.cuni.cz> | 2015-01-08 19:44:51 +0300 |
---|---|---|
committer | Ales Tamchyna <tamchyna@ufal.mff.cuni.cz> | 2015-01-08 19:44:51 +0300 |
commit | d7f8738ccf939bd98af737bf88f137c79ce085cf (patch) | |
tree | 347b0c890451cec8288c5508add422feb843c0f4 /vw | |
parent | 2cb0d482d7c53151bf34d7aa5f100675cecf08bb (diff) |
VW parser instance per thread, fixes race conditions in VW
Diffstat (limited to 'vw')
-rw-r--r-- | vw/Classifier.h | 8 | ||||
-rw-r--r-- | vw/VWPredictor.cpp | 8 | ||||
-rw-r--r-- | vw/VWPredictorFactory.cpp | 2 |
3 files changed, 11 insertions, 7 deletions
diff --git a/vw/Classifier.h b/vw/Classifier.h index 68487a740..f10747f69 100644 --- a/vw/Classifier.h +++ b/vw/Classifier.h @@ -84,6 +84,7 @@ protected: // some of VW settings are hard-coded because they are always needed in our scenario // (e.g. quadratic source X target features) const std::string VW_DEFAULT_OPTIONS = " --hash all --noconstant -q st -t --ldf_override s "; +const std::string VW_DEFAULT_PARSER_OPTIONS = " --quiet --hash all --noconstant -q st -t --csoaa_ldf s "; /** * Produce VW training file (does not use the VW library!) @@ -128,10 +129,10 @@ public: friend class VWPredictorFactory; protected: - void AddFeature(const StringPiece &name, float value); + void AddFeature(const StringPiece &name, float values); void Finish(); - ::vw *m_VWInstance; + ::vw *m_VWInstance, *m_VWParser; ::ezexample *m_ex; // if true, then the VW instance is owned by an external party and should NOT be // deleted at end; if false, then we own the VW instance and must clean up after it. @@ -142,7 +143,8 @@ protected: ~VWPredictor(); private: - VWPredictor(vw * instance, int index); // instantiation by VWPredictorFactory + // instantiation by VWPredictorFactory + VWPredictor(vw * instance, int index, const std::string &vwOption); }; /** diff --git a/vw/VWPredictor.cpp b/vw/VWPredictor.cpp index ab4c44c3f..76d194b5b 100644 --- a/vw/VWPredictor.cpp +++ b/vw/VWPredictor.cpp @@ -12,16 +12,18 @@ using namespace std; VWPredictor::VWPredictor(const string &modelFile, const string &vwOptions) { m_VWInstance = VW::initialize(VW_DEFAULT_OPTIONS + " -i " + modelFile + vwOptions); + m_VWParser = VW::initialize(VW_DEFAULT_PARSER_OPTIONS + vwOptions + " --noop"); m_sharedVwInstance = false; - m_ex = new ::ezexample(m_VWInstance, false); + m_ex = new ::ezexample(m_VWInstance, false, m_VWParser); m_isFirstSource = m_isFirstTarget = true; } -VWPredictor::VWPredictor(vw *instance, int index) +VWPredictor::VWPredictor(vw *instance, int index, const string &vwOptions) { m_VWInstance = instance; + m_VWParser = VW::initialize(vwOptions + " --noop"); m_sharedVwInstance = true; - m_ex = new ::ezexample(m_VWInstance, false); + m_ex = new ::ezexample(m_VWInstance, false, m_VWParser); m_index = index; m_isFirstSource = m_isFirstTarget = true; } diff --git a/vw/VWPredictorFactory.cpp b/vw/VWPredictorFactory.cpp index a9de02ff1..4a664d641 100644 --- a/vw/VWPredictorFactory.cpp +++ b/vw/VWPredictorFactory.cpp @@ -23,7 +23,7 @@ VWPredictorFactory::VWPredictorFactory( if (VWPredictor::DEBUG) std::cerr << "VW :: filling VWPredictor pool: "; for (int i = 0; i < poolSize; ++i) { - m_predictors.push_back(new VWPredictor(m_VWInstance, i)); + m_predictors.push_back(new VWPredictor(m_VWInstance, i, VW_DEFAULT_PARSER_OPTIONS + vwOptions)); m_nextFree.push_back(lastFree); lastFree = i; if (VWPredictor::DEBUG) std::cerr << "."; |