11 #define R_NONE 10 // label for NONE relation 12 #define LABEL_SKIP 11 // label for SKIP 54 .help(
"None Relation Cost"))
58 .help(
"Skip Cost (only used when search_order = skip"))
62 .help(
"Search Order 0: EntityFirst 1: Mix 2: Skip 3: EntityFirst(LDF)"));
82 for (
size_t a = 0;
a < 10;
a++)
84 ldf_examples[
a].
l.
cs.
costs.push_back(default_wclass);
112 size_t valid_ent1_id[] = {2, 3, 4, 2, 2};
113 size_t valid_ent2_id[] = {4, 4, 4, 3, 2};
116 if (valid_ent1_id[rel_id - 5] == ent1_id && valid_ent2_id[rel_id - 5] == ent2_id)
127 while (idx < tag.
size() && tag[idx] !=
'_' && tag[idx] !=
'\0')
132 id1 = atoi(s1.c_str());
135 while (idx < tag.
size() && tag[idx] !=
'_' && tag[idx] !=
'\0')
137 s2.push_back(tag[idx]);
140 id2 = atoi(s2.c_str());
166 for (uint32_t
a = 0;
a < 4;
a++)
171 lab.
costs[0].x = 0.f;
172 lab.
costs[0].class_index =
a;
173 lab.
costs[0].partial_prediction = 0.f;
174 lab.
costs[0].wap_value = 0.f;
213 if (my_task_data->
constraints && predictions[id1] != 0 && predictions[id2] != 0)
215 hist[0] = predictions[id1];
216 hist[1] = predictions[id2];
225 if (!my_task_data->
constraints || hist[0] == (
size_t)0 ||
245 constrained_relation_labels.
pop();
251 int correct_label = 0;
252 for (
size_t a = 0;
a < constrained_relation_labels.
size();
a++)
256 true, &my_task_data->
ldf_relation[
a], 28904713, 4832917 * (uint64_t)(constrained_relation_labels[
a]));
258 lab.
costs[0].x = 0.f;
259 lab.
costs[0].class_index = constrained_relation_labels[
a];
260 lab.
costs[0].partial_prediction = 0.f;
261 lab.
costs[0].wap_value = 0.f;
262 if (constrained_relation_labels[a] == ex->
l.
multi.
label)
264 correct_label = (int)a;
269 .set_oracle(correct_label)
272 prediction = constrained_relation_labels[pred_pos];
302 constrained_relation_labels.
delete_v();
309 size_t n_ent = (size_t)(std::sqrt(ec.size() * 8 + 1) - 1) / 2;
311 for (
size_t i = 0; i < ec.size(); i++)
323 uint32_t n_ent = (uint32_t)((std::sqrt(ec.size() * 8 + 1) - 1) / 2);
324 for (uint32_t t = 0; t < ec.size(); t++)
328 for (
ptag i = 0; i < n_ent; i++)
336 for (uint32_t j = 0; j < i; j++)
340 ptag rel_index = (
ptag)(n_ent + (2 * n_ent - j - 1) * j / 2 + i - j - 1);
341 predictions[rel_index] =
predict_relation(sch, ec[rel_index], predictions, rel_index);
354 size_t n_ent = (size_t)(std::sqrt(ec.size() * 8 + 1) - 1) / 2;
356 bool must_predict =
false;
357 size_t n_predicts = 0;
358 size_t p_n_predicts = 0;
362 for (
ptag t = 0;; t++)
364 ptag i = t % (uint32_t)ec.size();
365 if (n_predicts == ec.size())
368 if (predictions[i] == 0)
386 predictions[i] = prediction;
393 must_predict =
false;
397 if (i == ec.size() - 1)
399 if (n_predicts == p_n_predicts)
403 p_n_predicts = n_predicts;
413 for (
size_t i = 0; i < ec.size(); i++)
433 std::cerr <<
"search order " << my_task_data->
search_order <<
"is undefined." << std::endl;
436 for (
size_t i = 0; i < ec.size(); i++)
439 sch.
output() << predictions[i] <<
' ';
441 predictions.delete_v();
447 for (
feature_index& idx : fs.indicies) idx = ((idx * mult_amount) + plus_amount);
predictor & set_oracle(action a)
void entity_first_decoding(Search::search &sch, multi_ex &ec, v_array< size_t > &predictions, bool isLdf=false)
std::stringstream & output()
void copy_example_data(bool audit, example *dst, example *src)
void update_example_indicies(bool audit, example *ec, uint64_t mult_amount, uint64_t plus_amount)
predictor & add_condition(ptag tag, char name)
std::vector< std::string > * interactions
void dealloc_example(void(*delete_label)(void *), example &ec, void(*delete_prediction)(void *))
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)
example * alloc_examples(size_t, size_t count=1)
MULTICLASS::label_t multi
void run(Search::search &sch, multi_ex &ec)
vw & get_vw_pointer_unsafe()
void push_back(const T &new_ele)
void er_mixed_decoding(Search::search &sch, multi_ex &ec, v_array< size_t > &predictions)
size_t predict_entity(Search::search &sch, example *ex, v_array< size_t > &, ptag my_tag, bool isLdf=false)
void decode_tag(v_array< char > tag, char &type, int &id1, int &id2)
vw * initialize(options_i &options, io_buf *model, bool skipModelLoad, trace_message_t trace_listener, void *trace_context)
v_array< uint32_t > y_allowed_entity
v_array< uint32_t > y_allowed_relation
void set_options(uint32_t opts)
predictor & set_learner_id(size_t id)
predictor & set_allowed(action a)
size_t predict_relation(Search::search &sch, example *ex, v_array< size_t > &predictions, ptag my_tag, bool isLdf=false)
int add(svm_params ¶ms, svm_example *fec)
std::vector< example * > multi_ex
void set_task_data(T *data)
typed_option< T > make_option(std::string name, T &location)
std::vector< std::string > interactions
bool check_constraints(size_t ent1_id, size_t ent2_id, size_t rel_id)
void set_num_learners(size_t num_learners)
predictor & set_input(example &input_example)
void er_allow_skip_decoding(Search::search &sch, multi_ex &ec, v_array< size_t > &predictions)
void loss(float incr_loss)