CoolFace
Modelpublic

llm-blender/pair-ranker

sourceHugging Facemitupdated 1y agoView on Hugging Face
4likes33downloads
Model Card

PairRanker used in llm-blender, trained on deberta-v3-large. This is the ranker model used in experiments in LLM-Blender paper, which is trained on mixinstruct dataset for 5 epochs.

Statistics

Context length

PairRanker typeSource max lengthCandidate max lengthTotal max length
pair-ranker (This model)128128384
pair-reward-model12244122048

MixInstrut Performance

**Methods**BERTScoreBARTScoreBLEURTGPT-RankBeat Vic(%)Beat OA(%)Top-1(%)Top-2(%)Top-3(%)
Open Assistant74.68-3.45-0.393.9062.78N/A17.3535.6751.98
Vicuna69.60-3.44-0.614.13N/A64.7725.4741.2352.88
Alpaca71.46-3.57-0.534.6256.7061.3515.4129.8144.46
Baize65.57-3.53-0.664.8652.7656.4014.2326.9138.80
moss64.85-3.65-0.735.0951.6251.7915.9327.5238.27
ChatGLM70.38-3.52-0.625.6344.0445.679.4119.3728.78
Koala63.96-3.85-0.846.7639.9339.018.1515.7222.55
Dolly v262.26-3.83-0.876.9033.3331.445.1610.0616.45
Mosaic MPT63.21-3.72-0.827.1930.8730.165.3910.6116.24
StableLM62.47-4.12-0.988.7121.5519.872.334.747.96
Flan-T564.92-4.57-1.238.8123.8919.931.302.875.32
Oracle(BERTScore)77.67-3.17-0.273.8854.4138.8420.1638.1153.49
Oracle(BLEURT)75.02-3.15-0.153.7755.6145.8021.4839.8455.36
Oracle(BARTScore)73.23-2.87-0.383.6950.3257.0126.1043.7057.33
Oracle(ChatGPT)70.32-3.33-0.511.00100.00100.00100.00100.00100.00
Random66.36-3.76-0.776.1437.7536.9111.2820.6929.05
MLM-Scoring64.77-4.03-0.887.0033.8730.397.2914.0921.46
SimCLS73.14-3.22-0.383.5052.1149.9326.7246.2460.72
SummaReranker71.60-3.25-0.413.6655.6348.4623.8942.4457.54
**PairRanker**72.97-3.14-0.373.2054.7657.7930.0850.6865.12

Usage Example

Since PairRanker contains some custom layers and tokens. We recommend use our pairranker with our llm-blender python repo. Otherwise, loading it directly with hugging face from_pretrained() API will encounter errors.

  • —First install llm-blender
bash
pip install git+https://github.com/yuchenlin/LLM-Blender.git
  • —Then use pairranker with the following code:
python
import llm_blender
# ranker config
ranker_config = llm_blender.RankerConfig()
ranker_config.ranker_type = "pairranker" # only supports pairranker now.
ranker_config.model_type = "deberta"
ranker_config.model_name = "microsoft/deberta-v3-large" # ranker backbone
ranker_config.load_checkpoint = "llm-blender/pair-ranker" # hugging face hub model path or your local ranker checkpoint <your checkpoint path>
ranker_config.cache_dir = "./hf_models" # hugging face model cache dir
ranker_config.source_maxlength = 128
ranker_config.candidate_maxlength = 128
ranker_config.n_tasks = 1 # number of singal that has been used to train the ranker. This checkpoint is trained using BARTScore only, thus being 1.
fuser_config = llm_blender.GenFuserConfig()
# ignore fuser config as we don't use it here. You can load it if you want
blender_config = llm_blender.BlenderConfig()
# blender config
blender_config.device = "cuda" # blender ranker and fuser device
blender = llm_blender.Blender(blender_config, ranker_config, fuser_config)
  • —Then you can rank candidates with the following function
python
inputs = ["input1", "input2"]
candidates_texts = [["candidate1 for input1", "candidatefor input1"], ["candidate1 for input2", "candidate2 for input2"]]
ranks = blender.rank(inputs, candidates_texts, return_scores=False, batch_size=2)
# ranks is a list of ranks where ranks[i][j] represents the ranks of candidate-j for input-i
  • —Using pairranker to directly compare two candidates
python
candidates_A = [cands[0] for cands in candidates]
candidates_B = [cands[1] for cands in candidates]
comparison_results = blender.compare(inputs, candidates_A, candidates_B)
# comparison_results is a list of bool, where element[i] denotes whether candidates_A[i] is better than candidates_B[i] for inputs[i]

See LLM-Blender Github README.md and jupyter file blender_usage.ipynb for detailed usage examples.