モデル概要
モデル特徴
モデル能力
使用事例
🚀 Leeroo Dedidcated Math Expert 🤗
このモデルは、数学ドメインにおいてOrchestration of Expertを適用して構築されています。専用モデルは、解を生成するか、必要に応じてGPT - 4(または同等の性能を持つ大規模言語モデル)を利用して、知識ベースのギャップを埋めます。具体的には、入力が与えられると、専用モデルはまず、入力された質問がベースモデルで解けるかどうかを判断します。解ける場合は、オーケストレーターを切り離し、ベースの大規模言語モデルのエキスパートを使用してトークン生成を呼び出します。問題が難しく、GPT - 4のような大規模モデルが必要な場合は、<GPT4>
トークン(すなわち、token_id = 32000)を生成します。
オーケストレーターは、まず任意のクエリに対してベースモデルの知識を推定するように学習され、その後ベースモデル(ここではMetaMath7b)に統合されます。
一般的に任意のドメインでは、以下の手順で構築できます。
- ベースとなる大規模言語モデルのエキスパート🤗を選択する
- ドメイン固有のオーケストレーターを学習させる
- オーケストレーターをベースのエキスパートと統合する
✅ OpenLLM LeaderboardのGSM8kデータセットを使用した評価では、Leeroo Math 7bモデルは5 - shot設定で84.77%の正解率を達成し、同クラスのトップ性能を誇り、同じデータセットで68.84%を記録するベースモデルを大きく上回っています。これは、GSM8kからの質問の半分に対する回答にGPT - 4を利用しながら達成されました。
🚀 クイックスタート
このモデルは、数学ドメインに特化したモデルで、オーケストレーターを用いて解を生成するか、必要に応じてGPT - 4を呼び出します。以下に使い方を説明します。
✨ 主な機能
- 数学問題に対する解の生成
- ベースモデルで解けない問題に対しては、GPT - 4を呼び出す
- 任意のドメインに対して、ベースモデルとオーケストレーターを組み合わせて構築可能
📦 インストール
このモデルはtransformers
ライブラリを通じて使用できます。以下のコードでモデルとトークナイザーをロードできます。
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("leeroo/LeerooDedicated-Math-7b", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("leeroo/LeerooDedicated-Math-7b")
device = model.device
💻 使用例
基本的な使用法
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("leeroo/LeerooDedicated-Math-7b", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("leeroo/LeerooDedicated-Math-7b")
device = model.device
# 以下の質問はleerooエキスパートによって回答されます
question = "Natalia sold clips to 48 of her friends in April,and then she sold half as many clips in May.How many clips did Natalia sell altogether in April and May?"
encodeds = tokenizer([question], return_tensors="pt")
model_inputs = encodeds['input_ids'].to(device)
generated_ids = model.generate(model_inputs, max_new_tokens=100, do_sample=False)
decoded = tokenizer.batch_decode(generated_ids)
print(decoded[0])
# Natalia sold 48 clips in April.\nIn May, she sold half as many clips as in April,
# so she sold 48/2 = 24 clips.\nAltogether, Natalia sold 48 + 24 = 72 clips in April and May.\n#### 72\nThe answer is: 72</s>
# 以下の質問はGPT4に送られます
question = "James loves to go swimming and has to swim across a 20-mile lake. He can swim at a pace of 2 miles per hour. He swims 60% of the distance. After that, he stops on an island and rests for half as long as the swimming time. He then finishes the remaining distance while going half the speed. How long did it take him to get across the lake?"
encodeds = tokenizer([question], return_tensors="pt")
model_inputs = encodeds['input_ids'].to(device)
generated_ids = model.generate(model_inputs, max_new_tokens=100, do_sample=False)
decoded = tokenizer.batch_decode(generated_ids)
print(decoded[0])
# <GPT4></s>
高度な使用法
<GPT4>
トークンが生成されたときに、OpenAI APIを追加して完全な回答を取得することもできます。
from openai import OpenAI
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("leeroo/LeerooDedicated-Math-7b", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("leeroo/LeerooDedicated-Math-7b")
openai_client = OpenAI(
api_key= "OPENAI_API_KEY",
base_url= "https://api.openai.com/v1"
)
def generate(prompt, tokenizer, model, openai_client, max_new_tokens=100, verbose=True):
inputs = tokenizer(prompt, return_tensors="pt")
inputs = {k:v.to(model.device) for k,v in inputs.items()}
gen_tokens = model.generate( **inputs , max_new_tokens=max_new_tokens, do_sample=False, pad_token_id= tokenizer.pad_token_id)
if gen_tokens[0, inputs['input_ids'].shape[1]] != tokenizer.unk_token_id:
if verbose: print("\033[94mGenerating using MetaMath7b.\033[0m")
gen_text = tokenizer.decode(
gen_tokens[0, inputs['input_ids'].shape[1]:].tolist() )
else:
if verbose: print("\033[94mGenerating using gpt4.\033[0m")
gen_text = openai_client.completions.create(
model = "gpt-4-1106-preview", # NOTE you can use any bigger mode here having performance similar to gpt4
prompt = prompt,
max_tokens = max_new_tokens,
temperature = 0.0
).choices[0].text
return gen_text
# 以下の質問はleerooエキスパートによって回答されます
prompt = "Question: Natalia sold clips to 48 of her friends in April,and then she sold half as many clips in May.How many clips did Natalia sell altogether in April and May?\nAnswer:"
generation = generate(prompt, tokenizer, model, openai_client, max_new_tokens=500)
print(generation)
#> Generating using MetaMath7b.
# Natalia sold 48 clips in April.\nIn May, she sold half as many clips as in April,
# so she sold 48/2 = 24 clips.\nAltogether, Natalia sold 48 + 24 = 72 clips in April and May.\n#### 72\nThe answer is: 72</s>
# 以下の質問はGPT4に送られます
prompt = "James loves to go swimming and has to swim across a 40-mile lake. He can swim at a pace of 2 miles per hour. He swims 60% of the distance. After that, he stops on an island and rests for half as long as the swimming time. He then finishes the remaining distance while going half the speed. How many hours did it take him to get across the lake?"
generation = generate(prompt, tokenizer, model, openai_client, max_new_tokens=500)
print(generation)
#> Generating using gpt4.
# He swam 40*.6=24 miles
# So he swam for 24/2=12 hours
# He rested for 12/2=6 hours
# He had 40-24=16 miles left to swim
# He swam at 2/2=1 mile per hour
# So he swam for 16/1=16 hours
# So in total, it took him 12+6+16=34 hours
# 34
📚 ドキュメント
🔍 当社の手法と結果について詳しく知りたい場合は、HF blog 🤗、publication、およびrepositoryを参照してください。
🌍 さらなるアップデートを受け取るためにLeerooコミュニティに参加しましょう。Linkedin、Discord、X、Website。
📄 ライセンス
@misc{mohammadshahi2024leeroo,
title={Leeroo Orchestrator: Elevating LLMs Performance Through Model Integration},
author={Alireza Mohammadshahi and Ali Shaikh and Majid Yazdani},
year={2024},
eprint={2401.13979},
archivePrefix={arXiv},
primaryClass={cs.CL}
}



