ja
library_name: transformers
pipeline_tag: text-generation
license: llama2
model_type: llama
Swallow
Our Swallow model has undergone continual pre-training from the Llama 2 family, primarily with the addition of Japanese language data. The tuned versions use supervised fine-tuning (SFT).
Links to other models can be found in the index.
Model Release Updates
We are excited to share the release schedule for our latest models:
Tokenizer: This model employs a tokenizer that features a broadened vocabulary based on Japanese data. This allows for a more efficient representation of text using fewer tokens, leading to a notably faster inference process.
Contact: swallow[at]nlp.c.titech.ac.jp
Base Model Performance
Japanese tasks
Model
Size
JCommonsenseQA
JEMHopQA
NIILC
JSQuAD
XL-Sum
MGSM
WMT20-en-ja
WMT20-ja-en
4-shot
4-shot
4-shot
4-shot
1-shot
4-shot
4-shot
4-shot
Llama 2
7B
0.3852
0.4240
0.3410
0.7917
0.1905
0.0760
0.1783
0.1738
Swallow
7B
0.4808
0.5078
0.5968
0.8573
0.1830
0.1240
0.2510
0.1511
Swallow-Plus
7B
0.5478
0.5493
0.6030
0.8544
0.1806
0.1360
0.2568
0.1441
Swallow-NVE
7B
0.5433
0.5425
0.5729
0.8684
0.2117
0.1200
0.2405
0.1512
Llama 2
13B
0.6997
0.4415
0.4170
0.8533
0.2139
0.1320
0.2146
0.1982
Swallow
13B
0.7837
0.5063
0.6398
0.9005
0.2168
0.2040
0.2720
0.1771
Swallow-NVE
13B
0.7712
0.5438
0.6351
0.9030
0.2294
0.2120
0.2735
0.1817
Llama 2
70B
0.8686
0.4656
0.5256
0.9080
0.2361
0.3560
0.2643
0.2398
Swallow
70B
0.9348
0.6290
0.6960
0.9176
0.2266
0.4840
0.3043
0.2298
Swallow-NVE
70B
0.9410
0.5759
0.7024
0.9254
0.2758
0.4720
0.3042
0.2322
English tasks
Model
Size
OpenBookQA
TriviaQA
HellaSwag
SQuAD2.0
XWINO
GSM8K
8-shot
8-shot
8-shot
8-shot
8-shot
8-shot
Llama 2
7B
0.3580
0.6265
0.5860
0.3207
0.9049
0.1410
Swallow
7B
0.3180
0.4836
0.5308
0.3125
0.8817
0.1130
Swallow-Plus
7B
0.3280
0.4558
0.5259
0.3134
0.8929
0.1061
Swallow-NVE
7B
0.3180
0.5079
0.5329
0.2919
0.8817
0.0986
Llama 2
13B
0.3760
0.7255
0.6148
0.3681
0.9140
0.2403
Swallow
13B
0.3500
0.5852
0.5660
0.3406
0.9075
0.2039
Swallow-NVE
13B
0.3460
0.6025
0.5700
0.3478
0.9006
0.1751
Llama 2
70B
0.4280
0.8239
0.6742
0.3770
0.9290
0.5284
Swallow
70B
0.4220
0.7756
0.6458
0.3745
0.9204
0.4867
Swallow-NVE
70B
0.4240
0.7817
0.6439
0.3451
0.9256
0.4943
Evaluation Benchmarks
Japanese evaluation benchmarks
We used llm-jp-eval(v1.0.0) and JP Language Model Evaluation Harness(commit #9b42d41). The details are as follows:
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
34model_name ="tokyotech-llm/Swallow-7b-instruct-hf"56tokenizer = AutoTokenizer.from_pretrained(model_name)7model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto")8910PROMPT_DICT ={11"prompt_input":(12"以下に、あるタスクを説明する指示があり、それに付随する入力が更なる文脈を提供しています。"13"リクエストを適切に完了するための回答を記述してください。\n\n"14"### 指示:\n{instruction}\n\n### 入力:\n{input}\n\n### 応答:"1516),17"prompt_no_input":(18"以下に、あるタスクを説明する指示があります。"19"リクエストを適切に完了するための回答を記述してください。\n\n"20"### 指示:\n{instruction}\n\n### 応答:"21),22}2324defcreate_prompt(instruction,input=None):25"""
26 Generates a prompt based on the given instruction and an optional input.
27 If input is provided, it uses the 'prompt_input' template from PROMPT_DICT.
28 If no input is provided, it uses the 'prompt_no_input' template.
2930 Args:
31 instruction (str): The instruction describing the task.
32 input (str, optional): Additional input providing context for the task. Default is None.
3334 Returns:
35 str: The generated prompt.
36 """37ifinput:38# Use the 'prompt_input' template when additional input is provided39return PROMPT_DICT["prompt_input"].format(instruction=instruction,input=input)40else:41# Use the 'prompt_no_input' template when no additional input is provided42return PROMPT_DICT["prompt_no_input"].format(instruction=instruction)4344# Example usage45instruction_example ="以下のトピックに関する詳細な情報を提供してください。"46input_example ="東京工業大学の主なキャンパスについて教えてください"47prompt = create_prompt(instruction_example, input_example)4849input_ids = tokenizer.encode(50 prompt,51 add_special_tokens=False,52 return_tensors="pt"53)5455tokens = model.generate(56 input_ids.to(device=model.device),57 max_new_tokens=128,58 temperature=0.99,59 top_p=0.95,60 do_sample=True,61)6263out = tokenizer.decode(tokens[0], skip_special_tokens=True)64print(out)65
The models released here are still in the early stages of our research and development and have not been tuned to ensure outputs align with human intent and safety considerations.
Acknowledgements
We thank Meta Research for releasing Llama 2 under an open license for others to build on.
@misc{fujii2024continual,
title={Continual Pre-Training for Cross-Lingual LLM Adaptation: Enhancing Japanese Language Capabilities},
author={Kazuki Fujii and Taishi Nakamura and Mengsay Loem and Hiroki Iida and Masanari Ohi and Kakeru Hattori and Hirai Shota and Sakae Mizuki and Rio Yokota and Naoaki Okazaki},
year={2024},
eprint={2404.17790},
archivePrefix={arXiv},
primaryClass={cs.CL}
}