(English part follows Japanese one.)

byGPT-JP-multi-lm-head 6.5B alpha

バイト単位のtokenizerを採用した,日本語言語モデルです。 一度に4tokens (bytes) ずつ予測するための,複数のlmヘッドを持つアーキテクチャを採用しています。 また,multi byte predictionに適した独自のUnicode encodingを採用しています。 現在開発段階のモデルであり,十分な性能には達していません。

利用方法

transformers version 4.56.1 において、動作確認しています。 他のバージョンでは動作しない可能性があります。

import argparse

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer


SAMPLE_INPUT_TEXTS = [
    "日本三景一覧:\n1. 広島県, 宮島\n2. 京都府, 天橋立\n3. 宮城県, ",
    "原文: I like to play soccer. 訳文: 私はサッカーをするのが好きです。\n原文: She enjoys reading books. 訳文: 彼女は本を読むのが好きです。\n原文: They went to the park. 訳文:",
]

def main(args):
    torch.manual_seed(args.seed)
    device = torch.device("cuda")

    tokenizer = AutoTokenizer.from_pretrained(
        args.model_name_or_path,
        trust_remote_code=True,
    )
    model = AutoModelForCausalLM.from_pretrained(
        args.model_name_or_path,
        dtype=torch.bfloat16,
        trust_remote_code=True,
    )
    model.to(device)
    model.eval()

    input_texts = [f"{tokenizer.bos_token}{text}" for text in SAMPLE_INPUT_TEXTS]
    batch = tokenizer(
        input_texts, return_tensors="pt", padding="longest", add_special_tokens=False
    )
    batch = batch.to(device)
    decoded_ids = model.generate(
        input_ids=batch.input_ids,
        attention_mask=batch.attention_mask,
        eos_token_id=[tokenizer.encode("\n", add_special_tokens=False)],
        pad_token_id=tokenizer.pad_token_id,
        max_new_tokens=args.max_new_tokens,
        do_sample=False,
    )
    
    decoded_texts = tokenizer.batch_decode(decoded_ids, skip_special_tokens=False)
    for text in decoded_texts:
        print("===")
        print(f"Decoded: {text}")
        

if __name__ == "__main__":
    parser = argparse.ArgumentParser(allow_abbrev=False)
    parser.add_argument(
        "--model_name_or_path",
        "-m",
        type=str,
        default="tohoku-nlp/bygpt-jp-multi-lm-head-6.5B-alpha",
        help="Path to the model or model identifier from huggingface.co/models."
    )
    parser.add_argument("--max_new_tokens", "-n", type=int, help="Maximum number of new tokens to generate.", default=160)
    parser.add_argument("--seed", "-s", type=int, help="Random seed", default=42)
    args = parser.parse_args()
    main(args)

利用上の注意点

本モデルは,1度に4bytes (tokens) ずつ予測するため,特殊tokenも複数トークン (bytes) で構成されています.
そのため,例えばtokenizer.eos_tokenはlist of intです.
また,generate関数はcustom_generateの機能により実装されており,利用可能な機能に制限があります. また,このモデルはinstruction tuning等は実施していないモデルです.

モデルアーキテクチャ

Llama アーキテクチャをベースとしています。
具体的には、以下のモジュールを採用しています。

また,4tokens (bytes) ずつ予測するため,

  • 4つのlmヘッド
  • 入力のembeddingを4tokenごとにマージするモジュール を追加しています。

学習データ

llm-jp-corpus-v3 の日本語コーパスのサブセット (ja_cc, ja_warp_html, ja_warp_pdf, ja_wiki, kaken) を使用しました。

学習設定

tohoku-nlp/bygpt-jp-multi-lm-head-6.5B-alpha
Training Steps 208,000
Batch Size (tokens) 5,898,240
Max Learning Rate 5.0E-4
Min Learning Rate 1.0E-5
Learning Rate Warmup Steps 2,000
Scheduler cosine
Optimizer AdamW
Optimizer Config beta_1 = 0.9, beta_2 = 0.999, eps = 1.0E-8
Weight Decay 0.01
Gradient Clipping 1.0
Sequence Length 11,520

学習にはMegatron-LMをベースに,独自の変更を加えたコードベースを使用しています。

ライセンス

このモデルは Apache License 2.0 の下で配布しています。

免責事項

本モデルの作者は本モデルを作成するにあたって、その内容、機能等について細心の注意を払っておりますが、モデルの出力が正確であるかどうか、安全なものであるか等について保証をするものではなく、何らの責任を負うものではありません。
本モデルの利用により、万一、利用者に何らかの不都合や損害が発生したとしても、モデルやデータセットの作者や作者の所属組織は何らの責任を負うものではありません。

謝辞

