#include #include // for system #include "../vowpalwabbit/vw.h" #include "../vowpalwabbit/ezexample.h" #include "../vowpalwabbit/search_sequencetask.h" #include "libsearch.h" using std::cerr; using std::endl; struct wt { std::string word; uint32_t tag; wt(std::string w, uint32_t t) : word(w), tag(t) {} }; class SequenceLabelerTask : public SearchTask, std::vector > { public: SequenceLabelerTask(vw& vw_obj) : SearchTask, std::vector >(vw_obj) // must run parent constructor! { sch.set_options( Search::AUTO_HAMMING_LOSS | Search::AUTO_CONDITION_FEATURES ); HookTask::task_data* d = sch.get_task_data(); cerr << "num_actions = " << d->num_actions << endl; } // using vanilla vw interface void _run(Search::search& sch, std::vector & input_example, std::vector & output) { output.clear(); for (size_t i=0; i & input_example, std::vector & output) { output.clear(); for (size_t i=0; i data; std::vector output; uint32_t DET = 1, NOUN = 2, VERB = 3, ADJ = 4; data.push_back( wt("the", DET) ); data.push_back( wt("monster", NOUN) ); data.push_back( wt("ate", VERB) ); data.push_back( wt("a", DET) ); data.push_back( wt("big", ADJ) ); data.push_back( wt("sandwich", NOUN) ); task.learn(data, output); task.learn(data, output); task.learn(data, output); task.predict(data, output); cerr << "output = ["; for (size_t i=0; i out; task.predict(V, out); cerr << "out (should be 1 2 3 4 3) ="; for (size_t i=0; i