🚀 ラムダラボのPythia 2.8Bモデル
このモデルは、自然言語処理タスクに特化した事前学習済みモデルです。Transformerベースのアーキテクチャを採用し、特定のデータセットでファインチューニングされています。
🚀 クイックスタート
このコード例では、lambdalabs/pythia-2.8b-deduped-synthetic-instruct
モデルを使用してテキスト生成を行う方法を示しています。
基本的な使用法
import torch
from transformers import AutoTokenizer, pipeline, StoppingCriteria, StoppingCriteriaList
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
model_name = "lambdalabs/pythia-2.8b-deduped-synthetic-instruct"
max_new_tokens = 2048
stop_token = "<|stop|>"
class KeywordsStoppingCriteria(StoppingCriteria):
def __init__(self, keywords_ids: list):
self.keywords = keywords_ids
def __call__(
self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs
) -> bool:
if input_ids[0][-1] in self.keywords:
return True
return False
tokenizer = AutoTokenizer.from_pretrained(
model_name,
)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.add_tokens([stop_token])
stop_ids = [tokenizer.encode(w)[0] for w in [stop_token]]
stop_criteria = KeywordsStoppingCriteria(stop_ids)
generator = pipeline(
"text-generation",
model=model_name,
device=device,
max_new_tokens=max_new_tokens,
torch_dtype=torch.float16,
stopping_criteria=StoppingCriteriaList([stop_criteria]),
)
example = "How can I make an omelette."
text = "Question: {}\nAnswer:".format(example)
result = generator(
text,
num_return_sequences=1,
)
output = result[0]["generated_text"]
print(output)
出力例:
Question: How can I make an omelette.
Answer:To make an omelette, start by cracking two eggs into a bowl and whisking them together. Add a splash of milk and a pinch of salt and pepper. Heat a non-stick pan over medium-high heat and add a tablespoon of butter. Once the butter has melted, pour in the egg mixture. As the eggs set, use a spatula to lift the edges and let the uncooked egg run underneath. When the eggs are cooked through and no visible liquid egg remains, top with your desired fillings and fold the omelette in half before sliding it onto a plate.<|stop|>
✨ 主な機能
- 事前学習済みのPythia 2.8Bモデルを特定のデータセットでファインチューニングしています。
- テキスト生成タスクに適しており、質問応答形式での使用が可能です。
📦 インストール
このモデルを使用するには、transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install transformers
📚 ドキュメント
モデル詳細
前提条件
このモデルで推論を実行するには、約7GBのGPUメモリが必要です。
学習
このモデルは、Dahoas/synthetic-instruct-gptj-pairwise
データセットで学習されています。元のデータセットをトレインセット(最初の32000例)とバリデーションセット(残りの1144例)に分割して使用しています。
モデルは4エポックでファインチューニングされています。この学習には8台のA100 80GB GPUを使用し、5時間かかりました。batch_size_per_gpu
は 2
(グローバルバッチサイズは16)、学習率は 0.00001
(最後の学習ステップでゼロに線形減衰)に設定されています。学習記録は こちら で確認できます。
📄 ライセンス
このモデルはApache 2.0ライセンスの下で提供されています。