🚀 Extended-Mind-Mpt-7bのモデルカード
このモデルはExtended Mind Transformersコレクションの一部で、論文で説明されている手法を実装しています。このモデルは、外部のキーバリューペア(またはメモリ)のキャッシュを取得し、それにアテンションを向けます。また、ファインチューニングは行われておらず(元のモデルの重みは編集されていません)。
- GitHub: https://github.com/normal-computing/extended-mind-transformers/
- ArXiv: https://arxiv.org/abs/2406.02332
元のアーキテクチャとコードはMosaic MLによるものです。
- 開発元: Normal Computing(Mosacic MLから適応)
- ライセンス: Apache 2.0
🚀 クイックスタート
このモデルは、外部のキーバリューペア(メモリ)のキャッシュを取得し、それにアテンションを向ける機能を持っています。以下のセクションでは、このモデルの使い方を詳しく説明します。
💻 使用例
基本的な使用法
モデルに外部メモリを渡すのは簡単です。インスタンス化時にトークンIDをモデルに渡すだけです。以下の例で説明します。メモリの生成とキャッシュは、最初のmodel.generate()
呼び出し時に内部で処理されます。以下のコマンドシーケンスを使用してメモリを更新できます。
model.clear_memories()
model.memory_ids = list_of_new_token_ids
警告を避けるためにtrust_remote_code=True
を設定します。メモリはトークンIDのリストとしてモデルに渡します。
from transformers import AutoModelForCausalLM, AutoTokenizer
ag_wiki_entry = """Alexander Grothendieck (/ˈɡroʊtəndiːk/; German pronunciation: [ˌalɛˈksandɐ ˈɡʁoːtn̩ˌdiːk] (listen); French: [ɡʁɔtɛndik]; 28 March 1928 – 13 November 2014) was a stateless (and then, since 1971, French) mathematician who became the leading figure in the creation of modern algebraic geometry.[7][8] His research extended the scope of the field and added elements of commutative algebra, homological algebra, sheaf theory, and category theory to its foundations, while his so-called "relative" perspective led to revolutionary advances in many areas of pure mathematics.[7][9] He is considered by many to be the greatest mathematician of the twentieth century.[10][11]"""
tokenizer_hf = AutoTokenizer.from_pretrained("normalcomputing/extended-mind-mpt-7b")
memories = tokenizer_hf(ag_wiki_entry).input_ids
model_hf = AutoModelForCausalLM.from_pretrained("normalcomputing/extended-mind-mpt-7b", external_memories=memories, trust_remote_code=True)
この後、通常通りモデルでテキストを生成できます。モデルは生成中に自動的にメモリを使用します。model.generate()
メソッドに新しい値を渡すことで、任意の設定パラメータを更新できます(以下ではtopk
を設定しています)。
inputs = "When did Alexander Grothendieck become a French citizen?"
inputs = tokenizer(inputs, return_tensors="pt").input_ids
outputs = model.generate(inputs, max_length=40, topk=2)
tokenizer.decode(outputs_hf['sequences'][0], skip_special_tokens=True)
高度な使用法
model.generate()
メソッドでoutput_retrieved_memory_idx=True
を設定するだけで、生成中に使用されたメモリインデックスを取得できます。デモノートブックで例を説明しています。
📚 ドキュメント
追加設定
LongLLaMAにはいくつかの追加パラメータがあります。
属性 |
详情 |
memory_type |
外部メモリを手動で保存するか、ベクトルデータベースに保存するかを指定します。(文字列型、オプション、デフォルトはmanual ) |
mask_by_sim |
取得したメモリを類似度でマスクするかどうかを指定します。(ブール型、オプション、デフォルトはTrue ) |
sim_threshold |
取得したメモリをマスクするための閾値を指定します。(浮動小数点数型、オプション、デフォルトは0.25 ) |
tokenizer_all_special_ids |
メモリから削除する特殊トークンのIDを指定します。(リスト型、オプション、デフォルトは[0, 50278] ) |
remove_special_tokens |
トークナイザーの特殊IDに対応するメモリを削除するかどうかを指定します。(ブール型、オプション、デフォルトはTrue ) |
さらに、メモリ表現を計算するために使用されるストライドは、generate_cache()
メソッド内で設定できます。小さいストライドは高品質な表現を生成しますが、大きいストライドは計算量が少なくて済みます。
📄 ライセンス
このモデルはApache 2.0ライセンスの下で提供されています。