{"id":42421995,"url":"https://github.com/yui0/llm_from_scratch","last_synced_at":"2026-01-28T03:00:55.494Z","repository":{"id":317007446,"uuid":"1051577369","full_name":"yui0/llm_from_scratch","owner":"yui0","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-28T06:36:40.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-28T08:38:48.953Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yui0.png","metadata":{"files":{"readme":"README-ja.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["yui0"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2025-09-06T09:35:43.000Z","updated_at":"2025-09-28T06:36:44.000Z","dependencies_parsed_at":"2025-09-29T22:16:50.597Z","dependency_job_id":null,"html_url":"https://github.com/yui0/llm_from_scratch","commit_stats":null,"previous_names":["yui0/llm_from_scratch"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/yui0/llm_from_scratch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yui0%2Fllm_from_scratch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yui0%2Fllm_from_scratch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yui0%2Fllm_from_scratch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yui0%2Fllm_from_scratch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yui0","download_url":"https://codeload.github.com/yui0/llm_from_scratch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yui0%2Fllm_from_scratch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28835719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T02:10:51.810Z","status":"ssl_error","status_checked_at":"2026-01-28T02:10:50.806Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-28T03:00:34.313Z","updated_at":"2026-01-28T03:00:55.484Z","avatar_url":"https://github.com/yui0.png","language":"Python","funding_links":["https://github.com/sponsors/yui0"],"categories":[],"sub_categories":[],"readme":"# JAXを使用したゼロからの言語モデル（LLM）構築\n\nこのプロジェクトは、JAXを使用してゼロから言語モデル（LLM）を構築する方法を示します。効率的なテキスト処理のために、事前学習済みのGPT-2トークナイザーを活用しています。データ準備、モデル構築、トレーニング、テキスト生成が含まれており、Google Colab向けに最適化されています。\n\n## 機能\n- **データセット準備**: `wikitext-103-raw-v1`データセットを使用し、データ拡張（文のランダムシャッフルと一部のドロップ）を行います。\n- **トークナイザー**: 事前学習済みのGPT-2トークナイザーを使用し、パディングや特殊トークンを追加。\n- **モデルアーキテクチャ**: マルチヘッドアテンション、フィードフォワード層、層正規化を備えたトランスフォーマーベースのモデル。\n- **トレーニング**: Adamオプティマイザ、学習率スケジューリング、検証損失に基づく早期停止を備えたトレーニングループ。\n- **テキスト生成**: 多様で制御されたテキスト生成のためのトップkおよびトップpサンプリングをサポート。\n\n## 必要条件\n- Python 3.8以上\n- JAX\n- Optax\n- Datasets\n- Tokenizers\n- NumPy\n- Matplotlib\n\n## 使用方法\n1. **環境の準備**:\n   ```bash\n   pip install jax jaxlib optax datasets tokenizers numpy matplotlib\n   ```\n2. **スクリプトの実行**:\n   - `llm_from_scratch.py`をGoogle Colabまたはローカル環境で開きます。\n   - スクリプトを実行してデータセットを準備し、モデルをトレーニングし、テキストを生成します。\n3. **テキスト生成**:\n   - トレーニング後、プロンプト（例: \"Once upon a time\"）に基づいてテキストを生成します。\n   - `top_k`、`top_p`、`temperature`などの生成パラメータをカスタマイズして出力を調整できます。\n\n## 例\n```python\nprompt = \"Once upon a time\"\ngenerated = generate_text(params, tokenizer, prompt, block_size=128, top_k=40, top_p=0.9, temperature=0.9)\nprint(f\"Prompt: {prompt}\")\nprint(f\"Generated: {generated}\")\n```\n\n## 備考\n- デフォルトでは3000イテレーションのトレーニングを行い、過学習を防ぐために早期停止を採用。\n- パフォーマンス調整のために`block_size`、`batch_size`、`learning_rate`を調整可能。\n- トークナイザーはパディングおよびテキスト終了マーカーとして`\u003c|endoftext|\u003e`を使用。\n\n## ライセンス\nMITライセンス\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyui0%2Fllm_from_scratch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyui0%2Fllm_from_scratch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyui0%2Fllm_from_scratch/lists"}