--- license: apache-2.0 language: - ja --- (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](https://github.com/huggingface/transformers/releases/tag/v4.56.1) において、動作確認しています。 他のバージョンでは動作しない可能性があります。 ```python 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](https://arxiv.org/abs/2302.13971) アーキテクチャをベースとしています。 具体的には、以下のモジュールを採用しています。 - [SwiGLU](https://arxiv.org/abs/2002.05202) - [Rotary Positional Embeddings (RoPE)](https://arxiv.org/abs/2104.09864) - [Grouped Query Attention (GQA)](https://aclanthology.org/2023.emnlp-main.298/) また,4tokens (bytes) ずつ予測するため, - 4つのlmヘッド - 入力のembeddingを4tokenごとにマージするモジュール を追加しています。 ## 学習データ [llm-jp-corpus-v3](https://gitlab.llm-jp.nii.ac.jp/datasets/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](https://arxiv.org/abs/1909.08053)をベースに,独自の変更を加えたコードベースを使用しています。 ## ライセンス このモデルは Apache License 2.0 の下で配布しています。 # 免責事項 本モデルの作者は本モデルを作成するにあたって、その内容、機能等について細心の注意を払っておりますが、モデルの出力が正確であるかどうか、安全なものであるか等について保証をするものではなく、何らの責任を負うものではありません。 本モデルの利用により、万一、利用者に何らかの不都合や損害が発生したとしても、モデルやデータセットの作者や作者の所属組織は何らの責任を負うものではありません。 ## 謝辞 このモデルの学習にあたり様々な面でご協力いただきました [Tohoku NLP Group](https://www.nlp.ecei.tohoku.ac.jp/) の皆様に感謝いたします。 ## 作成者 - [Keito Kudo](https://x.com/k8kudo) - [Go Kamoda](https://x.com/go2oo2) - [Daiki Shiono](https://x.com/onely7_deep) - [Jun Suzuki](https://x.com/drJunSuzuki)



# 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](https://github.com/huggingface/transformers/releases/tag/v4.56.1). It may not work with other versions. ```python 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](https://arxiv.org/abs/2302.13971) architecture. Specifically, it adopts the following modules: - [SwiGLU](https://arxiv.org/abs/2002.05202) - [Rotary Positional Embeddings (RoPE)](https://arxiv.org/abs/2104.09864) - [Grouped Query Attention (GQA)](https://aclanthology.org/2023.emnlp-main.298/) 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](https://gitlab.llm-jp.nii.ac.jp/datasets/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](https://arxiv.org/abs/1909.08053) 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](https://www.nlp.ecei.tohoku.ac.jp/) who cooperated with us in various aspects of training this model. ## Authors - [Keito Kudo](https://x.com/k8kudo) - [Go Kamoda](https://x.com/go2oo2) - [Daiki Shiono](https://x.com/onely7_deep) - [Jun Suzuki](https://x.com/drJunSuzuki)