kan gpt
1.2.0
言語モデリングに Kolmogorov-Arnold Networks (KAN) を使用した Generative Pre-trained Transformers (GPT) の PyTorch 実装
pip install kan_gpt
私たちの仕事が役立つと思われる場合は、引用してください。
@misc{GANESH2024KANGPT,
author = {Aditya Nalgunda Ganesh},
title = {KAN-GPT: The PyTorch implementation of Generative Pre-trained Transformers (GPTs) using Kolmogorov-Arnold Networks (KANs) for language modeling},
year = {2024},
month = {May},
note = {Release 1.0.0, 9th May 2024},
url = {https://github.com/AdityaNG/kan-gpt/}
}
使用例については、KAN_GPT.ipynb および kan_gpt/prompt.py を参照してください。モデルの使用方法の概要は次のとおりです。
from kan_gpt . model import GPT
from transformers import GPT2Tokenizer
model_config = GPT . get_default_config ()
model_config . model_type = "gpt2"
model_config . vocab_size = 50257
model_config . block_size = 1024
model = GPT ( model_config )
tokenizer = GPT2Tokenizer . from_pretrained ( 'gpt2' )
prompt = "Bangalore is often described as the "
prompt_encoded = tokenizer . encode (
text = prompt , add_special_tokens = False
)
x = torch . tensor ( prompt_encoded ). unsqueeze ( 0 )
model . eval ()
y = model . generate ( x , 50 ) # sample 50 tokens
result = tokenizer . decode ( y [ 0 ])
print ( result )
# Bangalore is often described as the Silicon Valley of India.
# The city has witnessed rapid growth in the past two decades.....
# Download Repo
git clone https://github.com/AdityaNG/kan-gpt
cd kan-gpt
git pull
# Download Dataset
python3 -m kan_gpt.download_dataset --dataset tinyshakespeare
python3 -m kan_gpt.download_dataset --dataset mnist
python3 -m kan_gpt.download_dataset --dataset webtext
# Install dependencies for development
pip install -r requirements.txt
pip install -e .
次のダミー スクリプトを使用して、すべてが期待どおりに動作していることを確認します。
WANDB_MODE=offline CUDA_VISIBLE_DEVICE= " " python3 -m kan_gpt.train --architecture MLP --batch_size 1 --dummy_dataset --device cpu --max_iters 200
WANDB_MODE=offline CUDA_VISIBLE_DEVICE= " " python3 -m kan_gpt.train --architecture KAN --batch_size 1 --dummy_dataset --device cpu --max_iters 200
次に、トレーニング スクリプトを使用します。
python -m kan_gpt.train
次のようにモデルにテキストを生成するようプロンプトできます。
python -m kan_gpt.prompt --prompt " Bangalore is often described as the " --model_path (checkpoint)
KAN-GPT を、Tiny Shakespeare データセット上の同等の MLP-GPT モデルとトレーニングして比較します。 KAN-GPT のパフォーマンスが MLP-GPT よりわずかに優れていることがわかります。私たちはさらに深く掘り下げるためのさらなる実験を検討しています。結果を以下に示します。
メトリクス | ||
---|---|---|
KAN.train_kan
から KAN トレーニング ロジックを統合mkdocs gh-deploy
CONTRIBUTING.md ファイルを読み取ります。