tokyotech-llm/Swallow-7b-NVE-instruct-hf

Model

3

stars

33

commits

1

linked in READMEs

Oct 8, 2024

updated

endpoints_compatible
llama
safetensors
text-generation
text-generation-inference
transformers

README

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:

Swallow Model Index

ModelSwallow-hfSwallow-instruct-hfSwallow-instruct-v0.1
7BLinkLinkLink
7B-PlusLinkN/AN/A
13BLinkLinkLink
70BLinkLinkLink

Swallow Model Index NVE (No Vocabulary Expansion)

ModelSwallow-NVE-hfSwallow-NVE-instruct-hf
7BLinkLink
13BLinkN/A
70BLinkLink

logo

This repository provides large language models developed by TokyoTech-LLM. Read our blog post or our paper

Model Details

  • Model type: Please refer to LLaMA-2 technical report for details on the model architecture.
  • Language(s): Japanese English
  • Library: Megatron-LM
  • 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

ModelSizeJCommonsenseQAJEMHopQANIILCJSQuADXL-SumMGSMWMT20-en-jaWMT20-ja-en
4-shot4-shot4-shot4-shot1-shot4-shot4-shot4-shot
Llama 27B0.38520.42400.34100.79170.19050.07600.17830.1738
Swallow7B0.48080.50780.59680.85730.18300.12400.25100.1511
Swallow-Plus7B0.54780.54930.60300.85440.18060.13600.25680.1441
Swallow-NVE7B0.54330.54250.57290.86840.21170.12000.24050.1512
Llama 213B0.69970.44150.41700.85330.21390.13200.21460.1982
Swallow13B0.78370.50630.63980.90050.21680.20400.27200.1771
Swallow-NVE13B0.77120.54380.63510.90300.22940.21200.27350.1817
Llama 270B0.86860.46560.52560.90800.23610.35600.26430.2398
Swallow70B0.93480.62900.69600.91760.22660.48400.30430.2298
Swallow-NVE70B0.94100.57590.70240.92540.27580.47200.30420.2322

English tasks

ModelSizeOpenBookQATriviaQAHellaSwagSQuAD2.0XWINOGSM8K
8-shot8-shot8-shot8-shot8-shot8-shot
Llama 27B0.35800.62650.58600.32070.90490.1410
Swallow7B0.31800.48360.53080.31250.88170.1130
Swallow-Plus7B0.32800.45580.52590.31340.89290.1061
Swallow-NVE7B0.31800.50790.53290.29190.88170.0986
Llama 213B0.37600.72550.61480.36810.91400.2403
Swallow13B0.35000.58520.56600.34060.90750.2039
Swallow-NVE13B0.34600.60250.57000.34780.90060.1751
Llama 270B0.42800.82390.67420.37700.92900.5284
Swallow70B0.42200.77560.64580.37450.92040.4867
Swallow-NVE70B0.42400.78170.64390.34510.92560.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:

  • Multiple-choice question answering (JCommonsenseQA [Kurihara+, 2022])
  • Open-ended question answering (JEMHopQA [Ishii+, 2023])
  • Open-ended question answering (NIILC [Sekine, 2003])
  • Machine reading comprehension (JSQuAD [Kurihara+, 2022])
  • Automatic summarization (XL-Sum [Hasan+, 2021])
  • Machine translation (WMT2020 ja-en [Barrault+, 2020])
  • Machine translation (WMT2020 en-ja [Barrault+, 2020])
  • Mathematical reasoning (MGSM [Shi+, 2023])

English evaluation benchmarks

We used the Language Model Evaluation Harness(v.0.3.0). The details are as follows:

  • Multiple-choice question answering (OpenBookQA [Mihaylov+, 2018])
  • Open-ended question answering (TriviaQA [Joshi+, 2017])
  • Machine reading comprehension (SQuAD 2.0 [Rajpurkar+, 2018])
  • Commonsense reasoning (XWINO [Tikhonov & Ryabinin, 2021])
  • Natural language inference (HellaSwag [Zellers+, 2019])
  • Mathematical reasoning (GSM8k [Cobbe+, 2021])

