MCPcopy Create free account
hub / github.com/Tencent/embedx / GetTrainBatch

Method GetTrainBatch

src/model/instance_reader/dssm_inst_reader.cc:85–122  ·  view source on GitHub ↗

/ Read batch data from file for training */ /

Source from the content-addressed store, hash-verified

83 /* Read batch data from file for training */
84 /************************************************************************/
85 bool GetTrainBatch(Instance* inst) {
86 std::vector<AdjValue> values;
87 if (!NextInstanceBatch<AdjValue>(inst, batch_, &values)) {
88 return false;
89 }
90 pos_items_ = Collect<AdjValue, int_t>(values, &AdjValue::node);
91 DXCHECK(deep_client_->SharedSampleNegative(num_neg_, pos_items_, pos_items_,
92 &neg_items_list_));
93
94 // Fill Instance
95 // 1. Fill user feature
96 vec_int_t* user_nodes_ptr = nullptr;
97 feats_list_ = Collect<AdjValue, vec_pair_t>(values, &AdjValue::pairs);
98 flow_.FillNodeFeature(inst, instance_name::X_USER_FEATURE_NAME,
99 user_nodes_ptr, feats_list_);
100
101 // 2. Fill item feature
102 inst_util::RemoveDuplicateItems(pos_items_, neg_items_list_,
103 &unique_items_);
104 vec_int_t* item_nodes_ptr = add_node_ ? &unique_items_ : nullptr;
105 DXCHECK(deep_client_->LookupItemFeature(unique_items_, &item_feats_list_));
106 flow_.FillNodeFeature(inst, instance_name::X_ITEM_FEATURE_NAME,
107 item_nodes_ptr, item_feats_list_);
108
109 // 3. Fill edge and label
110 indexing_wrapper_->Clear();
111 indexing_wrapper_->BuildFrom(unique_items_);
112 auto indexing_func = [this](int_t node) {
113 return indexing_wrapper_->GlobalGet(node);
114 };
115 flow_.FillEdgeAndLabel(inst, instance_name::X_USER_ID_NAME,
116 instance_name::X_ITEM_ID_NAME, deepx_core::Y_NAME,
117 pos_items_, neg_items_list_, indexing_func,
118 indexing_func);
119
120 inst->set_batch(pos_items_.size());
121 return true;
122 }
123
124 /************************************************************************/
125 /* Read batch data from file for predicting */

Callers

nothing calls this directly

Calls 8

RemoveDuplicateItemsFunction · 0.85
BuildFromMethod · 0.80
GlobalGetMethod · 0.80
SharedSampleNegativeMethod · 0.45
FillNodeFeatureMethod · 0.45
LookupItemFeatureMethod · 0.45
ClearMethod · 0.45
FillEdgeAndLabelMethod · 0.45

Tested by

no test coverage detected