You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
auto sims = torch::stack({repeated_pos, negative_vals}, -1); //[batch_size x negative_phrase_n x 2]
126
+
auto sims = torch::stack({repeated_pos, negative_vals}, -1); //[batch_size x negative_phrase_n x 2]
125
127
std::cout << "Relevancy: 6" << std::endl;
126
128
auto smx = torch::softmax(10 * sims, -1); // [batch_size x negative_phrase_n x 2]
127
129
std::cout << "Relevancy: 7" << std::endl;
128
-
auto best_id = smx.index({"...", 0}).argmin(1); // [batch_size x 2]
130
+
auto best_id = smx.index({"...", 0}).argmin(1); // [batch_size x 2]
129
131
std::cout << "Relevancy: 8" << std::endl;
130
-
auto result = torch::gather(smx, 1, best_id.index({"...", torch::indexing::None, torch::indexing::None}).expand({best_id.sizes()[0], negatives.sizes()[0], 2})
131
-
).index({torch::indexing::Slice(), 0, torch::indexing::Slice()});// [batch_size x 2]
132
+
auto result = torch::gather(smx, 1, best_id.index({"...", torch::indexing::None, torch::indexing::None}).expand({best_id.sizes()[0], negatives.sizes()[0], 2})
133
+
).index({torch::indexing::Slice(), 0, torch::indexing::Slice()});// [batch_size x 2]
132
134
return result;
135
+
#else
136
+
auto embeds2 = torch::cat({ positives, negatives }, 0);
137
+
auto logits = torch::mm(embeds, embeds2.t()); // [batch_size, 1 + negatives_len]
0 commit comments