Usage

First install additional dependencies in requirements.txt:

pip install -r requirements.txt

Use the instruct model

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "tokyotech-llm/Swallow-7b-instruct-hf"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto")


PROMPT_DICT = {
    "prompt_input": (
        "以下に、あるタスクを説明する指示があり、それに付随する入力が更なる文脈を提供しています。"
        "リクエストを適切に完了するための回答を記述してください。\n\n"
        "### 指示:\n{instruction}\n\n### 入力:\n{input}\n\n### 応答:"

    ),
    "prompt_no_input": (
        "以下に、あるタスクを説明する指示があります。"
        "リクエストを適切に完了するための回答を記述してください。\n\n"
        "### 指示:\n{instruction}\n\n### 応答:"
    ),
}

def create_prompt(instruction, input=None):
    """
    Generates a prompt based on the given instruction and an optional input.
    If input is provided, it uses the 'prompt_input' template from PROMPT_DICT.
    If no input is provided, it uses the 'prompt_no_input' template.

    Args:
        instruction (str): The instruction describing the task.
        input (str, optional): Additional input providing context for the task. Default is None.

    Returns:
        str: The generated prompt.
    """
    if input:
        # Use the 'prompt_input' template when additional input is provided
        return PROMPT_DICT["prompt_input"].format(instruction=instruction, input=input)
    else:
        # Use the 'prompt_no_input' template when no additional input is provided
        return PROMPT_DICT["prompt_no_input"].format(instruction=instruction)

# Example usage
instruction_example = "以下のトピックに関する詳細な情報を提供してください。"
input_example = "東京工業大学の主なキャンパスについて教えてください"
prompt = create_prompt(instruction_example, input_example)

input_ids = tokenizer.encode(
    prompt,
    add_special_tokens=False,
    return_tensors="pt"
)

tokens = model.generate(
    input_ids.to(device=model.device),
    max_new_tokens=128,
    temperature=0.99,
    top_p=0.95,
    do_sample=True,
)

out = tokenizer.decode(tokens[0], skip_special_tokens=True)
print(out)

Use the base model

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "tokyotech-llm/Swallow-7b-hf"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")

prompt = "東京工業大学の主なキャンパスは、"
input_ids = tokenizer.encode(
    prompt,
    add_special_tokens=False,
    return_tensors="pt"
)
tokens = model.generate(
    input_ids.to(device=model.device),
    max_new_tokens=128,
    temperature=0.99,
    top_p=0.95,
    do_sample=True,
)

out = tokenizer.decode(tokens[0], skip_special_tokens=True)
print(out)

Training Datasets

Continual Pre-Training

The following datasets were used for continual pre-training.

Instruction Tuning

The following datasets were used for the instruction tuning.

Risks and Limitations

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.

Our project is supported by the ABCI Large-scale Language Model Building Support Program of the National Institute of Advanced Industrial Science and Technology.

License

Llama 2 is licensed under the LLAMA 2 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.

Authors

Here are the team members:

How to cite

If you find our work helpful, please feel free to cite us.

@inproceedings{Fujii:COLM2024,
   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},
   booktitle="Proceedings of the First Conference on Language Modeling",
   series={COLM},
   pages="(to appear)",
   year="2024",
   month=oct,
   address={University of Pennsylvania, USA},
}

@inproceedings{Okazaki:COLM2024,
   title={Building a Large Japanese Web Corpus for Large Language Models},
   author={Naoaki Okazaki and Kakeru Hattori and Hirai Shota and Hiroki
Iida and Masanari Ohi and Kazuki Fujii and Taishi Nakamura and Mengsay
Loem and Rio Yokota and Sakae Mizuki},
   booktitle="Proceedings of the First Conference on Language Modeling",
   series={COLM},
   pages="(to appear)",
   year="2024",
   month=oct,
   address={University of Pennsylvania, USA},
}

Contributors

Taishi-N324

21 commits

okoge

11 commits

KF
Kazuki Fujii

1 commits

