zyznull commited on
Commit
12c4770
·
1 Parent(s): dc1807c

Update README.md

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