<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.3.4">Jekyll</generator><link href="https://ofey.me/feed.xml" rel="self" type="application/atom+xml"/><link href="https://ofey.me/" rel="alternate" type="text/html" hreflang="en"/><updated>2026-08-11T02:04:03+00:00</updated><id>https://ofey.me/feed.xml</id><title type="html">blank</title><subtitle>Associate professor @ Institute of Computing Technology, Chinese Academy of Sciences (ICT, CAS). </subtitle><entry><title type="html">TikZ Gallery</title><link href="https://ofey.me/blog/2025/tikz-gallery/" rel="alternate" type="text/html" title="TikZ Gallery"/><published>2025-06-20T22:30:00+00:00</published><updated>2025-06-20T22:30:00+00:00</updated><id>https://ofey.me/blog/2025/tikz-gallery</id><content type="html" xml:base="https://ofey.me/blog/2025/tikz-gallery/"><![CDATA[<h2 id="two-system-comparison">two system comparison</h2> <div class="row mt-3"> <div class="col-sm mt-3 mt-md-0"> <a href="https://raw.githubusercontent.com/FeiSun/LaTeX-Drawing/refs/heads/master/Drawing/editing_eval.tex" target="_blank"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/blog/latex/editing_evaluation-480.webp 480w,/assets/img/blog/latex/editing_evaluation-800.webp 800w,/assets/img/blog/latex/editing_evaluation-1400.webp 1400w," type="image/webp" sizes="95vw"/> <img src="/assets/img/blog/latex/editing_evaluation.png" class="img-fluid rounded z-depth-1" width="100%" height="auto" loading="eager" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </a> </div> </div> <div class="caption"> ACL 2025 paper <em><a href="https://arxiv.org/abs/2502.11177" target="_blank">The Mirage of Model Editing: Revisiting Evaluation in the Wild</a></em> </div> <ul> <li><code class="language-plaintext highlighter-rouge">TikZ pics</code> for reusable components: Defines a pics/self_att module (the abstract module in ROME paper) containing hidden states, MHA, and MLP layers that can be instantiated repeatedly, streamlining neural network diagram creation.</li> </ul>]]></content><author><name></name></author><category term="latex"/><category term="latex"/><category term="tikz"/><summary type="html"><![CDATA[A collection of TikZ examples in my papers.]]></summary></entry><entry><title type="html">Embedding Heatmaps in LaTeX Tables</title><link href="https://ofey.me/blog/2025/latex-table-heatmap/" rel="alternate" type="text/html" title="Embedding Heatmaps in LaTeX Tables"/><published>2025-06-15T22:30:00+00:00</published><updated>2025-06-15T22:30:00+00:00</updated><id>https://ofey.me/blog/2025/latex-table-heatmap</id><content type="html" xml:base="https://ofey.me/blog/2025/latex-table-heatmap/"><![CDATA[<p>In our ACL 2025 paper <em><a href="https://arxiv.org/abs/2502.11177">The Mirage of Model Editing: Revisiting Evaluation in the Wild</a></em>, we needed a compact yet expressive way to present the performance degradation of model editing methods when moving from synthetic to real-world (Wild) evaluation settings.</p> <p>The most natural way to highlight these performance drops is through a heatmap, where deeper colors indicate larger decreases. However, manually adding background colors to each table cell in LaTeX and calculating appropriate color gradients would be extremely tedious and error-prone.</p> <p>To address this, we designed a LaTeX table that <strong>automatically applies heatmap-style background coloring</strong> to each cell based on the <strong>relative performance drop</strong>, using TikZ to dynamically compute and render the shading intensity. This approach provides a clear visual signal for how robust—or brittle—editing methods are under realistic evaluation.</p> <p>Here’s what the final result looks like:</p> <div class="row mt-3"> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" srcset="/assets/img/blog/table_heatmap-480.webp 480w,/assets/img/blog/table_heatmap-800.webp 800w,/assets/img/blog/table_heatmap-1400.webp 1400w," type="image/webp" sizes="95vw"/> <img src="/assets/img/blog/table_heatmap.png" class="img-fluid rounded z-depth-1" width="100%" height="auto" loading="eager" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> </div> <h2 id="implementation">Implementation</h2> <h3 id="heatmap">heatmap</h3> <p><code class="language-plaintext highlighter-rouge">\numwild{&lt;wild_value&gt;}{&lt;synthetic_value&gt;}</code></p> <p>This is the core macro. It compares the WILD score with the corresponding synthetic score and calculates the percentage drop. Then, it dynamically fills the background color intensity using TikZ.</p> <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\newcommand</span><span class="p">{</span><span class="k">\numwild</span><span class="p">}</span>[2]<span class="p">{</span>
    <span class="nt">\begin{tikzpicture}</span>[baseline]
        <span class="k">\pgfmathparse</span><span class="p">{</span>#1 &gt; #2 ? 1 : 0<span class="p">}</span>
        <span class="k">\ifnum\pgfmathresult</span>=0
            <span class="k">\pgfmathsetmacro</span><span class="p">{</span><span class="k">\percentdiff</span><span class="p">}{</span>min(130, 130*(#2-#1)/#2)<span class="p">}</span>
            <span class="k">\pgfmathsetmacro</span><span class="p">{</span><span class="k">\intensity</span><span class="p">}{</span><span class="k">\percentdiff</span><span class="p">}</span>
            <span class="k">\fill</span><span class="na">[monte_carlo!\intensity!white, rounded corners=1]</span> (-0.6em, -0.3em) rectangle (2.6em, 1em);
        <span class="k">\fi</span>
        <span class="k">\node</span><span class="na">[inner sep=0pt]</span> at (1em, 0.7ex) <span class="p">{</span>#1<span class="p">}</span>;
    <span class="nt">\end{tikzpicture}</span>
<span class="p">}</span>
</code></pre></div></div> <h4 id="how-it-works">How It Works</h4> <ol> <li> <p><strong>Input Parameters</strong>: The command takes two arguments - the Wild evaluation score (<code class="language-plaintext highlighter-rouge">#1</code>) and the synthetic evaluation score (<code class="language-plaintext highlighter-rouge">#2</code>).</p> </li> <li> <p><strong>Conditional Coloring</strong>: It only applies coloring when the Wild score is lower than the synthetic score (indicating a performance drop).</p> </li> <li><strong>Color Intensity Calculation</strong>: The intensity is calculated as a percentage of the performance drop, capped at 130% to ensure visibility: <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\pgfmathsetmacro</span><span class="p">{</span><span class="k">\percentdiff</span><span class="p">}{</span>min(130, 130*(#2-#1)/#2)<span class="p">}</span>
</code></pre></div> </div> </li> <li><strong>Background Rendering</strong>: A filled rectangle with rounded corners is drawn behind the text: <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\fill</span><span class="na">[monte_carlo!\intensity!white, rounded corners=1]</span> 
      (-0.6em, -0.3em) rectangle (2.6em, 1em);
</code></pre></div> </div> <ul> <li><strong>Color mixing</strong>: <code class="language-plaintext highlighter-rouge">monte_carlo!\intensity!white</code> creates a blend between the <code class="language-plaintext highlighter-rouge">monte_carlo</code> color and white, where <code class="language-plaintext highlighter-rouge">\intensity</code> (0-130) controls the mixing ratio</li> <li><strong>Rectangle coordinates</strong>: <ul> <li>Bottom-left corner: <code class="language-plaintext highlighter-rouge">(-0.6em, -0.3em)</code> - starts 0.6em to the left and 0.3em below the baseline</li> <li>Top-right corner: <code class="language-plaintext highlighter-rouge">(2.6em, 1em)</code> - extends 2.6em to the right and 1em above the baseline</li> <li>This creates a rectangle that’s 3.2em wide and 1.3em tall, providing adequate padding around the number</li> </ul> </li> </ul> </li> <li><strong>Text Display</strong>: The Wild evaluation value is positioned at the center of the colored background: <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\node</span><span class="na">[inner sep=0pt]</span> at (1em, 0.7ex) <span class="p">{</span>#1<span class="p">}</span>;
</code></pre></div> </div> <ul> <li><strong>Position</strong>: <code class="language-plaintext highlighter-rouge">(1em, 0.7ex)</code> places the text 1em from the left (roughly centered in the 3.2em wide rectangle) and 0.7ex above the baseline</li> <li><strong><code class="language-plaintext highlighter-rouge">inner sep=0pt</code></strong>: Removes default padding around the node to ensure precise positioning</li> <li>The <code class="language-plaintext highlighter-rouge">ex</code> unit (x-height) is used for vertical positioning to maintain proper alignment with surrounding text</li> </ul> </li> </ol> <p><strong>Note</strong>: These coordinates work well for our specific use case, but you may need to adjust them.</p> <h3 id="color-bar-implementation">Color Bar Implementation</h3> <p>To help readers interpret the heatmap, we include a vertical color bar:</p> <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\newcommand</span><span class="p">{</span><span class="k">\colorbarvertical</span><span class="p">}{</span>
    <span class="nt">\begin{tikzpicture}</span>
        <span class="c">% Create smooth vertical gradient</span>
        <span class="k">\shade</span>[top color=white, 
               bottom color=monte<span class="p">_</span>carlo!150, 
               rounded corners=0.6] (0, 0) rectangle (0.3, 6);
        <span class="c">% Add scale markers</span>
        <span class="k">\foreach</span> <span class="k">\y</span> in <span class="p">{</span>0,0.1,...,1<span class="p">}</span> <span class="p">{</span>
            <span class="k">\pgfmathsetmacro</span><span class="p">{</span><span class="k">\percentage</span><span class="p">}{</span><span class="k">\y*</span>100<span class="p">}</span>
            <span class="k">\draw</span><span class="na">[white, semithick]</span> (0.25, 6-<span class="k">\y*</span>6) -- (0.3, 6-<span class="k">\y*</span>6);
            <span class="k">\draw</span><span class="na">[white, semithick]</span> (0, 6-<span class="k">\y*</span>6) -- (0.05, 6-<span class="k">\y*</span>6);
            <span class="k">\node</span><span class="na">[right]</span> at (0.25, 6-<span class="k">\y*</span>6) 
                  <span class="p">{</span><span class="k">\footnotesize</span> <span class="k">\pgfmathprintnumber</span><span class="na">[fixed,precision=0]</span><span class="p">{</span><span class="k">\percentage</span><span class="p">}}</span>;
        <span class="p">}</span>
        <span class="k">\node</span><span class="na">[right]</span> at (0.25, 0) <span class="p">{</span><span class="k">\footnotesize</span> <span class="k">\pgfmathprintnumber</span><span class="na">[fixed,precision=0]</span><span class="p">{</span>100<span class="p">}}</span>;
        <span class="k">\node</span><span class="na">[right]</span> at (0.15, 6.5) <span class="p">{</span><span class="k">\small</span> <span class="k">\textbf</span><span class="p">{</span><span class="k">\%</span><span class="p">}}</span>;
        <span class="k">\node</span><span class="na">[right]</span> at (0.15, 7.7) <span class="p">{}</span>;
    <span class="nt">\end{tikzpicture}</span>
<span class="p">}</span>
</code></pre></div></div> <h4 id="how-it-works-1">How It Works</h4> <ol> <li><strong>Gradient Background</strong>: <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\shade</span>[top color=white, 
       bottom color=monte<span class="p">_</span>carlo!150, 
       rounded corners=0.6] (0, 0) rectangle (0.3, 6);
</code></pre></div> </div> <ul> <li>Creates a rectangle from (0,0) to (0.3, 6) - that’s 0.3 units wide and 6 units tall</li> <li><code class="language-plaintext highlighter-rouge">\shade</code> produces a smooth gradient from white at the top to 150% intensity monte_carlo at the bottom</li> <li>The <code class="language-plaintext highlighter-rouge">!150</code> creates an over-saturated color for better visual impact</li> <li>Rounded corners add a polished look</li> </ul> </li> <li><strong>Scale Markers</strong>: <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\draw</span><span class="na">[white, semithick]</span>(0.25, 6-<span class="k">\y*</span>6) -- (0.3, 6-<span class="k">\y*</span>6);
<span class="k">\draw</span><span class="na">[white, semithick]</span> (0, 6-<span class="k">\y*</span>6) -- (0.05, 6-<span class="k">\y*</span>6);
</code></pre></div> </div> <ul> <li>Creates clean straight lines on the left side of the color bar</li> </ul> </li> <li><strong>Percentage Labels</strong>: <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">\node</span><span class="na">[right]</span> at (0.25, 6-<span class="k">\y*</span>6) 
      <span class="p">{</span><span class="k">\footnotesize</span> <span class="k">\pgfmathprintnumber</span><span class="na">[fixed,precision=0]</span><span class="p">{</span><span class="k">\percentage</span><span class="p">}}</span>;
</code></pre></div> </div> <ul> <li>Places percentage values to the right of the color bar</li> <li><code class="language-plaintext highlighter-rouge">\pgfmathprintnumber[fixed,precision=0]</code> formats numbers without decimal places</li> <li>The manual “100” at the bottom avoids potential floating-point issues.</li> </ul> </li> </ol> <h3 id="usage-in-tables">Usage in Tables</h3> <p>Using this approach in your tables is straightforward. Here’s a minimal example of how to use this in a table:</p> <div class="language-latex highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">\begin{table}</span>
<span class="nt">\begin{minipage}</span><span class="p">{</span>0.94<span class="k">\textwidth</span><span class="p">}</span>
<span class="nt">\begin{tabular}</span><span class="p">{</span>l cc cc<span class="p">}</span>
<span class="k">\toprule</span>
Method <span class="p">&amp;</span> <span class="k">\multicolumn</span><span class="p">{</span>2<span class="p">}{</span>c<span class="p">}{</span>Reliability<span class="p">}</span> <span class="p">&amp;</span> <span class="k">\multicolumn</span><span class="p">{</span>2<span class="p">}{</span>c<span class="p">}{</span>Generalization<span class="p">}</span> <span class="k">\\</span>
       <span class="p">&amp;</span> syn. <span class="p">&amp;</span> <span class="k">\textsc</span><span class="p">{</span>Wild<span class="p">}</span> <span class="p">&amp;</span> syn. <span class="p">&amp;</span> <span class="k">\textsc</span><span class="p">{</span>Wild<span class="p">}</span> <span class="k">\\</span>
<span class="k">\cmidrule</span>(lr)<span class="p">{</span>2-3<span class="p">}</span> <span class="k">\cmidrule</span>(lr)<span class="p">{</span>4-5<span class="p">}</span>
FT-M   <span class="p">&amp;</span> 1.000 <span class="p">&amp;</span> <span class="k">\numwild</span><span class="p">{</span>0.562<span class="p">}{</span>1.000<span class="p">}</span> <span class="p">&amp;</span> 0.950 <span class="p">&amp;</span> <span class="k">\numwild</span><span class="p">{</span>0.470<span class="p">}{</span>0.950<span class="p">}</span> <span class="k">\\</span>
MEND   <span class="p">&amp;</span> 0.967 <span class="p">&amp;</span> <span class="k">\numwild</span><span class="p">{</span>0.288<span class="p">}{</span>0.967<span class="p">}</span> <span class="p">&amp;</span> 0.949 <span class="p">&amp;</span> <span class="k">\numwild</span><span class="p">{</span>0.244<span class="p">}{</span>0.949<span class="p">}</span> <span class="k">\\</span>
ROME   <span class="p">&amp;</span> 0.964 <span class="p">&amp;</span> <span class="k">\numwild</span><span class="p">{</span>0.741<span class="p">}{</span>0.964<span class="p">}</span> <span class="p">&amp;</span> 0.811 <span class="p">&amp;</span> <span class="k">\numwild</span><span class="p">{</span>0.656<span class="p">}{</span>0.811<span class="p">}</span> <span class="k">\\</span>
<span class="k">\bottomrule</span>
<span class="nt">\end{tabular}</span>
<span class="nt">\end{minipage}</span>
<span class="nt">\end{minipage}</span>
<span class="k">\hfil</span>
<span class="nt">\begin{minipage}</span><span class="p">{</span>0.05<span class="k">\textwidth</span><span class="p">}</span>
<span class="k">\colorbarvertical</span>
<span class="nt">\end{minipage}</span>
<span class="k">\caption</span><span class="p">{</span>Performance comparison with automatic heatmap coloring<span class="p">}</span>
<span class="nt">\end{table}</span>
</code></pre></div></div> <h2 id="benefits">Benefits</h2> <ol> <li><strong>Automatic Calculation</strong>: No need to manually calculate color intensities for each cell</li> <li><strong>Consistent Visualization</strong>: Ensures uniform color mapping across all cells</li> <li><strong>Easy Maintenance</strong>: Changing values automatically updates the visualization</li> <li><strong>Customizable</strong>: Easy to adjust color schemes, intensity calculations, or cell styling</li> </ol>]]></content><author><name></name></author><category term="latex"/><category term="latex"/><category term="visualization"/><category term="tikz"/><category term="heatmap"/><summary type="html"><![CDATA[How to use TikZ to add dynamic heatmap shading to LaTeX table cells.]]></summary></entry></feed>