45 for (
size_t i = 0; i < ec.size(); i++)
47 action oracle = ec[i]->l.multi.label;
99 for (
size_t n = 0; n < ec.size(); n++)
103 action nexty = (n == ec.size() - 1) ? 0 : ec[n + 1]->l.multi.label;
109 ylab.
label = (y / 2 - 1) * 4 + 2;
111 ylab.
label = (y / 2 - 1) * 4 + 3;
116 ylab.
label = (y - 1) * 2 + 1;
118 ylab.
label = (y - 1) * 2;
136 bool search_span_bilou =
false;
140 .help(
"switch to (internal) BILOU encoding instead of BIO encoding"))
144 if (search_span_bilou)
146 std::cerr <<
"switching to BILOU encoding for sequence span labeling" << std::endl;
148 num_actions = num_actions * 2 - 1;
164 for (
action l = 2; l < num_actions; l += 4)
201 for (
size_t n = 0; n < ec.size(); n++)
213 for (
size_t pass = 1; pass <= D.
multipass; pass++)
215 action last_prediction = 1;
216 for (
size_t i = 0; i < ec.size(); i++)
218 action oracle = ec[i]->l.multi.label;
219 size_t len = y_allowed->size();
224 if (last_prediction == 1)
226 else if (last_prediction % 2 == 0)
228 (*y_allowed)[len - 1] = last_prediction + 1;
233 (*y_allowed)[len - 1] = last_prediction;
236 if ((oracle > 1) && (oracle % 2 == 1) && (last_prediction != oracle) && (last_prediction != oracle - 1))
241 if ((last_prediction == 1) || ((last_prediction - 2) % 4 == 0) ||
242 ((last_prediction - 2) % 4 == 3))
246 if ((oracle > 1) && (((oracle - 2) % 4 == 2) || ((oracle - 2) % 4 == 3)))
251 action other = ((last_prediction - 2) % 4 == 1) ? (last_prediction + 2) : last_prediction;
254 if ((oracle != last_prediction + 1) && (oracle != other))
287 float* costs = calloc_or_throw<float>(K);
289 for (
size_t i = 0; i < ec.size(); i++)
291 action oracle = ec[i]->l.multi.label;
292 for (
size_t k = 0; k < K; k++) costs[k] = 1.;
293 costs[oracle - 1] = 0.;
294 size_t prediction = P.set_tag((
ptag)i + 1)
296 .set_allowed(
nullptr, costs, K)
323 .help(
"Relative weight of negative examples"))
345 uint32_t max_prediction = 1;
346 uint32_t max_label = 1;
348 for (
size_t i = 0; i < ec.size(); i++) max_label = std::max(ec[i]->l.multi.label, max_label);
350 for (
ptag i = 0; i < ec.size(); i++)
353 uint32_t oracle = D.
predict_max ? max_label : ec[i]->l.multi.label;
354 uint32_t prediction = sch.
predict(*ec[i], i + 1, &oracle, 1, &i,
"p");
356 max_prediction = std::max(prediction, max_prediction);
359 if (max_label > max_prediction)
361 else if (max_prediction > max_label)
366 sch.
output() << max_prediction;
384 for (
size_t a = 0;
a < num_actions;
a++)
388 lab.
costs.push_back(default_wclass);
392 task_data* data = &calloc_or_throw<task_data>();
416 for (
feature_index& idx : fs.indicies) idx = (((idx >> ss) * mult_amount) + plus_amount) << ss;
423 for (
ptag i = 0; i < ec.size(); i++)
438 lab.
costs[0].class_index =
a + 1;
439 lab.
costs[0].partial_prediction = 0.;
440 lab.
costs[0].wap_value = 0.;
443 action oracle = ec[i]->l.multi.label - 1;
449 action prediction = pred_id + 1;
452 sch.
output() << prediction <<
' ';
predictor & set_oracle(action a)
size_t get_stride_shift()
uint32_t get_history_length()
float false_negative_cost
vw * setup(options_i &options)
std::stringstream & output()
void copy_example_data(bool audit, example *dst, example *src)
std::string pretty_label(action a)
std::vector< std::string > * interactions
void(* default_label)(void *)
void dealloc_example(void(*delete_label)(void *), example &ec, void(*delete_prediction)(void *))
v_array< action > allowed_actions
the core definition of a set of features.
void delete_label(void *v)
virtual void add_and_parse(const option_group_definition &group)=0
void finish(vw &all, bool delete_all)
float loss(cbify &data, uint32_t label, uint32_t final_prediction)
v_array< action > only_two_allowed
action bilou_to_bio(action y)
example * alloc_examples(size_t, size_t count=1)
void convert_bio_to_bilou(multi_ex &ec)
uint32_t AUTO_CONDITION_FEATURES
predictor & add_condition_range(ptag hi, ptag count, char name0)
vw & get_vw_pointer_unsafe()
void push_back(const T &new_ele)
void my_update_example_indicies(Search::search &sch, bool, example *ec, uint64_t mult_amount, uint64_t plus_amount)
vw * initialize(options_i &options, io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
predictor & add_allowed(action a)
void set_options(uint32_t opts)
predictor & set_learner_id(size_t id)
action predict(example &ec, ptag my_tag, const action *oracle_actions, size_t oracle_actions_cnt=1, const ptag *condition_on=nullptr, const char *condition_on_names=nullptr, const action *allowed_actions=nullptr, size_t allowed_actions_cnt=0, const float *allowed_actions_cost=nullptr, size_t learner_id=0, float weight=0.)
predictor & set_allowed(action a)
option_group_definition & add(T &&op)
int add(svm_params ¶ms, svm_example *fec)
std::vector< example * > multi_ex
uint32_t AUTO_HAMMING_LOSS
void set_task_data(T *data)
predictor & set_condition_range(ptag hi, ptag count, char name0)
typed_option< T > make_option(std::string name, T &location)
predictor & set_tag(ptag tag)
std::vector< std::string > interactions
void predict(bfgs &b, base_learner &, example &ec)
void takedown(Search::search &sch, multi_ex &ec)
uint32_t EXAMPLES_DONT_CHANGE
bool predictNeedsExample()
void set_num_learners(size_t num_learners)
predictor & set_input(example &input_example)
void run(Search::search &sch, multi_ex &ec)
void loss(float incr_loss)