Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++] Initial Work for Pairwise Ranking #6182

Open
wants to merge 88 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
9ae3476
initial work for pairwise ranking (dataset part)
shiyu1994 Nov 8, 2023
2314099
remove unrelated changes
shiyu1994 Nov 8, 2023
06ddf68
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Nov 8, 2023
42e91e2
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Nov 23, 2023
a8379d4
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Dec 1, 2023
da5f02d
first version of pairwie ranking bin
shiyu1994 Dec 5, 2023
9d0afd9
Merge branch 'pairwise-ranking-dev' of https://github.com/Microsoft/L…
shiyu1994 Dec 5, 2023
0cb436d
templates for bins in pairwise ranking dataset
shiyu1994 Dec 5, 2023
fc9b381
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Dec 5, 2023
6fbc674
fix lint issues and compilation errors
shiyu1994 Dec 6, 2023
6082913
Merge branch 'pairwise-ranking-dev' of https://github.com/Microsoft/L…
shiyu1994 Dec 6, 2023
9e16dc3
add methods for pairwise bin
shiyu1994 Dec 6, 2023
6154bde
instantiate templates
shiyu1994 Dec 6, 2023
3a646eb
remove unrelated files
shiyu1994 Dec 6, 2023
9e77ab9
add return values for unimplemented methods
shiyu1994 Dec 7, 2023
eba4560
add new files and windows/LightGBM.vcxproj and windows/LightGBM.vcxpr…
shiyu1994 Dec 7, 2023
f1d2281
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Dec 7, 2023
873d7ad
create pairwise dataset
shiyu1994 Dec 7, 2023
3838b9b
Merge branch 'pairwise-ranking-dev' of https://github.com/Microsoft/L…
shiyu1994 Dec 7, 2023
986a979
set num_data_ of pairwise dataset
shiyu1994 Dec 7, 2023
c40965a
skip query with no paired items
shiyu1994 Dec 15, 2023
97d34d7
store original query information
shiyu1994 Jan 31, 2024
1e57e27
copy position information for pairwise dataset
shiyu1994 Jan 31, 2024
1699c06
rename to pointwise members
shiyu1994 Feb 1, 2024
d5b6f0a
adding initial support for pairwise gradients and NDCG eval with pair…
metpavel Feb 9, 2024
2ee1199
fix score offsets
metpavel Feb 9, 2024
fe10a2c
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Feb 19, 2024
0aaf090
skip copy for weights and label if none
shiyu1994 Feb 19, 2024
8714bfb
fix pairwise dataset bugs
shiyu1994 Feb 29, 2024
250996b
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Feb 29, 2024
38b2f3e
fix validation set with pairwise lambda rank
shiyu1994 Feb 29, 2024
09fff25
Merge branch 'pairwise-ranking-dev' of https://github.com/Microsoft/L…
shiyu1994 Feb 29, 2024
ba3c815
fix pairwise ranking objective initialization
shiyu1994 Feb 29, 2024
d9b537d
keep the original query boundaries and add pairwise query boundaries
shiyu1994 Feb 29, 2024
362baf8
allow empty queries in pairwise query boundaries
shiyu1994 Mar 1, 2024
06597ac
fix query boundaries
shiyu1994 Mar 1, 2024
18e3a1b
clean up
shiyu1994 Mar 1, 2024
43b8582
various fixes
metpavel Mar 1, 2024
ad4e89f
construct all pairs for validation set
shiyu1994 Mar 1, 2024
dc17309
Merge branch 'pairwise-ranking-dev' of https://github.com/microsoft/L…
metpavel Mar 1, 2024
1ad78b2
fix for validation set
shiyu1994 Mar 1, 2024
9cd3b93
fix validation pairs
shiyu1994 Mar 1, 2024
f9d9c07
fatal error when no query boundary is provided
shiyu1994 Mar 1, 2024
97e0a81
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Mar 1, 2024
746bc82
add differential features
shiyu1994 Mar 8, 2024
f9ab075
add differential features
shiyu1994 Mar 20, 2024
7aa170b
bug fixing and efficiency improvement
metpavel Mar 25, 2024
abdb716
add feature group for differential features
shiyu1994 Mar 27, 2024
3cdfd83
refactor template initializations with macro
shiyu1994 Mar 28, 2024
3703495
tree learning with differential features
shiyu1994 Mar 28, 2024
8f55a93
avoid copy sampled values
shiyu1994 Mar 28, 2024
8c3e7be
fix sampled indices
shiyu1994 Apr 2, 2024
5aa2d17
push data into differential features
shiyu1994 Apr 11, 2024
1c319b8
fix differential feature bugs
shiyu1994 Apr 17, 2024
d8eb68b
clean up debug code
shiyu1994 Apr 17, 2024
b088236
fix validation set with differential features
shiyu1994 Apr 18, 2024
2d09897
support row-wise histogram construction with pairwise ranking
shiyu1994 Jun 15, 2024
406d0c1
fix row wise in pairwise ranking
shiyu1994 Jun 20, 2024
6c65d1f
save for debug
shiyu1994 Jun 20, 2024
7738915
update code for debug
shiyu1994 Jun 28, 2024
d6c16df
save changes
shiyu1994 Jul 4, 2024
0d572d7
save changes for debug
shiyu1994 Jul 8, 2024
1f59f85
save changes
shiyu1994 Aug 21, 2024
0618bb2
add bagging by query for lambdarank
shiyu1994 Aug 27, 2024
185bdf6
Merge branch 'master' into bagging/bagging-by-query-for-lambdarank
shiyu1994 Aug 27, 2024
38fa4c2
fix pre-commit
shiyu1994 Aug 27, 2024
2fce147
Merge branch 'bagging/bagging-by-query-for-lambdarank' of https://git…
shiyu1994 Aug 27, 2024
1f7f967
Merge branch 'master' into bagging/bagging-by-query-for-lambdarank
shiyu1994 Aug 29, 2024
9e2a322
fix bagging by query with cuda
shiyu1994 Aug 29, 2024
666c51e
fix bagging by query test case
shiyu1994 Aug 30, 2024
9e2c338
fix bagging by query test case
shiyu1994 Aug 30, 2024
3abbc11
fix bagging by query test case
shiyu1994 Aug 30, 2024
13fa0a3
add #include <vector>
shiyu1994 Aug 30, 2024
b8427b0
merge bagging by query
shiyu1994 Sep 4, 2024
0258f07
update CMakeLists.txt
shiyu1994 Sep 4, 2024
90a95fa
fix bagging by query with pairwise lambdarank
shiyu1994 Sep 20, 2024
306af04
Merge branch 'master' into pairwise-ranking-dev
shiyu1994 Sep 20, 2024
b69913d
fix compilation error C3200 with visual studio
shiyu1994 Oct 10, 2024
6dba1cf
clean up main.cpp
shiyu1994 Oct 11, 2024
3b2e29d
Exposing configuration parameters for pairwise ranking
metpavel Oct 18, 2024
f1c32d3
fix bugs and pass by reference for SigmoidCache&
shiyu1994 Nov 8, 2024
51693e2
add pairing approach
shiyu1994 Nov 8, 2024
5071842
add at_least_one_relevant
shiyu1994 Nov 8, 2024
598764b
fix num bin for row wise in pairwise ranking
shiyu1994 Nov 21, 2024
f7deab4
save for debug
shiyu1994 Dec 17, 2024
0d1b310
update doc
shiyu1994 Dec 18, 2024
8f9ab26
add random_k pairing mode
shiyu1994 Feb 18, 2025
d797122
clean up code
shiyu1994 Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
initial work for pairwise ranking (dataset part)
  • Loading branch information
