code: def ranking_demo(args: argparse.Namespace) -> None:
      """Demonstration for learning to rank with relevance degree."""
      data = load_mlsr_10k(args.data, args.cache)
  
      # Sort data according to query index
      X_train, y_train, qid_train = data.train
      sorted_idx = np.argsort(qid_train)
      X_train = X_train[sorted_idx]
      y_train = y_train[sorted_idx]
      qid_train = qid_train[sorted_idx]
  
      X_test, y_test, qid_test = data.test
      sorted_idx = np.argsort(qid_test)
      X_test = X_test[sorted_idx]
      y_test = y_test[sorted_idx]
      qid_test = qid_test[sorted_idx]
  
      ranker = xgb.XGBRanker(
          tree_method="hist",
          device="cuda",
          lambdarank_pair_method="topk",
          lambdarank_num_pair_per_sample=13,
          eval_metric=["ndcg@1", "ndcg@8"],
      )
      ranker.fit(
          X_train,
          y_train,
          qid=qid_train,
          eval_set=[(X_test, y_test)],
          eval_qid=[qid_test],
          verbose=True,
      )
  
file_path: xgboost/demo/guide-python/learning_to_rank.py
imports: from __future__ import annotations
  import argparse
  import json
  import os
  import pickle
  import numpy
  import pandas
  from sklearn.datasets import load_svmlight_file
  import xgboost
  from xgboost.testing.data import RelDataCV, simulate_clicks, sort_ltr_samples
label_desc: Use image node_id 2 for calling a global function with example usage: ranking_demo(args) without return types