| 59 | |
| 60 | template <class PosIndexingFunc, class NegIndexingFunc> |
| 61 | void FillEdgeAndLabel(Instance* inst, const std::string& user_name, |
| 62 | const std::string& item_name, const std::string& y_name, |
| 63 | const vec_int_t& pos_items, |
| 64 | const std::vector<vec_int_t>& neg_items_list, |
| 65 | PosIndexingFunc&& pos_indexing_func, |
| 66 | NegIndexingFunc&& neg_indexing_func) const { |
| 67 | auto* user_ptr = &inst->get_or_insert<csr_t>(user_name); |
| 68 | auto* item_ptr = &inst->get_or_insert<csr_t>(item_name); |
| 69 | auto* y_ptr = &inst->get_or_insert<tsr_t>(y_name); |
| 70 | user_ptr->clear(); |
| 71 | item_ptr->clear(); |
| 72 | y_ptr->clear(); |
| 73 | y_ptr->resize((int)pos_items.size(), 1); |
| 74 | |
| 75 | int k = 0; |
| 76 | for (size_t i = 0; i < pos_items.size(); ++i) { |
| 77 | // (user, pos_item) |
| 78 | auto pos = pos_indexing_func(pos_items[i]); |
| 79 | user_ptr->emplace(i, 1); |
| 80 | user_ptr->add_row(); |
| 81 | item_ptr->emplace(pos, 1); |
| 82 | item_ptr->add_row(); |
| 83 | // sampled softmax: [pos, neg, neg, neg, ...] |
| 84 | // Y should be set as the position of pos items (0 in this case) |
| 85 | y_ptr->data(k++) = 0; |
| 86 | |
| 87 | // (user, neg_item) |
| 88 | auto ns = io_util::GetNodeType(pos_items[i]); |
| 89 | for (auto neg_item : neg_items_list[ns]) { |
| 90 | auto neg = neg_indexing_func(neg_item); |
| 91 | user_ptr->emplace(i, 1); |
| 92 | user_ptr->add_row(); |
| 93 | item_ptr->emplace(neg, 1); |
| 94 | item_ptr->add_row(); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | } // namespace embedx |
nothing calls this directly
no test coverage detected