Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- ja
|
5 |
+
- en
|
6 |
+
pipeline_tag: text-generation
|
7 |
+
datasets:
|
8 |
+
- NTQAI/sharegpt-clean-ja
|
9 |
+
---
|
10 |
+
|
11 |
+
# chatntq-7b-jpntuned Card
|
12 |
+
|
13 |
+
## Model Details
|
14 |
+
|
15 |
+
ChatNTQ-7B-Japanese is a chat assistant trained by fine-tuning [BlinkDL/rwkv-4-world](https://huggingface.co/BlinkDL/rwkv-4-world) on user-shared conversations collected from ShareGPT.
|
16 |
+
|
17 |
+
- **Developed by:** [NTQAI](https://huggingface.co/NTQAI)
|
18 |
+
- **Model type:** An auto-regressive language model based on the transformer architecture.
|
19 |
+
- **License:** Commercial license
|
20 |
+
- **Finetuned from model:** [BlinkDL/rwkv-4-world/JPNtuned-7B-v1](https://huggingface.co/BlinkDL/rwkv-4-world/blob/main/RWKV-4-World-JPNtuned-7B-v1-OnlyForTest_76%25_trained-20230714-ctx4096.pth).
|
21 |
+
|
22 |
+
## Uses
|
23 |
+
|
24 |
+
```python
|
25 |
+
import os, gc, copy, torch
|
26 |
+
import gradio as gr
|
27 |
+
os.environ["RWKV_JIT_ON"] = '1'
|
28 |
+
os.environ["RWKV_CUDA_ON"] = '1'
|
29 |
+
from rwkv.model import RWKV
|
30 |
+
model_path = "chatntq-7b-jpntuned/ChatNTQ-7B-RWKV-world-JPNtuned-ctx2048.pth"
|
31 |
+
WORD_NAME = "rwkv_vocab_v20230424" # copy rwkv_vocab_v20230424.txt in ChatNTQ-7B-Japanese to the same folder test
|
32 |
+
ctx_limit = 1024
|
33 |
+
model = RWKV(model=model_path, strategy='cuda fp16i8 *24 -> cuda fp16')
|
34 |
+
from rwkv.utils import PIPELINE, PIPELINE_ARGS
|
35 |
+
pipeline = PIPELINE(model, WORD_NAME)
|
36 |
+
def generate_prompt(instruction):
|
37 |
+
return f"\x00Human: {instruction}\x00Assistant: "
|
38 |
+
|
39 |
+
def evaluate(
|
40 |
+
prompt,
|
41 |
+
token_count=1024,
|
42 |
+
temperature=1.2,
|
43 |
+
top_p=0.5,
|
44 |
+
presencePenalty = 0.4,
|
45 |
+
countPenalty = 0.4,
|
46 |
+
):
|
47 |
+
args = PIPELINE_ARGS(temperature = max(0.2, float(temperature)), top_p = float(top_p),
|
48 |
+
alpha_frequency = countPenalty,
|
49 |
+
alpha_presence = presencePenalty,
|
50 |
+
token_ban = [], # ban the generation of some tokens
|
51 |
+
token_stop = [0,1]) # stop generation whenever you see any token here
|
52 |
+
|
53 |
+
all_tokens = []
|
54 |
+
out_last = 0
|
55 |
+
out_str = ''
|
56 |
+
occurrence = {}
|
57 |
+
state = None
|
58 |
+
prompt = generate_prompt(prompt)
|
59 |
+
print(prompt)
|
60 |
+
for i in range(int(token_count)):
|
61 |
+
out, state = model.forward(pipeline.encode(prompt)[-ctx_limit:] if i == 0 else [token], state)
|
62 |
+
for n in occurrence:
|
63 |
+
out[n] -= (args.alpha_presence + occurrence[n] * args.alpha_frequency)
|
64 |
+
|
65 |
+
token = pipeline.sample_logits(out, temperature=args.temperature, top_p=args.top_p)
|
66 |
+
if token in args.token_stop:
|
67 |
+
break
|
68 |
+
all_tokens += [token]
|
69 |
+
if token not in occurrence:
|
70 |
+
occurrence[token] = 1
|
71 |
+
else:
|
72 |
+
occurrence[token] += 1
|
73 |
+
|
74 |
+
tmp = pipeline.decode(all_tokens[out_last:])
|
75 |
+
if '\ufffd' not in tmp:
|
76 |
+
out_str += tmp
|
77 |
+
out_last = i + 1
|
78 |
+
gc.collect()
|
79 |
+
torch.cuda.empty_cache()
|
80 |
+
return out_str
|
81 |
+
if __name__ == "__main__":
|
82 |
+
question = "東京の人口はどれくらいですか?"
|
83 |
+
response = evaluate(question)
|
84 |
+
```
|
85 |
+
### Contact information
|
86 |
+
For personal communication related to this project, please contact Nha Nguyen Van (nha282@gmail.com).
|