shiyu1994 committed Nov 8, 2023
commit 9ae347614bb7beef5186a4b791baafd26231ce93
5 changes: 5 additions & 0 deletions include/LightGBM/config.h
Original file line number Diff line number Diff line change
@@ -36,6 +36,11 @@ enum TaskType {
};
const int kDefaultNumLeaves = 31;

/*! \brief Types of pairwise ranking mode */
enum PairwiseRankingMode {
kNone, kFull, kRelevance, kManual
};

struct Config {
public:
std::string ToString() const;
24 changes: 24 additions & 0 deletions include/LightGBM/dataset.h
Original file line number Diff line number Diff line change
@@ -199,6 +199,12 @@ class Metadata {
const double* init_scores,
const int32_t* queries);

/*!
* \brief Build metadata for ranking with pairwise features from metadata of an existing ranking dataset
* \param metadata Pointer to metadata of the existing ranking dataset
*/
void BuildPairwiseFeatureRanking(const Metadata& metadata);

/*!
* \brief Perform any extra operations after all data has been loaded
*/
@@ -247,6 +253,18 @@ class Metadata {
return position_ids_.size();
}

/*!
* \brief Get the pairwise item index map in ranking with pairwise features
* \return Pointer to the pairwise item index map
*/
inline const std::pair<data_size_t, data_size_t>* paired_ranking_item_index_map() const {
if (!paired_ranking_item_index_map_.empty()) {
return paired_ranking_item_index_map_.data();
} else {
return nullptr;
}
}

/*!
* \brief Get data boundaries on queries, if not exists, will return nullptr
* we assume data will order by query,
@@ -367,6 +385,10 @@ class Metadata {
std::vector<double> init_score_;
/*! \brief Queries data */
std::vector<data_size_t> queries_;
/*! \brief Mode for pairwise ranking */
PairwiseRankingMode pairwise_ranking_mode_;
/*! \brief Pairwise data index to original data indices for ranking with pairwise features */
std::vector<std::pair<data_size_t, data_size_t>> paired_ranking_item_index_map_;
/*! \brief mutex for threading safe call */
std::mutex mutex_;
bool weight_load_from_file_;
@@ -677,6 +699,8 @@ class Dataset {

LIGHTGBM_EXPORT void CreateValid(const Dataset* dataset);

LIGHTGBM_EXPORT void CreatePairWiseRankingData(const Dataset* dataset, std::vector<std::pair<data_size_t, data_size_t>> pair_index_map);

void InitTrain(const std::vector<int8_t>& is_feature_used,
TrainingShareStates* share_state) const;

2 changes: 1 addition & 1 deletion include/LightGBM/feature_group.h
Original file line number Diff line number Diff line change
@@ -581,7 +581,7 @@ class FeatureGroup {
}
}

private:
protected:
void CreateBinData(int num_data, bool is_multi_val, bool force_dense, bool force_sparse) {
if (is_multi_val) {
multi_bin_data_.clear();
107 changes: 107 additions & 0 deletions include/LightGBM/pairwise_ranking_feature_group.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*!
* Copyright (c) 2023 Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for
* license information.
*/
#ifndef LIGHTGBM_PAIRWISE_FEATURE_GROUP_H_
#define LIGHTGBM_PAIRWISE_FEATURE_GROUP_H_

#include "feature_group.h"

#include <cstdio>
#include <memory>
#include <utility>
#include <vector>

namespace LightGBM {

/*! \brief Using to store data and providing some operations on one feature
group*/
class PairwiseRankingFeatureGroup: public FeatureGroup {
public:
/*!
* \brief Constructor
* \param num_feature number of features of this group
* \param bin_mappers Bin mapper for features
* \param num_data Total number of data
* \param is_enable_sparse True if enable sparse feature
*/

PairwiseRankingFeatureGroup(const FeatureGroup& other, int num_data) {
num_feature_ = other.num_feature_;
is_multi_val_ = false;
is_dense_multi_val_ = false;
is_sparse_ = false;
num_total_bin_ = other.num_total_bin_;
bin_offsets_ = other.bin_offsets_;
num_data_ = num_data;

bin_mappers_.reserve(other.bin_mappers_.size());
for (auto& bin_mapper : other.bin_mappers_) {
bin_mappers_.emplace_back(new BinMapper(*bin_mapper));
}
CreateBinData(num_data, is_multi_val_, !is_sparse_, is_sparse_);
}

/*!
* \brief Constructor from memory when data is present
* \param memory Pointer of memory
* \param num_all_data Number of global data
* \param local_used_indices Local used indices, empty means using all data
* \param group_id Id of group
*/
PairwiseRankingFeatureGroup(const void* memory,
data_size_t num_all_data,
const std::vector<data_size_t>& local_used_indices,
int group_id) {
// TODO(shiyu1994)
}

/*!
* \brief Constructor from definition in memory (without data)
* \param memory Pointer of memory
* \param local_used_indices Local used indices, empty means using all data
*/
FeatureGroup(const void* memory, data_size_t num_data, int group_id) {
// TODO(shiyu1994)
}

/*! \brief Destructor */
~PairwiseRankingFeatureGroup() {}

/*!
* \brief Load the overall definition of the feature group from binary serialized data
* \param memory Pointer of memory
* \param group_id Id of group
*/
const char* LoadDefinitionFromMemory(const void* memory, int group_id) {
// TODO(shiyu1994)
}

inline BinIterator* SubFeatureIterator(int sub_feature) {
// TODO(shiyu1994)
}

inline void FinishLoad() {
// TODO(shiyu1994)
}

inline BinIterator* FeatureGroupIterator() {
// TODO(shiyu1994)
}

private:
void CreateBinData(int num_data, bool is_multi_val, bool force_dense, bool force_sparse) {
// TODO(shiyu1994)
}


/*! \brief Pairwise data index to original data indices for ranking with pairwise features */
const std::pair<data_size_t, data_size_t>* paired_ranking_item_index_map_;
/*! \brief Number of pairwise data */
data_size_t num_data_;
};

} // namespace LightGBM

#endif // LIGHTGBM_PAIRWISE_FEATURE_GROUP_H_
Loading
Oops, something went wrong.