zyznull commited on
Commit
9e6c5d4
1 Parent(s): 4efa8bc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +58 -0
README.md CHANGED
@@ -1,3 +1,61 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+
6
+ # RankingGPT-bloom-3b
7
+
8
+ RankingGPT is a text ranker based on large language models with significant in-domain and out-domain effectiveness.
9
+ We provide RankingGPT in different sizes and types, including bloom-560m, bloom-1b1, bloom-3b, bloom-7b, llama2-7b, baichuan2-7b and qwen-7b.
10
+
11
+ More details please refer to our [paper](https://arxiv.org/abs/2311.16720) and [github](https://github.com/Alibaba-NLP/RankingGPT).
12
+
13
+
14
+ ## Usage
15
+
16
+ Code example
17
+ ```python
18
+ import torch
19
+ from transformers import AutoTokenizer, AutoModelForCausalLM
20
+
21
+ tokenizer = AutoTokenizer.from_pretrained('zyznull/RankingGPT-bloom-3b')
22
+ model = AutoModelForCausalLM.from_pretrained('zyznull/RankingGPT-bloom-3b').eval()
23
+
24
+ query='when should a baby walk'
25
+ document='Most babies start to walk around 13 months, but your baby may start walking as early as 9 or 10 months or as late as 15 or 16 months.'
26
+
27
+ context=f'Document: {document} Query:'
28
+ example=context+query
29
+
30
+ context_enc = tokenizer.encode(context, add_special_tokens=False)
31
+ continuation_enc = tokenizer.encode(query, add_special_tokens=False)
32
+ model_input = torch.tensor(context_enc+continuation_enc[:-1])
33
+ continuation_len = len(continuation_enc)
34
+ input_len, = model_input.shape
35
+
36
+
37
+ with torch.no_grad():
38
+ logprobs = torch.nn.functional.log_softmax(model(model_input.unsqueeze(dim=0))[0], dim=-1)[0]
39
+
40
+ logprobs = logprobs[input_len-continuation_len:]
41
+ logprobs = torch.gather(logprobs, 1, torch.tensor(continuation_enc).unsqueeze(-1)).squeeze(-1)
42
+ score = torch.sum(logprobs)/logprobs.shape[0]
43
+
44
+ print(f"Document: {document[:20] + '...'} Score: {score}")
45
+ ```
46
+
47
+
48
+ ### Citation
49
+
50
+ If you find our paper or models helpful, please consider citing them as follows:
51
+
52
+ ```
53
+ @misc{zhang2023rankinggpt,
54
+ title={RankingGPT: Empowering Large Language Models in Text Ranking with Progressive Enhancement},
55
+ author={Longhui Zhang and Yanzhao Zhang and Dingkun Long and Pengjun Xie and Meishan Zhang and Min Zhang},
56
+ year={2023},
57
+ eprint={2311.16720},
58
+ archivePrefix={arXiv},
59
+ primaryClass={cs.IR}
60
+ }
61
+ ```