tokyotech-llm/Swallow-7b-NVE-instruct-hf

Model

3

stars

33

commits

1

linked in READMEs

Oct 8, 2024

updated

endpoints_compatible
llama
safetensors
text-generation
text-generation-inference
transformers

README

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:

Swallow Model Index

ModelSwallow-hfSwallow-instruct-hfSwallow-instruct-v0.1
7BLinkLinkLink
7B-PlusLinkN/AN/A
13BLinkLinkLink
70BLinkLinkLink

Swallow Model Index NVE (No Vocabulary Expansion)

ModelSwallow-NVE-hfSwallow-NVE-instruct-hf
7BLinkLink
13BLinkN/A
70BLinkLink

logo

This repository provides large language models developed by TokyoTech-LLM. Read our blog post or our paper

Model Details

  • Model type: Please refer to LLaMA-2 technical report for details on the model architecture.
  • Language(s): Japanese English
  • Library: Megatron-LM
  • 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

ModelSizeJCommonsenseQAJEMHopQANIILCJSQuADXL-SumMGSMWMT20-en-jaWMT20-ja-en
4-shot4-shot4-shot4-shot1-shot4-shot4-shot4-shot
Llama 27B0.38520.42400.34100.79170.19050.07600.17830.1738
Swallow7B0.48080.50780.59680.85730.18300.12400.25100.1511
Swallow-Plus7B0.54780.54930.60300.85440.18060.13600.25680.1441
Swallow-NVE7B0.54330.54250.57290.86840.21170.12000.24050.1512
Llama 213B0.69970.44150.41700.85330.21390.13200.21460.1982
Swallow13B0.78370.50630.63980.90050.21680.20400.27200.1771
Swallow-NVE13B0.77120.54380.63510.90300.22940.21200.27350.1817
Llama 270B0.86860.46560.52560.90800.23610.35600.26430.2398
Swallow70B0.93480.62900.69600.91760.22660.48400.30430.2298
Swallow-NVE70B0.94100.57590.70240.92540.27580.47200.30420.2322

English tasks

ModelSizeOpenBookQATriviaQAHellaSwagSQuAD2.0XWINOGSM8K
8-shot8-shot8-shot8-shot8-shot8-shot
Llama 27B0.35800.62650.58600.32070.90490.1410
Swallow7B0.31800.48360.53080.31250.88170.1130
Swallow-Plus7B0.32800.45580.52590.31340.89290.1061
Swallow-NVE7B0.31800.50790.53290.29190.88170.0986
Llama 213B0.37600.72550.61480.36810.91400.2403
Swallow13B0.35000.58520.56600.34060.90750.2039
Swallow-NVE13B0.34600.60250.57000.34780.90060.1751
Llama 270B0.42800.82390.67420.37700.92900.5284
Swallow70B0.42200.77560.64580.37450.92040.4867
Swallow-NVE70B0.42400.78170.64390.34510.92560.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:

  • Multiple-choice question answering (JCommonsenseQA [Kurihara+, 2022])
  • Open-ended question answering (JEMHopQA [Ishii+, 2023])
  • Open-ended question answering (NIILC [Sekine, 2003])
  • Machine reading comprehension (JSQuAD [Kurihara+, 2022])
  • Automatic summarization (XL-Sum [Hasan+, 2021])
  • Machine translation (WMT2020 ja-en [Barrault+, 2020])
  • Machine translation (WMT2020 en-ja [Barrault+, 2020])
  • Mathematical reasoning (MGSM [Shi+, 2023])

English evaluation benchmarks

We used the Language Model Evaluation Harness(v.0.3.0). The details are as follows:

  • Multiple-choice question answering (OpenBookQA [Mihaylov+, 2018])
  • Open-ended question answering (TriviaQA [Joshi+, 2017])
  • Machine reading comprehension (SQuAD 2.0 [Rajpurkar+, 2018])
  • Commonsense reasoning (XWINO [Tikhonov & Ryabinin, 2021])
  • Natural language inference (HellaSwag [Zellers+, 2019])
  • Mathematical reasoning (GSM8k [Cobbe+, 2021])

