<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nah, I would win on Medium]]></title>
        <description><![CDATA[Stories by Nah, I would win on Medium]]></description>
        <link>https://medium.com/@winroom?source=rss-e9c9b046095a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MztW3MRC-tTuMgBH.jpg</url>
            <title>Stories by Nah, I would win on Medium</title>
            <link>https://medium.com/@winroom?source=rss-e9c9b046095a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:53:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@winroom/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Latent Visualization]]></title>
            <link>https://medium.com/ruffblitz/latent-visualization-781e602db93f?source=rss-e9c9b046095a------2</link>
            <guid isPermaLink="false">https://medium.com/p/781e602db93f</guid>
            <category><![CDATA[latent-space]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[dimensionality-reduction]]></category>
            <dc:creator><![CDATA[Nah, I would win]]></dc:creator>
            <pubDate>Thu, 24 Jul 2025 11:12:55 GMT</pubDate>
            <atom:updated>2025-07-30T11:44:22.676Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดี ผมคือ Nah, I would win.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/0*tMHExsr_Q2AsTYb2" /></figure><p>วันนี้มาพูดถึง Dimensionality Reduction กับ Latent Visualization ครับทุกคนคงเคยเห็น plot อะไรแนวๆนี้ ที่เป็นจุดๆจำนวนมาก แสดงถึงข้อมูลแต่ละชิ้นว่า อะไรใกล้เคียงกับอะไรแค่ไหน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*EORs9up4nafys91m2gfvZA.png" /></figure><p>ผมก็จะมาเล่าว่ามันทำขึ้นมาอย่างไร plot พวกนี้ และมันหมายถึงอะไร โดยที่เราจะเริ่มต้นจาก dimensionality reduction in simple dataset ก่อนเพื่อปูพื้นฐานก่อนจะไปเล่าการ visualize latent ของ model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*yrb99_yMl8h3Ox_S" /></figure><p>นี่น่ะคือตัวอย่างข้อมูลจาก MNIST เป็น dataset hand writing digits 0–10 ขนาด 60,000 (training set) + 10,000 (test set) โดยแต่ละภาพมีขนาด 28x28x1 (width, height, channel มันมีแค่ 1 channel แทนที่จะ 3 ตาม RGB format ของภาพทั่วไปเพราะมันขาวดำเนอะ) dimension รวมต่อภาพก็… 784 dimension. เราเริ่มกันที่ dataset นี้เพราะมันเป็น dataset ที่ค่อนข้างง่าย ทั้งขนาดเล็ก และก็ Visualize ได้ง่ายอีกด้วย</p><p>แต่เราไม่สามารถ plot ข้อมูลทั้ง 784 dimensions ให้ลงมาเหลือแค่ 2 แกนได้โดยตรงเพื่อดูว่า ภาพแต่ละชิ้น อะไรใกล้เคียงกันอะไร และมีการเกาะกลุ่มกันไหม เราจะต้องลด dimensions ของภาพแต่ละภาพลงมา โดยคงสิ่งที่สำคัญให้ได้มากที่สุด โดยวิธีการลด dimensions (<strong>Dimensionality Reduction</strong>) นั้น ผมจะมาเสนอ 3 วิธีนะ</p><ol><li><strong>PCA: Principle Component Analysis</strong></li></ol><p>มันก็เหมือนการฉายแสงผ่านวัตถุให้เกิดเงา (lower dimensional data) โดยการหา ทิศทางในการฉายเงาที่เหมาะสมที่สุด (principle axis). แต่ในครั้งนี้ เราจะ reduce dimension to 2 นะ เราจะใช้แค่ ทิศทางในการฉายเงาที่ดีที่สุดแค่สองอันแรก</p><pre>import numpy as np<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>from sklearn.manifold import TSNE<br>import umap.umap_ as umap<br>import tensorflow as tf<br>import time</pre><pre># prepare dataset and its class names for plotting<br>(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()<br>y = y_test.flatten()<br>class_names = [str(i) for i in range(10)]</pre><pre>from sklearn.decomposition import PCA</pre><pre>pca = PCA(n_components=2)<br>pca_result = pca.fit_transform(X_subset)</pre><pre># the shape of pca_result is (10000, 2)<br># เพราะเราลด dimensionality ของภาพแต่ละรูปจาก 784-&gt;2<br># แต่ละจุดเป็นตัวแทนของภาพแต่ละภาพว่า เมื่อลดขนาดมิติแล้ว ภาพไหนใกล้เคียงกับอะไรแค่ไหน</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*Eg0R4e0-yzDDawO_B4Mytw.png" /></figure><p>ข้อดี</p><ul><li>เร็ว, เร็วแบบ O(n)</li><li>เข้าใจง่าย เราสามารถสำรวจ แกนแสงแต่ละอันได้</li></ul><p>ข้อเสีย</p><ul><li>PCA มัน linear ข้อมูลที่ non-linear มัน reduce dimensionality ได้ไม่ค่อยดีนะบางที</li></ul><p>2. t-SNE</p><p>อันนี้ต่างจาก PCA ที่หาแกนที่เหมาะ แล้ว project to lower dimension เหมือน วางแกนแสงแล้วดูเงานะ. t-SNE เนี่ยมันจะ คอยดู distances ของ data points ต่างๆใน high dimension แล้วปรับแก้ระยะทางของแต่ละจุดใน low dimension data points ให้มีสัดส่วนที่เป็นไปในทางเดียวกัน</p><pre>from sklearn.manifold import TSNE<br>tsne = TSNE(n_components=2, verbose=0, perplexity=30, max_iter=1000)<br>tsne_result = tsne.fit_transform(X_subset)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*WXbhshRmCDNR5QsovnZfHQ.png" /></figure><p>จะเห็นได้ชัดเลยใช่มะว่ามัน down dimension ออกมาข้อมูลแยกกลุ่มกันตาม class ของรูปภาพชัดเจนขึ้นเยอะ เพราะ t-SNE มันเข้าใจ data ที่ non-linear, ไม่เป็นเส้นตรงได้ดีกว่า PCA มาก</p><p>ข้อดี</p><ul><li>แบ่งกลุ่ม data ได้ดีแม้จะมี non-linearity แต่มันจะรักษา structure เหล่านั้นมาแสดงผลให้เราดูได้</li></ul><p>ข้อเสีย</p><ul><li>ช้ามากๆ เป็นวิธีที่ช้าที่สุดในทั้งสามอันเลย</li></ul><p>3. UMAP</p><p>มันมอง distance and data points เป็น graph โดยจัดกลุ่มด้วย k-nearest neighbor แล้วก็ รวบรวม graph ต่างๆเข้าด้วยกัน มันจะมี graph ของ low dim กับ high dimensional representation graph แล้วก็ค่อยๆ ปรับ graph เหมือน t-SNE</p><pre>import umap.umap_ as umap<br>reducer = umap.UMAP(n_components=2)<br>umap_result = reducer.fit_transform(X_subset)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*nrawm4x1-NrD1FC_gacijQ.png" /></figure><p>ข้อดี</p><ul><li>เร็วกว่า t-SNE เยอะ แม้จะยังช้ากว่า PCA</li><li>จัดการกับ non-linearity ได้ดี เช่นเดียวกับ t-SNE นอกจากนั้นยังรักษา global structure ได้ดีกว่า</li><li>นับว่าเป็นวิธีที่รวดเร็วและดีที่สุดแบบ optimal เลยก็ว่าได้ ผมใช้บ่อยอยู่ โดยเฉพาะการส่อง embedding เพื่อ overview synthetic dataset</li></ul><h3>ว่าด้วย non-linearity</h3><p>ผมขอยกตัวอย่าง dataset ที่นำมาแสดง non-linearity problem ของ PCA ด้วย Mammoth dataset นะครับ เนื่องจากมันเป็น dataset ที่มี 3 dimensionality ที่ผมสามารถ plot ให้ดูได้ง่ายโดยตรง และทุกคนเห็นภาพน้องช้าง นอนชัดเจน และผมจะ reduce dimensionality to 2D ด้วยวิธีต่างๆที่แสดงไปก่อนหน้านี้ และมันจะแดสงถึงข้อจำกัดของ linear method แบบ PCA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*PV45SjEgi9GTCLmKNK5tPA.png" /></figure><p>PCA จะฉาย projection ลงไปตรงๆ ในระนาทที่รักษาข้อมูลมากที่สุด แต่รายละเอียด ร่างกายตามแนวยาว ค่อนข้างเสียหายไปหมดเลย, ผมเลือกสีตามแกน z หรือความสูง ตามที่ช้างมันล้มลงนะ เพื่อให้เห็นข้อมูลที่เสียไปจาก linear projection ของ PCA ชัดๆ ว่าข้างขวา กับซ้ายมันทับกัน แต่ขายังแยกออกว่าคนละข้างซ้ายกับขวา เพราะ PCA มันพยายามหาแกนที่รักษารายละเอียดเอาไว้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*tDbEThHUzAsxaCod1IWGqA.png" /></figure><p>t-SNE กับ UMAP จะจัดการรักษา non-linear information ได้ดีกว่า local structures, ซ้ายขวา แสดงออกมาได้ โดย t-SNE จะเน้น local structure ได้ดีกว่า UMAP เราจะเห็นเขาซ้ายขวา ซี่โครงซ้ายขวาแบบไม่ซ้อนทับกันเลย.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*VmrgJBPmX0GkrXHs59qYpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*8pyNd44_lZ197Pu5wFyIrg.png" /></figure><p>ตามคำอธิบายตามทฤษฏี คือ UMAP จะรักษา structure ได้ดีกว่า t-SNE เพราะมันจะสนใจทั้ง local และ global structure, คงสภาพของที่อยู่ใกล้กันทั้งงา และระยะห่างจากของที่อยู่ไกลเช่นหาง ในขณะที่ t-SNE จะเน้น local structure.</p><h3>Latent Visualization</h3><p>ก่อนหน้านี้เราก็ดูกันเรื่อง dimensionality reduction กันไปเรียบร้อยแล้วนะครับ. methods พวกนี้ค่อนข้าง powerful พอสมควร สามารถแยกแยะ dataset ได้โดยไม่ต้องใช้ embedding ของ neural network models ในระดับหนึ่ง ที่ทำไปกับ MNIST เราใช้แค่ pixel ของภาพโดยตรงเข้าอัลกอลิทิม dimensionality reduction แต่ dataset MNIST มันค่อนข้างจะเป็น dataset ที่ง่ายนะ คราวนี้ผมจะแสดงถึงขีดจำกัดของการใช้ dimensionality reduction กับข้อมูลโดยตรงด้วย CIFAR-10 (Canadian Institute For Advanced Research) เป็น dataset ภาพ 3 สี ที่มแต่ละภาพมีขนาด 32x32 pixel สรุปเป็น dimensionality (32,32,3) หรือ 3072 มิติ (3072 of CIFAR-10 &gt;&gt; 784 of MNIST)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/0*6t8OIw2M1tnarkz1" /><figcaption>sample from CIFAR-10</figcaption></figure><p>ผมจะแสดงให้เห็นว่า dimensionality reduction methods ที่ถูกกล่าวถึงก่อนหน้านี้มันใช้ไม่ได้แล้วเมื่อ complexity ของ dataset เพิ่มขึ้นโดยเราจะ rerun algorithm ทั้งสามอันที่ได้กล้าวถึงไว้ก่อนหน้า</p><p><strong>PCA</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*lYKkhH7YOtfLSN0-FTE2_g.png" /></figure><p><strong>t-SNE</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*RVEp1Su6yDCiqjFOQ1xp8A.png" /></figure><p><strong>UMAP</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*Wzk76D2vCTCFyf_n5HDM0g.png" /></figure><p>จะเห็นได้ชัดเจนเลยว่า class ต่างๆไม่แยกออกจากกันและกระจัดกระจายแบบดูไม่ค่อยมีความหมาย ซึ่งมันเป็นขีดจำกัดของการใช้ dimensionality reduction methods พวกนี้กับ dataset โดยตรง</p><p>แต่ถ้าเราสามารถใช้ dimensionality reduction methods พวกนี้มาทำความเข้าใจ latent representation ของ AI ได้ว่ามันมองภาพแล้วเข้าใจว่าภาพแบบไหน เหมือนกับภาพกลุ่มไหน ข้อมูลกระจัดกระจายอย่างไร</p><p>ในที่นี้ผมเลือก Siglip2 model (<a href="https://huggingface.co/google/siglip2-base-patch16-224">https://huggingface.co/google/siglip2-base-patch16-224</a>) ถูกสร้างขึ้นโดย Google, เป็น one of the best vision language model ที่ใช้ transformers ทำขึ้นมา. มันสามารถเข้าใจทั้งภาพและภาษาได้ แต่ในตอนนี้ผมจะแสดงให้เห็นว่ามันเห็นภาพเหล่านี้ และมองการกระจุกของข้อมูลอย่างไร</p><pre>import torch<br>from transformers import AutoModel, AutoProcessor<br>from transformers.image_utils import load_image</pre><pre># load the model and processor<br>ckpt = &quot;google/siglip2-base-patch16-224&quot;<br>model = AutoModel.from_pretrained(ckpt, device_map=&quot;auto&quot;).eval()<br>processor = AutoProcessor.from_pretrained(ckpt)</pre><pre># load the image<br>image = load_image(&quot;https://huggingface.co/datasets/merve/coco/resolve/main/val2017/000000000285.jpg&quot;)<br>inputs = processor(images=[image], return_tensors=&quot;pt&quot;).to(model.device)</pre><pre># run infernece<br>with torch.no_grad():<br>    image_embeddings = model.get_image_features(**inputs)    </pre><pre>print(image_embeddings.shape)</pre><pre># output: torch.Size([1, 768])<br># ข้อมูลแต่ละตัวถูก model แปลงเป็น embeddingขนาด 768 dimension</pre><p>Embedding ของ siglip จะมีขนาด 768 dimension ซึ่งเราไม่สามารถ plot ลงไปได้โดยตรงเช่นเดียวกับ image pixels ก่อนหน้านี้ ก็เลยยังใช้ทั้ง 3 dimensionality reduction methods ทั้งสามอันก่อนหน้า</p><p><strong>PCA</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*-35Kt2k71_C5qsvcchjm8w.png" /></figure><p><strong>t-SNE</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*t1pY_TE7TaxesELjgVc-BA.png" /></figure><p><strong>UMAP</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*2_MWOLyGk2vZznU3biqNMg.png" /></figure><p>เท่านี้เราก็จะได้ latent visualization ที่แสดงการเกาะกลุ่มของ dataset ของ Siglip2 นอกจาก input ที่เป็นภาพนี้ text, audio, and other modal ก็สามารถแสดงแบบนี้ได้ด้วย แต่ต้องหา model ที่เหมาะสมมา encode</p><h3>Recap</h3><ul><li>เราได้เห็น 3 prevalent methods ในการทำ dimensionality reduction in pixel space ของรูปภาพ</li><li>นอกจากนี้เราก็ได้เห็นขีดจำกัดของ linear dimensionality reduction ของ PCA ด้วย Mammoth dataset</li><li>รวมถึงข้อจำกัดของ dimensionality reduction on pixel ว่าสุดท้ายพอเพิ่ม complexity, methods ต่างๆก็แยกแยะ cluster ไม่ได้</li><li>และจบเรื่องราวของ blog นี้ด้วยการ visualize latent ของ neural network model, Siglip2</li></ul><h3>Resources:</h3><ul><li>my notebook for these visualizations: <a href="https://colab.research.google.com/drive/1PcTd6hWOG6fPMPG9qNTv6fcueA48xp75?usp=sharing">https://colab.research.google.com/drive/1PcTd6hWOG6fPMPG9qNTv6fcueA48xp75?usp=sharing</a></li><li>A nice YouTube video to illustrate this concept: <a href="https://www.youtube.com/watch?v=o_cAOa5fMhE">https://www.youtube.com/watch?v=o_cAOa5fMhE</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=781e602db93f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ruffblitz/latent-visualization-781e602db93f">Latent Visualization</a> was originally published in <a href="https://medium.com/ruffblitz">RuffBlitz</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grokking at the Edge of Numerical Stability]]></title>
            <link>https://medium.com/@winroom/grokking-at-the-edge-of-numerical-stability-39a6b2ef74e6?source=rss-e9c9b046095a------2</link>
            <guid isPermaLink="false">https://medium.com/p/39a6b2ef74e6</guid>
            <dc:creator><![CDATA[Nah, I would win]]></dc:creator>
            <pubDate>Fri, 10 Jan 2025 16:22:28 GMT</pubDate>
            <atom:updated>2025-01-10T16:22:28.228Z</atom:updated>
            <content:encoded><![CDATA[<p>reference: <a href="https://arxiv.org/abs/2501.04697">https://arxiv.org/abs/2501.04697</a></p><p>ผมไปเจอเรื่องน่าสนใจมา เกี่ยวกับ Grokking without weight decay น่ะ</p><p>เริ่มจาก Grokking คืออะไรก่อนเลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*IlqAWjaobuy86ykCDjottA.png" /></figure><p>Grokking คือการที่ neural network model มัน train จน overfit ไปแล้วซักพักเกิดการ generalizationขึ้นอย่างฉับพลัน เราจะเห็น example ที่ผมไป crop รูปมาได้เลยว่า training set โดน overfitted ไปซักพักใหญ่มากๆ model ถึงค่อย improve test set แสดงถึงความสามารถในการ generalization</p><p>ถ้างั้นงาน Grokking at the Edge of Numerical Stability มีอะไรมาเล่าละ?</p><p>ปรกติ model ที่มัน Grokk อ่ะ <a href="https://arxiv.org/abs/2201.02177">https://arxiv.org/abs/2201.02177</a> มันพึ่งพาพวก regularization เช่น weight decay ให้เกิด Grokking phenomena. แต่ Grokking at the Edge of Numerical Stability มองไปยังจุด/ปัญหาอื่นที่ขัดขวาง generalization of the model นั่นคือ softmax collapse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/129/1*7J_WCxd4osXhqnreXEDg7w.png" /></figure><p>Softmax คือ activation function ยอดนิยมที่เราใช้กันใน decision making ของ output layer ของ neural network และทั้งใน attention layer. งานนี้น่ะมองว่ามันเกิดปัญหาที่เรียกว่า Softmax Collapse เมื่อ logit ของ class ที่ถูกต้องมันเยอะมากจนบดบัง class อื่นๆที่ผิด และ absorb ให้พวก exponential ของพวกนั้น insignificant/vanish ภายใต้ floating point precision ที่จำกัด</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*ca_BqhyVs2NdrJhj3kzPbg.png" /></figure><p>ปรกติ เวลาเรา train neural network เราจะใช้ floating point แบบ 16 หรือ 32 bit กัน ซึ่งนั้นก็อาจจะทำให้เกิด Softmax Collapse ได้ ถ้า numerical precision ไม่มากพอจน large term (of the correct class) absorb exponent terms of other classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*739G1u0DCwBUehNZuvKDUg.png" /></figure><p>เพราะ Gradient ของ correct class จะกลายเป็น 0 และขัดขวาง Grokking</p><p>Experiment on various floating precision in the study</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PhR5eNPi2iiPRsRLxgpELw.png" /></figure><p>โห แล้วไงอ่ะ เราต้องใช้ floating point ใหญ่ขนาดนั้นเลยเหรอในการ train NN?</p><p>“Nah, I would win.” -เจ้าของ paper ไม่ได้กล่าวไว้</p><p>เขาออกแบบ new version of Softmax เอาไว้ ภายใต้ชื่อว่า StableMax</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*TD9HAZ-pu33uLMfuJFJS1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*KdhTLaCYCJaq2BpuinyYsw.png" /></figure><p>มันเป็น Softmax ที่ logit of each class growth นุ่มนวลขึ้น แทนที่จะ ramp up exponentially เมื่อเทียบกับ e**x ของ softmax</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*lTR6sVFiDv8NVXxAjgBMXw.png" /></figure><p>Then, the Grokking can happen without the weight decay. แต่ story ของ paper นี้ยังไม่จบ แต่ผมขี้เกียจเขียนละ เดี๋ยว data พวกนี้ก็คงโดน scraped เอาไปทำ text-image interleaved for vision language model ด้วยรึเปล่านะ พวก text สลับกับภาพ ช่วย few-shot learning in VLM</p><p>บายยยย</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39a6b2ef74e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>