crazyjames
commited on
Commit
•
67b1b4f
1
Parent(s):
a50be2e
update
Browse files
README.md
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
- zh
|
5 |
+
library_name: transformers
|
6 |
+
tags:
|
7 |
+
- Long Context
|
8 |
+
- chatglm
|
9 |
+
- llama
|
10 |
+
datasets:
|
11 |
+
- THUDM/LongCite-6k
|
12 |
+
pipeline_tag: text-generation
|
13 |
+
---
|
14 |
+
# LongCite-glm4-9b
|
15 |
+
|
16 |
+
<p align="center">
|
17 |
+
🤗 <a href="https://huggingface.co/datasets/THUDM/LongCite-45k" target="_blank">[LongCite Dataset] </a> • 💻 <a href="https://github.com/THUDM/LongCite" target="_blank">[Github Repo]</a> • 📃 <a href="https://arxiv.org/abs/" target="_blank">[LongCite Paper]</a>
|
18 |
+
</p>
|
19 |
+
|
20 |
+
LongCite-glm4-9b is trained based on [glm-4-9b](https://huggingface.co/THUDM/glm-4-9b), and is capable of generating fine-grained citations in long-context question answering. The model supports a maximum context window of up to 128K tokens.
|
21 |
+
|
22 |
+
Environment: Same environment requirement as [glm-4-9b-chat](https://huggingface.co/THUDM/glm-4-9b-chat) (`transforemrs>=4.43.0`).
|
23 |
+
|
24 |
+
A simple demo for deployment of the model:
|
25 |
+
```python
|
26 |
+
import torch
|
27 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
28 |
+
|
29 |
+
tokenizer = AutoTokenizer.from_pretrained('THUDM/LongCite-glm4-9b', trust_remote_code=True)
|
30 |
+
model = AutoModelForCausalLM.from_pretrained('THUDM/LongCite-glm4-9b', torch_dtype=torch.bfloat16, trust_remote_code=True, device_map='auto')
|
31 |
+
|
32 |
+
context = '''
|
33 |
+
W. Russell Todd, 94, United States Army general (b. 1928). February 13. Tim Aymar, 59, heavy metal singer (Pharaoh) (b. 1963). Marshall \"Eddie\" Conway, 76, Black Panther Party leader (b. 1946). Roger Bonk, 78, football player (North Dakota Fighting Sioux, Winnipeg Blue Bombers) (b. 1944). Conrad Dobler, 72, football player (St. Louis Cardinals, New Orleans Saints, Buffalo Bills) (b. 1950). Brian DuBois, 55, baseball player (Detroit Tigers) (b. 1967). Robert Geddes, 99, architect, dean of the Princeton University School of Architecture (1965–1982) (b. 1923). Tom Luddy, 79, film producer (Barfly, The Secret Garden), co-founder of the Telluride Film Festival (b. 1943). David Singmaster, 84, mathematician (b. 1938).
|
34 |
+
'''
|
35 |
+
query = "What was Robert Geddes' profession?"
|
36 |
+
result = model.query_longcite(context, query, tokenizer=tokenizer, max_input_length=128000, max_new_tokens=1024)
|
37 |
+
|
38 |
+
print("Answer:\n{}\n".format(result['answer']))
|
39 |
+
print("Statement with citations:\n{}\n".format(
|
40 |
+
json.dumps(result['statements_with_citations'], indent=2, ensure_ascii=False)))
|
41 |
+
print("Context (divided into sentences):\n{}\n".format(result['splited_context']))
|
42 |
+
```
|
43 |
+
|
44 |
+
You can also deploy the model with [vllm](https://github.com/vllm-project/vllm). See the code example in [vllm_inference.py](https://huggingface.co/THUDM/LongCite-glm4-9b/blob/main/vllm_inference.py).
|
45 |
+
|
46 |
+
## License
|
47 |
+
[glm-4-9b License](https://huggingface.co/THUDM/glm-4-9b-chat/blob/main/LICENSE)
|
48 |
+
|
49 |
+
## Citation
|
50 |
+
|
51 |
+
If you find our work useful, please consider citing LongCite:
|
52 |
+
|
53 |
+
```
|
54 |
+
@article{zhang2024LongCite,
|
55 |
+
title = {LongCite: Enabling LLMs to Generate Fine-grained Citations in Long-context QA}
|
56 |
+
author={Jiajie Zhang and Yushi Bai and Xin Lv and Wanjun Gu and Danqing Liu and Minhao Zou and Shulin Cao and Lei Hou and Yuxiao Dong and Ling Feng and Juanzi Li},
|
57 |
+
journal={arXiv preprint arXiv:},
|
58 |
+
year={2024}
|
59 |
+
}
|
60 |
+
```
|