File size: 5,213 Bytes
36dbf43
 
 
 
3b03f80
36dbf43
 
 
 
7fc0fb2
36dbf43
 
a2d0a32
3b03f80
36dbf43
41d5bf3
36dbf43
 
7fc0fb2
 
 
bdb23c0
36dbf43
7fc0fb2
36dbf43
7fc0fb2
36dbf43
bdb23c0
caa2d88
7fc0fb2
 
 
 
 
 
 
 
 
 
bdb23c0
7fc0fb2
bdb23c0
7fc0fb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0840db4
7fc0fb2
 
 
 
36dbf43
 
 
7fc0fb2
 
 
 
 
36dbf43
 
 
 
 
 
7fc0fb2
 
 
36dbf43
7fc0fb2
3b03f80
36dbf43
 
 
7fc0fb2
 
 
 
 
36dbf43
7929455
36dbf43
 
 
1bb3cb8
36dbf43
 
 
0840db4
36dbf43
7fc0fb2
36dbf43
7fc0fb2
 
36dbf43
 
 
 
 
7fc0fb2
 
 
 
 
 
 
 
 
 
36dbf43
 
 
 
 
 
3b03f80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
language:
- en
- ja
license: cc-by-nc-4.0
library_name: transformers
pipeline_tag: text-generation
---

# PLaMo-13B-Instruct-NC

## Model Description
PLaMo-13B-Instruct-NC is a noncommercial instruct fine-tuned model built upon the 8192 context length version of [PLaMo-13B](https://huggingface.co/pfnet/plamo-13b) text generation model. PLaMo-13B-Instruct-NC is fine-tuned using multiple publicly available Japanese datasets.
This model is released under CC-BY-NC-4.0.

[PLaMo-13B-Instruct Release blog (Japanese)](https://tech.preferred.jp/ja/blog/llm-plamo-instruct/)


## Usage
Install the required libraries as follows:
```sh
>>> python -m pip install numpy safetensors sentencepiece torch transformers accelerate

```

Execute the following python code:
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained(
    "pfnet/plamo-13b-instruct-nc",
    trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
    "pfnet/plamo-13b-instruct-nc",
    trust_remote_code=True,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)
```

```python
def completion(prompt: str, max_new_tokens: int = 128) -> str:
    inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
    generated_ids = model.generate(
        inputs.input_ids,
        eos_token_id=2,
        pad_token_id=3,
        max_new_tokens=max_new_tokens,
        temperature=1,
        top_p=0.95,
        top_k=50,
        do_sample=True,
    )
    return tokenizer.decode(generated_ids[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)

def generate_prompt(messages: list) -> str:
    sep = "\n\n### "
    prompt = [
        "以下はタスクを説明する指示で、文脈を説明した入力とペアになっています。",
        "要求を適切に補完するよう応答を書いてください。",
    ]
    roles = {"instruction": "指示", "response": "応答", "input": "入力"}
    for msg in messages:
        prompt.append(sep + roles[msg["role"]] + ":\n" + msg['content'])
    prompt.append(sep + roles["response"] + ":\n")
    return "".join(prompt)
```

```python
prompt = generate_prompt([
    {"role": "instruction", "content": "日本の首都はどこですか?"},
    # {"role": "input", "content": "..."}  ## An extra input (optional)
])
print(completion(prompt, max_new_tokens=128))
```

## Model Details

- Model size: 13B
- Trained tokens: 1.5T tokens (English: 1.32T tokens, Japanese: 0.18T tokens)
- Tokenizer: sentencepiece tokenizer trained on a subset of the pretraining datasets.
- Context length: 8192
- Developed by: Preferred Networks, Inc
- Model type: Causal decoder-only
- Language(s): Japanese and English
- License: CC-BY-NC-4.0

## Training Dataset

- [Stanford Alpaca (Japanese translation)](https://huggingface.co/datasets/fujiki/japanese_alpaca_data)
- [databricks-dolly-15k (Japanese translation)](https://huggingface.co/datasets/kunishou/databricks-dolly-15k-ja)
- [Anthropic HH-RLHF (Japanese translation, subset)](https://huggingface.co/datasets/fujiki/japanese_hh-rlhf-49k)
- [OpenAssistant Conversations Dataset (Japanese translation, oasst1)](https://huggingface.co/datasets/kunishou/oasst1-89k-ja)
- [Wikinews subset of Izumi-lab llm-japanese-dataset](https://huggingface.co/datasets/izumi-lab/llm-japanese-dataset)

For the pretraining model, see [PLaMo-13B](https://huggingface.co/pfnet/plamo-13b).


## Bias, Risks, and Limitations
PLaMo-13B-Instruct-NC is a new technology that carries risks with use. Testing conducted to date has been in English and Japanese, and has not covered, nor could it cover all scenarios. For these reasons, as with all LLMs, PLaMo-13B-Instruct-NC’s potential outputs cannot be predicted in advance, and the model may in some instances produce inaccurate, biased or other objectionable responses to user prompts. Therefore, before deploying any applications of PLaMo-13B-Instruct-NC, developers should perform safety testing and tuning tailored to their specific applications of the model.

## How to cite
```tex
@online{PLaMoInstructNC2023Introducing,
    author    = {Preferred Networks, Inc},
    title     = {PLaMo-13B-Instruct-NC},
    year      = {2023},
    url       = {https://huggingface.co/pfnet/plamo-13b-instruct-nc},
    urldate   = {2023-10-26}
}
```

## References
```tex
@misc{alpaca,
  author = {Rohan Taori and Ishaan Gulrajani and Tianyi Zhang and Yann Dubois and Xuechen Li and Carlos Guestrin and Percy Liang and Tatsunori B. Hashimoto },
  title = {Stanford Alpaca: An Instruction-following LLaMA model},
  year = {2023},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/tatsu-lab/stanford_alpaca}},
}
```
```tex
@article{touvron2023llama,
  title={LLaMA: Open and Efficient Foundation Language Models},
  author={Touvron, Hugo and Lavril, Thibaut and Izacard, Gautier and Martinet, Xavier and Lachaux, Marie-Anne and Lacroix, Timoth{\'e}e and Rozi{\`e}re, Baptiste and Goyal, Naman and Hambro, Eric and Azhar, Faisal and Rodriguez, Aurelien and Joulin, Armand and Grave, Edouard and Lample, Guillaume},
  journal={arXiv preprint arXiv:2302.13971},
  year={2023}
}
```