このモデルの学習にあたり様々な面でご協力いただきました Tohoku NLP Group の皆様に感謝いたします。

作成者





byGPT-JP-multi-lm-head 6.5B alpha

This is a Japanese language model that adopts a byte-level tokenizer. It adopts an architecture with multiple LM heads for predicting 4 tokens (bytes) at once. It also adopts a unique Unicode encoding suitable for multi-byte prediction. This is currently a model in development stage and has not yet reached sufficient performance.

Usage

Operation has been confirmed with transformers version 4.56.1. It may not work with other versions.

import argparse

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer


SAMPLE_INPUT_TEXTS = [
    "日本三景一覧:\n1. 広島県, 宮島\n2. 京都府, 天橋立\n3. 宮城県, ",
    "原文: I like to play soccer. 訳文: 私はサッカーをするのが好きです。\n原文: She enjoys reading books. 訳文: 彼女は本を読むのが好きです。\n原文: They went to the park. 訳文:",
]

def main(args):
    torch.manual_seed(args.seed)
    device = torch.device("cuda")

    tokenizer = AutoTokenizer.from_pretrained(
        args.model_name_or_path,
        trust_remote_code=True,
    )
    model = AutoModelForCausalLM.from_pretrained(
        args.model_name_or_path,
        dtype=torch.bfloat16,
        trust_remote_code=True,
    )
    model.to(device)
    model.eval()

    input_texts = [f"{tokenizer.bos_token}{text}" for text in SAMPLE_INPUT_TEXTS]
    batch = tokenizer(
        input_texts, return_tensors="pt", padding="longest", add_special_tokens=False
    )
    batch = batch.to(device)
    decoded_ids = model.generate(
        input_ids=batch.input_ids,
        attention_mask=batch.attention_mask,
        eos_token_id=[tokenizer.encode("\n", add_special_tokens=False)],
        pad_token_id=tokenizer.pad_token_id,
        max_new_tokens=args.max_new_tokens,
        do_sample=False,
    )
    
    decoded_texts = tokenizer.batch_decode(decoded_ids, skip_special_tokens=False)
    for text in decoded_texts:
        print("===")
        print(f"Decoded: {text}")
        

if __name__ == "__main__":
    parser = argparse.ArgumentParser(allow_abbrev=False)
    parser.add_argument(
        "--model_name_or_path",
        "-m",
        type=str,
        default="tohoku-nlp/bygpt-jp-multi-lm-head-6.5B-alpha",
        help="Path to the model or model identifier from huggingface.co/models."
    )
    parser.add_argument("--max_new_tokens", "-n", type=int, help="Maximum number of new tokens to generate.", default=160)
    parser.add_argument("--seed", "-s", type=int, help="Random seed", default=42)
    args = parser.parse_args()
    main(args)

Important Notes for Usage

Since this model predicts 4 bytes (tokens) at once, special tokens are also composed of multiple tokens (bytes). Therefore, for example, tokenizer.eos_token is a list of int. Also, the generate function is implemented through custom_generate functionality, which has limitations on available features. Additionally, this model has not undergone instruction tuning.

Model Architecture

Based on the Llama architecture. Specifically, it adopts the following modules:

Also, for predicting 4 tokens (bytes) at once, we have added:

  • 4 LM heads
  • A module to merge input embeddings every 4 tokens

Training Data

We used a subset of the Japanese corpus from llm-jp-corpus-v3 (ja_cc, ja_warp_html, ja_warp_pdf, ja_wiki, kaken).

Training Configuration

tohoku-nlp/bygpt-jp-multi-lm-head-6.5B-alpha
Training Steps 170,000
Batch Size (tokens) 5,898,240
Max Learning Rate 5.0E-4
Min Learning Rate 1.0E-5
Learning Rate Warmup Steps 2,000
Scheduler cosine
Optimizer AdamW
Optimizer Config beta_1 = 0.9, beta_2 = 0.999, eps = 1.0E-8
Weight Decay 0.01
Gradient Clipping 1.0
Sequence Length 11,520

For training, we used a codebase based on Megatron-LM with our own custom modifications.

License

This model is distributed under the Apache License 2.0.

Disclaimer

While the authors of this model have paid careful attention to its content and functionality during creation, we do not guarantee that the model's outputs are accurate or safe, and we assume no responsibility for them. Even if users experience any inconvenience or damage due to the use of this model, the authors of the model and dataset and their affiliated organizations assume no responsibility.

Acknowledgments

We thank all members of the Tohoku NLP Group who cooperated with us in various aspects of training this model.

Authors

Downloads last month
14
Safetensors
Model size
6.58B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including tohoku-nlp/bygpt-jp-multi-lm-head-6.5B-alpha