Skip to content

Commit 3530417

Browse files
committed
「前の記事」「次の記事」ボタン関連を変更
1 parent f2cdfc4 commit 3530417

File tree

15 files changed

+156
-133
lines changed

15 files changed

+156
-133
lines changed

articles/20240803/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ <h1>自己紹介</h1>
3535
ただ、その時々でgitの話が出たりもします。<br />
3636
たまに誤った情報を書くこともあるかもしれないので、そのときはこのブログのリポジトリ(<a href="https://github.com/shizukani-cp/blog">https://github.com/shizukani-cp/blog</a>)にIssueやPull requestで教えてください。<br />
3737
ちなみに身長は3mm、体重は3mg、年齢は138億歳です。 </p>
38-
<button class="button"
39-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240807/'">次の記事</button>
40-
<button class="button"
38+
<button class="button back-next"
4139
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241224/'">前の記事</button>
40+
<button class="button back-next"
41+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240807/'">次の記事</button>
4242
</main>
4343
<aside id="sidebar"></aside>
4444
<script src="../../scripts/articles.json.js"></script>

articles/20240807/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ <h2>2024/08/08追記</h2>
5959
1. <a href="https://git-lfs.com/">git-lfsのホームページ</a>を開く
6060
2. 画面にあるインストーラをダウンロード・実行する
6161
3. ターミナルでgit lfs installを実行する</p>
62-
<button class="button"
63-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240816/'">次の記事</button>
64-
<button class="button"
62+
<button class="button back-next"
6563
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240803/'">前の記事</button>
64+
<button class="button back-next"
65+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240816/'">次の記事</button>
6666
</main>
6767
<aside id="sidebar"></aside>
6868
<script src="../../scripts/articles.json.js"></script>

articles/20240816/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ <h2>Vitepress</h2>
3737
<p>そういったことで、Vitepressというエンジンを使ってみました。しかし、肝心のGitHub Pagesへの公開をうまくできなかったので、変更することにしました。</p>
3838
<h2></h2>
3939
<p>とりあえずRustで<a href="https://github.com/shizukani-cp/md2html.git">md2html</a>というツールを気合いで作って、それを使うことにしました。なので、使い方を見ればあるだろうと推測できますが、contentsフォルダーの直下にtemplate.htmlがいたり、それぞれの記事のフォルダーにentry.mdがいたりします。</p>
40-
<button class="button"
41-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240925/'">次の記事</button>
42-
<button class="button"
40+
<button class="button back-next"
4341
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240807/'">前の記事</button>
42+
<button class="button back-next"
43+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240925/'">次の記事</button>
4444
</main>
4545
<aside id="sidebar"></aside>
4646
<script src="../../scripts/articles.json.js"></script>

articles/20240925/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ <h4>Rust</h4>
8585
name = &quot;rust&quot;
8686
</code></pre>
8787
<p>はい。至極シンプルです。</p>
88-
<button class="button"
89-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241113/'">次の記事</button>
90-
<button class="button"
88+
<button class="button back-next"
9189
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240816/'">前の記事</button>
90+
<button class="button back-next"
91+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241113/'">次の記事</button>
9292
</main>
9393
<aside id="sidebar"></aside>
9494
<script src="../../scripts/articles.json.js"></script>

articles/20241113/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ <h2>現時点のリポジトリ</h2>
4747
条件は<a href="https://github.com/shizukani-cp/textdatas">リポジトリ</a>のREADMEに書いておいたので、適宜参照してください。</p>
4848
<h2>最後に</h2>
4949
<p>久しぶり(1カ月以上!)に書いたせいか、調子が狂っているかもしれませんが、とりあえず今回のリポジトリに協力していただけると幸いです。</p>
50-
<button class="button"
51-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241117/'">次の記事</button>
52-
<button class="button"
50+
<button class="button back-next"
5351
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20240925/'">前の記事</button>
52+
<button class="button back-next"
53+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241117/'">次の記事</button>
5454
</main>
5555
<aside id="sidebar"></aside>
5656
<script src="../../scripts/articles.json.js"></script>

articles/20241117/index.html

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,28 @@ <h2>おおまかな概要</h2>
3838
そして、AGIが指示を受け取ったとき、リクエストを送り、その結果を返すというものです。リクエストは複数回送ることができ、リクエストを受け取ったサーバーサイドでも送ることができます。</p>
3939
<h2>規格的なもの</h2>
4040
<h3>通信方式</h3>
41-
<p>通信方式には、以下の要素があるといいかなというところです。
42-
- リクエスト
43-
- メソッド
44-
- 送り主
45-
- プロンプト
46-
- レスポンス
47-
- ステータスコード的な何か(HTTPを流用するのはきつそう)
48-
- レスポンス本体(GETメソッドの場合)</p>
41+
<p>通信方式には、以下の要素があるといいかなというところです。<br />
42+
* リクエスト
43+
* メソッド
44+
* 送り主
45+
* プロンプト
46+
* レスポンス
47+
* ステータスコード的な何か(HTTPを流用するのはきつそう)
48+
* レスポンス本体(GETメソッドの場合)</p>
4949
<h3>メソッド</h3>
50-
<p>メソッドは、今のところ以下のものがあれば十分かなと思います。
51-
- <code>GET</code>メソッド
52-
- 弱いAIにリクエストを送るときのメソッド。レスポンス本体もある。
53-
- <code>POST</code>メソッド
54-
- AgentのTool的なものに送るときのメソッド。レスポンスはステータスコードだけ。
55-
- 個人的になんとなくPOSTメソッドじゃない感があるので、もっといい案があったら変えるかも。</p>
50+
<p>メソッドは、今のところ以下のものがあれば十分かなと思います。<br />
51+
* <code>GET</code>メソッド
52+
* 弱いAIにリクエストを送るときのメソッド。レスポンス本体もある。
53+
* <code>POST</code>メソッド
54+
* AgentのTool的なものに送るときのメソッド。レスポンスはステータスコードだけ。
55+
* 個人的になんとなくPOSTメソッドじゃない感があるので、もっといい案があったら変えるかも。</p>
5656
<h2>名前どうしよう…</h2>
5757
<p>現在、これに対して名前が思いつかないという事態が発生しています!?<br />
5858
いい名前が思いついたら教えてください。</p>
59-
<button class="button"
60-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241129/'">次の記事</button>
61-
<button class="button"
59+
<button class="button back-next"
6260
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241113/'">前の記事</button>
61+
<button class="button back-next"
62+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241129/'">次の記事</button>
6363
</main>
6464
<aside id="sidebar"></aside>
6565
<script src="../../scripts/articles.json.js"></script>

articles/20241129/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ <h2>感想</h2>
5959
<h2>書いた後公開する前の追記</h2>
6060
<p>この記事を書いている方のPCでは、日本語を入れると文字化けするのですが、学校で配られたPCでは文字化けしていませんでした。<br />
6161
バージョンの違いか、OSの違いかと思います。</p>
62-
<button class="button"
63-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241130/'">次の記事</button>
64-
<button class="button"
62+
<button class="button back-next"
6563
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241117/'">前の記事</button>
64+
<button class="button back-next"
65+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241130/'">次の記事</button>
6666
</main>
6767
<aside id="sidebar"></aside>
6868
<script src="../../scripts/articles.json.js"></script>

articles/20241130/index.html

Lines changed: 84 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -40,100 +40,112 @@ <h2>概要</h2>
4040
<h2>方法</h2>
4141
<p>…これで終わるわけにも行かないので、方法を書き散らしておきます。<br />
4242
まずは、Llamaを教師モデルとして自分のモデルを訓練するために、そのプログラムをPerplexityに書いてもらいます。
43-
そのプログラムがこちらです。(動作確認していないので、ご注意)
44-
```python:初回用
43+
そのプログラムがこちらです。(動作確認していないので、ご注意)</p>
44+
<pre><code class="language-python"># 初回用
4545
import torch
4646
import torch.nn as nn
4747
import torch.optim as optim
4848
from torch.utils.data import Dataset, DataLoader
4949
from transformers import MllamaForConditionalGeneration, AutoProcessor
50-
from logging import getLogger, Formatter, StreamHandler, DEBUG</p>
51-
<h1>ロガーの設定</h1>
52-
<p>logger = getLogger(<strong>name</strong>)
50+
from logging import getLogger, Formatter, StreamHandler, DEBUG
51+
52+
# ロガーの設定
53+
logger = getLogger(__name__)
5354
logger.setLevel(DEBUG)
5455
handler = StreamHandler()
5556
handler.setLevel(DEBUG)
5657
formatter = Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
5758
handler.setFormatter(formatter)
58-
logger.addHandler(handler)</p>
59-
<h1>WikipediaDatasetの定義</h1>
60-
<p>class WikipediaDataset(Dataset):
61-
def <strong>init</strong>(self, file_path, max_length=512):
59+
logger.addHandler(handler)
60+
61+
# WikipediaDatasetの定義
62+
class WikipediaDataset(Dataset):
63+
def __init__(self, file_path, max_length=512):
6264
self.file_path = file_path
6365
self.max_length = max_length
64-
self.data = self.load_annotations()</p>
65-
<pre><code>def load_annotations(self):
66-
with open(self.file_path, 'r', encoding='utf-8') as f:
67-
return [line.strip() for line in f if line.strip()]
66+
self.data = self.load_annotations()
67+
68+
def load_annotations(self):
69+
with open(self.file_path, 'r', encoding='utf-8') as f:
70+
return [line.strip() for line in f if line.strip()]
6871

69-
def __len__(self):
70-
return len(self.data)
72+
def __len__(self):
73+
return len(self.data)
7174

72-
def __getitem__(self, idx):
73-
return self.data[idx][:self.max_length]
74-
</code></pre>
75-
<h1>SmallModelの定義</h1>
76-
<p>class SmallModel(nn.Module):
77-
def <strong>init</strong>(self, input_size, hidden_size, output_size):
78-
super(SmallModel, self).<strong>init</strong>()
75+
def __getitem__(self, idx):
76+
return self.data[idx][:self.max_length]
77+
78+
# SmallModelの定義
79+
class SmallModel(nn.Module):
80+
def __init__(self, input_size, hidden_size, output_size):
81+
super(SmallModel, self).__init__()
7982
self.fc1 = nn.Linear(input_size, hidden_size)
8083
self.fc2 = nn.Linear(hidden_size, output_size)
81-
self.relu = nn.ReLU()</p>
82-
<pre><code>def forward(self, x):
83-
x = self.relu(self.fc1(x))
84-
x = self.fc2(x)
85-
return x
86-
</code></pre>
87-
<h1>ローカルのLlama 3.2モデルのロード</h1>
88-
<p>model_path = "path/to/your/local/llama3.2/model"
84+
self.relu = nn.ReLU()
85+
86+
def forward(self, x):
87+
x = self.relu(self.fc1(x))
88+
x = self.fc2(x)
89+
return x
90+
91+
# ローカルのLlama 3.2モデルのロード
92+
model_path = &quot;path/to/your/local/llama3.2/model&quot;
8993
teacher_model = MllamaForConditionalGeneration.from_pretrained(
9094
model_path,
9195
torch_dtype=torch.bfloat16,
92-
device_map="auto"
96+
device_map=&quot;auto&quot;
9397
)
94-
processor = AutoProcessor.from_pretrained(model_path)</p>
95-
<h1>SmallModelの初期化</h1>
96-
<p>input_size = 768 # 入力サイズ(実際のタスクに合わせて調整)
98+
processor = AutoProcessor.from_pretrained(model_path)
99+
100+
# SmallModelの初期化
101+
input_size = 768 # 入力サイズ(実際のタスクに合わせて調整)
97102
hidden_size = 256
98103
output_size = teacher_model.config.vocab_size
99-
student_model = SmallModel(input_size, hidden_size, output_size).to("cuda")</p>
100-
<h1>データセットとDataLoaderの準備</h1>
101-
<p>dataset = WikipediaDataset("path/to/wiki.txt")
102-
dataloader = DataLoader(dataset, batch_size=2, shuffle=True)</p>
103-
<h1>損失関数とオプティマイザの設定</h1>
104-
<p>criterion = nn.KLDivLoss(reduction='batchmean')
105-
optimizer = optim.Adam(student_model.parameters())</p>
106-
<h1>学習ループ</h1>
107-
<p>num_epochs = 10
108-
temperature = 2.0</p>
109-
<p>for epoch in range(num_epochs):
104+
student_model = SmallModel(input_size, hidden_size, output_size).to(&quot;cuda&quot;)
105+
106+
# データセットとDataLoaderの準備
107+
dataset = WikipediaDataset(&quot;path/to/wiki.txt&quot;)
108+
dataloader = DataLoader(dataset, batch_size=2, shuffle=True)
109+
110+
# 損失関数とオプティマイザの設定
111+
criterion = nn.KLDivLoss(reduction='batchmean')
112+
optimizer = optim.Adam(student_model.parameters())
113+
114+
# 学習ループ
115+
num_epochs = 10
116+
temperature = 2.0
117+
118+
for epoch in range(num_epochs):
110119
for batch in dataloader:
111120
# 入力の処理
112-
inputs = processor(batch, return_tensors="pt", padding=True, truncation=True).to("cuda")</p>
113-
<pre><code> # 教師モデルの出力を取得
114-
with torch.no_grad():
115-
teacher_outputs = teacher_model(**inputs).logits
116-
117-
# 生徒モデルの出力を取得
118-
student_outputs = student_model(inputs.input_ids)
119-
120-
# 知識蒸留損失の計算
121-
loss = criterion(
122-
nn.functional.log_softmax(student_outputs / temperature, dim=-1),
123-
nn.functional.softmax(teacher_outputs / temperature, dim=-1)
124-
)
125-
126-
# 逆伝播と最適化
127-
optimizer.zero_grad()
128-
loss.backward()
129-
optimizer.step()
130-
131-
logger.debug(f"Epoch {epoch+1}/{num_epochs}, Loss: {loss.item()}")
121+
inputs = processor(batch, return_tensors=&quot;pt&quot;, padding=True, truncation=True).to(&quot;cuda&quot;)
122+
123+
# 教師モデルの出力を取得
124+
with torch.no_grad():
125+
teacher_outputs = teacher_model(**inputs).logits
126+
127+
# 生徒モデルの出力を取得
128+
student_outputs = student_model(inputs.input_ids)
129+
130+
# 知識蒸留損失の計算
131+
loss = criterion(
132+
nn.functional.log_softmax(student_outputs / temperature, dim=-1),
133+
nn.functional.softmax(teacher_outputs / temperature, dim=-1)
134+
)
135+
136+
# 逆伝播と最適化
137+
optimizer.zero_grad()
138+
loss.backward()
139+
optimizer.step()
140+
141+
logger.debug(f&quot;Epoch {epoch+1}/{num_epochs}, Loss: {loss.item()}&quot;)
142+
143+
# モデルの保存
144+
torch.save(student_model.state_dict(), &quot;small_model.pth&quot;)
145+
146+
logger.debug(&quot;モデルが保存されました。&quot;) )
132147
</code></pre>
133-
<h1>モデルの保存</h1>
134-
<p>torch.save(student_model.state_dict(), "small_model.pth")</p>
135-
<p>logger.debug("モデルが保存されました。") )</p>
136-
<pre><code>```python:2回目以降用
148+
<pre><code class="language-python"># 2回目以降用
137149
import torch
138150
import torch.nn as nn
139151
import torch.optim as optim
@@ -276,10 +288,10 @@ <h2>Wikipediaだけじゃ…</h2>
276288
これで、CC BY-SAとCC BY-NC-SAの組み合わせだったら、死んでいたところでした。 </p>
277289
<h2>今後</h2>
278290
<p>とりあえず開発途中に書いた記事なので、今後もどんどん更新を入れていきます。</p>
279-
<button class="button"
280-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241201/'">次の記事</button>
281-
<button class="button"
291+
<button class="button back-next"
282292
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241129/'">前の記事</button>
293+
<button class="button back-next"
294+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241201/'">次の記事</button>
283295
</main>
284296
<aside id="sidebar"></aside>
285297
<script src="../../scripts/articles.json.js"></script>

articles/20241201/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ <h2>こういうので得られるもの</h2>
4545
<p>まずは、自分が考えたもの以外を実装するということでしょうか。<br />
4646
普段は自分で考えたものを自分で考えている感じになっているので、こういうのは新鮮だったりします。<br />
4747
あとは要求されたものが、普段やっていないもの(3D)だったので、その分野の知識もちょっと身に付きました。</p>
48-
<button class="button"
49-
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241208/'">次の記事</button>
50-
<button class="button"
48+
<button class="button back-next"
5149
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241130/'">前の記事</button>
50+
<button class="button back-next"
51+
onclick="location.href = 'https://shizukani-cp.github.io/blog/articles/20241208/'">次の記事</button>
5252
</main>
5353
<aside id="sidebar"></aside>
5454
<script src="../../scripts/articles.json.js"></script>

0 commit comments

Comments
 (0)