Usage

First install additional dependencies in requirements.txt:

pip install -r requirements.txt

Use the instruct model

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "tokyotech-llm/Swallow-7b-instruct-hf"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto")


PROMPT_DICT = {
    "prompt_input": (
        "以下に、あるタスクを説明する指示があり、それに付随する入力が更なる文脈を提供しています。"
        "リクエストを適切に完了するための回答を記述してください。\n\n"
        "### 指示:\n{instruction}\n\n### 入力:\n{input}\n\n### 応答:"

    ),
    "prompt_no_input": (
        "以下に、あるタスクを説明する指示があります。"
        "リクエストを適切に完了するための回答を記述してください。\n\n"
        "### 指示:\n{instruction}\n\n### 応答:"
    ),
}

def create_prompt(instruction, input=None):
    """
    Generates a prompt based on the given instruction and an optional input.
    If input is provided, it uses the 'prompt_input' template from PROMPT_DICT.
    If no input is provided, it uses the 'prompt_no_input' template.

    Args:
        instruction (str): The instruction describing the task.
        input (str, optional): Additional input providing context for the task. Default is None.

    Returns:
        str: The generated prompt.
    """
    if input:
        # Use the 'prompt_input' template when additional input is provided
        return PROMPT_DICT["prompt_input"].format(instruction=instruction, input=input)
    else:
        # Use the 'prompt_no_input' template when no additional input is provided
        return PROMPT_DICT["prompt_no_input"].format(instruction=instruction)

# Example usage
instruction_example = "以下のトピックに関する詳細な情報を提供してください。"
input_example = "東京工業大学の主なキャンパスについて教えてください"
prompt = create_prompt(instruction_example, input_example)

input_ids = tokenizer.encode(
    prompt,
    add_special_tokens=False,
    return_tensors="pt"
)

tokens = model.generate(
    input_ids.to(device=model.device),
    max_new_tokens=128,
    temperature=0.99,
    top_p=0.95,
    do_sample=True,
)

out = tokenizer.decode(tokens[0], skip_special_tokens=True)
print(out)

Use the base model

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "tokyotech-llm/Swallow-7b-hf"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")

prompt = "東京工業大学の主なキャンパスは、"
input_ids = tokenizer.encode(
    prompt,
    add_special_tokens=False,
    return_tensors="pt"
)
tokens = model.generate(
    input_ids.to(device=model.device),
    max_new_tokens=128,
    temperature=0.99,
    top_p=0.95,
    do_sample=True,
)

out = tokenizer.decode(tokens[0], skip_special_tokens=True)
print(out)

Training Datasets

Continual Pre-Training

The following datasets were used for continual pre-training.

Instruction Tuning

The following datasets were used for the instruction tuning.

Risks and Limitations

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.

Our project is supported by the ABCI Large-scale Language Model Building Support Program of the National Institute of Advanced Industrial Science and Technology.

License

Llama 2 is licensed under the LLAMA 2 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.

Authors

Here are the team members:

How to cite

If you find our work helpful, please feel free to cite us.

@inproceedings{Fujii:COLM2024,
   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},
   booktitle="Proceedings of the First Conference on Language Modeling",
   series={COLM},
   pages="(to appear)",
   year="2024",
   month=oct,
   address={University of Pennsylvania, USA},
}

@inproceedings{Okazaki:COLM2024,
   title={Building a Large Japanese Web Corpus for Large Language Models},
   author={Naoaki Okazaki and Kakeru Hattori and Hirai Shota and Hiroki
Iida and Masanari Ohi and Kazuki Fujii and Taishi Nakamura and Mengsay
Loem and Rio Yokota and Sakae Mizuki},
   booktitle="Proceedings of the First Conference on Language Modeling",
   series={COLM},
   pages="(to appear)",
   year="2024",
   month=oct,
   address={University of Pennsylvania, USA},
}

Contributors

Taishi-N324

21 commits

okoge

11 commits

KF
Kazuki Fujii

1 commits