<?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 Ruite Xiang on Medium]]></title>
        <description><![CDATA[Stories by Ruite Xiang on Medium]]></description>
        <link>https://medium.com/@ruite.xiang?source=rss-fdec56935368------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wagTHEUBCIYj7FjNLqzkRA.png</url>
            <title>Stories by Ruite Xiang on Medium</title>
            <link>https://medium.com/@ruite.xiang?source=rss-fdec56935368------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 04:53:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ruite.xiang/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[5 Key Lessons From My Python Journey To Improve Your Code and Fast-Track Your Progress]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://blog.stackademic.com/5-key-lessons-from-my-python-journey-to-improve-your-code-and-fast-track-your-progress-7303f6832cd5?source=rss-fdec56935368------2"><img src="https://cdn-images-1.medium.com/max/2600/1*xuxGLSmR_-OxMWnOVgR7JQ.jpeg" width="5472"></a></p><p class="medium-feed-snippet">Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.</p><p class="medium-feed-link"><a href="https://blog.stackademic.com/5-key-lessons-from-my-python-journey-to-improve-your-code-and-fast-track-your-progress-7303f6832cd5?source=rss-fdec56935368------2">Continue reading on Stackademic »</a></p></div>]]></description>
            <link>https://blog.stackademic.com/5-key-lessons-from-my-python-journey-to-improve-your-code-and-fast-track-your-progress-7303f6832cd5?source=rss-fdec56935368------2</link>
            <guid isPermaLink="false">https://medium.com/p/7303f6832cd5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[lessons-learned]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Ruite Xiang]]></dc:creator>
            <pubDate>Thu, 01 Feb 2024 14:16:57 GMT</pubDate>
            <atom:updated>2024-02-01T14:16:57.528Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[PyTorch for Beginners: 7 Good Practices to Improve Your Model Development]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://pub.towardsai.net/pytorch-for-beginners-7-good-practices-to-improve-your-model-development-8777bed00ecd?source=rss-fdec56935368------2"><img src="https://cdn-images-1.medium.com/max/2600/1*wGxmcQwXRvEqJUIDN5U27g.jpeg" width="6836"></a></p><p class="medium-feed-snippet">Build a Strong PyTorch Foundation and Create Reliable Machine Learning Models.</p><p class="medium-feed-link"><a href="https://pub.towardsai.net/pytorch-for-beginners-7-good-practices-to-improve-your-model-development-8777bed00ecd?source=rss-fdec56935368------2">Continue reading on Towards AI »</a></p></div>]]></description>
            <link>https://pub.towardsai.net/pytorch-for-beginners-7-good-practices-to-improve-your-model-development-8777bed00ecd?source=rss-fdec56935368------2</link>
            <guid isPermaLink="false">https://medium.com/p/8777bed00ecd</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ruite Xiang]]></dc:creator>
            <pubDate>Thu, 25 Jan 2024 12:01:42 GMT</pubDate>
            <atom:updated>2024-01-25T12:01:42.981Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Hard Work, Smart Recovery: 7 Activities to Recharge Your Energy and Productivity]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/practice-in-public/hard-work-smart-recovery-7-activities-to-recharge-your-energy-and-productivity-cb1c891d684f?source=rss-fdec56935368------2"><img src="https://cdn-images-1.medium.com/max/2600/1*h3-Rc4FrlP-2oBRco4dSKg.jpeg" width="2760"></a></p><p class="medium-feed-snippet">Treat recovery as seriously as work because it is what fuels your productivity.</p><p class="medium-feed-link"><a href="https://medium.com/practice-in-public/hard-work-smart-recovery-7-activities-to-recharge-your-energy-and-productivity-cb1c891d684f?source=rss-fdec56935368------2">Continue reading on Practice in Public »</a></p></div>]]></description>
            <link>https://medium.com/practice-in-public/hard-work-smart-recovery-7-activities-to-recharge-your-energy-and-productivity-cb1c891d684f?source=rss-fdec56935368------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb1c891d684f</guid>
            <category><![CDATA[health]]></category>
            <category><![CDATA[lifestyle]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[worklife-balance]]></category>
            <dc:creator><![CDATA[Ruite Xiang]]></dc:creator>
            <pubDate>Sat, 20 Jan 2024 03:50:04 GMT</pubDate>
            <atom:updated>2024-01-31T14:36:13.906Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Rebuild Self-Confidence and Self-Esteem after Depression by Challenging Your Assumptions]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/illumination/how-to-rebuild-self-confidence-and-self-esteem-after-depression-by-challenging-your-assumptions-3fdeaeecb384?source=rss-fdec56935368------2"><img src="https://cdn-images-1.medium.com/max/2600/1*Ft-Mynh1YZLbKW-0CT7wxg.jpeg" width="5184"></a></p><p class="medium-feed-snippet">Thanks to cognitive behavioral therapy I overcame my depression and I hope it helps you too</p><p class="medium-feed-link"><a href="https://medium.com/illumination/how-to-rebuild-self-confidence-and-self-esteem-after-depression-by-challenging-your-assumptions-3fdeaeecb384?source=rss-fdec56935368------2">Continue reading on ILLUMINATION »</a></p></div>]]></description>
            <link>https://medium.com/illumination/how-to-rebuild-self-confidence-and-self-esteem-after-depression-by-challenging-your-assumptions-3fdeaeecb384?source=rss-fdec56935368------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fdeaeecb384</guid>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[depression]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[books]]></category>
            <dc:creator><![CDATA[Ruite Xiang]]></dc:creator>
            <pubDate>Wed, 10 Jan 2024 22:05:52 GMT</pubDate>
            <atom:updated>2024-01-13T07:13:59.576Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[A More Intuitive Way To Understand Graph Neural Networks With a Code Example]]></title>
            <link>https://pub.towardsai.net/a-more-intuitive-way-to-understand-graph-neural-networks-with-a-code-example-adc5c196ea20?source=rss-fdec56935368------2</link>
            <guid isPermaLink="false">https://medium.com/p/adc5c196ea20</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[science]]></category>
            <dc:creator><![CDATA[Ruite Xiang]]></dc:creator>
            <pubDate>Thu, 04 Jan 2024 20:01:29 GMT</pubDate>
            <atom:updated>2024-01-04T20:01:29.175Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understand the steps in most GNNs and how they relate to the theory with a sample code</h4><p>Sometimes, it is difficult to understand the theory — the math and the formulas- without seeing how it translates into code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*WsEvnhKCwIC1gSnsee0Pig.png" /><figcaption>Source from the author</figcaption></figure><p>At least, that is my case, so I put together this post to explain the different concepts in graph neural networks (GNNs) in a way that is more intuitive and beginner-friendly, complemented with a code example.</p><p>However, when I say beginners, you might still need to know some concepts such as matrix multiplications and Pytorch.</p><h3>What is a graph?</h3><p>Graphs are used to represent a set of connected objects, modeled as nodes connected via edges that represent their relationships. Each node is described with a feature vector, which is what the GNNs will use to make the predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFeUhBTHA6YinjcMA8Fnmg.png" /><figcaption>Source image from the author</figcaption></figure><p>For each graph with a set of nodes and edges, we would have a feature matrix (X) and information about how the different nodes are connected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEU0ziopYZq9WtXJu5l57w.png" /><figcaption>Source image from the author</figcaption></figure><p>The<strong> </strong>connectivity data can be represented in different formats such as an <strong>adjacency matrix</strong> where 1s represent connections and the row or column index is the edge index.</p><p>In the case of PyTorch Geometric, connectivity is represented in the sparse COO format of shape <strong>[2, num_edges]</strong> with row 0 being the source nodes and row 1 the destination nodes, as you can see in the image.</p><p>It is quite a flexible representation since any data where the relationships between the objects are relevant to the prediction task can benefit from the graph representation.</p><p>Well-known examples include <strong>social networks,</strong> where people are nodes and relationships are edges, and <strong>molecules or drugs,</strong> where atoms are nodes and bonds are edges.</p><h3>Most GNNs consist of 3 steps</h3><p>This formula represents the most basic and popular GNN architecture, the graph convolutional networks, but the steps are very much generalizable. This formula is basically how most GNNs work with some modifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*KJoVKexBh0fYZMy009-yXQ.png" /><figcaption>Modified image from <a href="https://pytorch-geometric.readthedocs.io/en/latest/notes/create_gnn.html">PyTorch Geometric</a></figcaption></figure><ul><li>H’<em>ᵢ</em> is the updated node embedding.</li><li>X is the node features before the update.</li><li>b<em>ᵢ</em> is the bias term.</li><li>W is the learnable weight in a linear layer, for instance.</li><li>Âij is a normalized adjacency matrix, or it could also be attention scores for each node in the GAT (graph attention networks) architecture. Intuitively, we can think that the different edges are weighted differently.</li></ul><h4>Step 1: Transform</h4><p>In this step, the node features are first transformed by some learnable weight matrix, in the case of a GCN it is just a fully connected layer without the bias (<strong>X * W</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x0WtdB-PMUpazaXVV2SthA.png" /><figcaption>Source image from the author</figcaption></figure><h4><strong>Step 2: Aggregate</strong></h4><p>We then apply some aggregation operations like the sum operation (∑); other options include mean or max. However, for each node, only features from connecting nodes will be summed.</p><p>In my example, features from nodes 1 and 2 would be summed to the features from node 0, but for node 1, only features from node 0 would be summed.</p><p>This is also called the <strong>message-passing</strong> step since we are passing the information from the neighboring nodes to the source node.</p><p>This step is achieved by multiplying the normalized adjacency matrix by the transformed weights, which will automatically sum only the connected nodes. The normalization means that each neighbor node will have a different weight when summed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCi5fF63rXQ1T6rqqQkF8Q.png" /><figcaption>Source image from the author</figcaption></figure><p>See in the adjacency matrix that the different nodes are also connected to themselves (it is called the self-loop) so during the matrix multiplication its information will also be included.</p><h3>Step 3: Update</h3><p>Using the source node and the neighboring nodes, we update the source node features.</p><p>After the matrix multiplication, we obtain a new embedding for each node, to which we apply a bias and an activation function to get the updated embeddings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmYOrJIg3wzpdWj0gmiaiA.png" /><figcaption>Source image from the author</figcaption></figure><p>We could say that in this case, the update operation is a sum, however, for other implementations, the update can happen with another learnable function like a linear layer or recurrent neural networks, so another transformation step.</p><h3>Step 4: Repeat or predict</h3><p>We could repeat the process, which means stacking several layers of GCN, or we can pool all the node features into a single feature vector to make some prediction on a property of the graph by adding a final fully connected layer.</p><p>Similarly, for predictions on specific node or edge properties, we can pool information on neighboring nodes and edges.</p><h3>An example from PyTorch Geometric</h3><p>This is an example implementation of GCN extracted from the official page of PyTorch Geometric, where I added an activation function.</p><p>Let’s see how the different steps apply here:</p><pre>import torch<br>from torch.nn import Linear, Parameter, ReLU<br>from torch_geometric.nn import MessagePassing<br>from torch_geometric.utils import add_self_loops, degree<br><br>class GCNConv(MessagePassing):<br>    def __init__(self, in_channels, out_channels):<br>        super().__init__(aggr=&#39;add&#39;)  # &quot;Add&quot; aggregation (Step 5).<br>        self.lin = Linear(in_channels, out_channels, bias=False)<br>        self.bias = Parameter(torch.empty(out_channels))<br>        self.activation = ReLU()<br><br>        self.reset_parameters()<br><br>    def reset_parameters(self):<br>        self.lin.reset_parameters()<br>        self.bias.data.zero_()<br><br>    def forward(self, x, edge_index):<br>        # x has shape [N, in_channels]<br>        # edge_index has shape [2, E]<br><br>        # Step 1: Add self-loops to the adjacency matrix.<br>        edge_index, _ = add_self_loops(edge_index, num_nodes=x.size(0))<br><br>        # Step 2: Linearly transform node feature matrix.<br>        x = self.lin(x)<br><br>        # Step 3: Compute normalization.<br>        row, col = edge_index<br>        deg = degree(col, x.size(0), dtype=x.dtype)<br>        deg_inv_sqrt = deg.pow(-0.5)<br>        deg_inv_sqrt[deg_inv_sqrt == float(&#39;inf&#39;)] = 0<br>        norm = deg_inv_sqrt[row] * deg_inv_sqrt[col]<br><br>        # Step 4-5: Start propagating messages.<br>        out = self.propagate(edge_index, x=x, norm=norm)<br><br>        # Step 6: Apply a final bias vector.<br>        out += self.bias<br>        out = self.activation(out)<br>        return out<br><br>    def message(self, x_j, norm):<br>        # x_j has shape [E, out_channels]<br><br>        # Step 4: Normalize node features.<br>        return norm.view(-1, 1) * x_j</pre><h3>Step 1: Transform</h3><p>We transform the feature matrix with a linear layer or a learnable weight since we are not using bias</p><pre>x = self.lin(x)</pre><h3>Step 2: Aggregate</h3><p>We have to add the self-loop first to the adjacency matrix (in this case represented as a sparse COO format) then we multiply the normalized connectivity matrix by the feature matrix (X). Even though it is in a different format, the resulting operation is the same.</p><pre># Step 1: Add self-loops to the adjacency matrix.<br>edge_index, _ = add_self_loops(edge_index, num_nodes=x.size(0))<br><br># Normalize the connectivity data<br>row, col = edge_index<br>deg = degree(col, x.size(0), dtype=x.dtype)<br>deg_inv_sqrt = deg.pow(-0.5)<br>deg_inv_sqrt[deg_inv_sqrt == float(&#39;inf&#39;)] = 0<br>norm = deg_inv_sqrt[row] * deg_inv_sqrt[col]<br><br># Step 4-5: Start propagating messages.<br>out = self.propagate(edge_index, x=x, norm=norm) # this calls to the message function<br><br>def message(self, x_j, norm):<br>    # x_j has shape [E, out_channels]<br>    # Step 4: Normalize node features.<br>    return norm.view(-1, 1) * x_j</pre><h3>Step 3: Update</h3><p>We apply the bias and the activation function to update the node embeddings.</p><pre># Step 4-5: Start propagating messages.<br>out = self.propagate(edge_index, x=x, norm=norm) # this calls to the message function<br># Step 6: Apply a final bias vector.<br>out += self.bias<br>out = self.activation(out)</pre><h3>Conclusion</h3><p>Just remember that GCNs have 3 steps, and the steps are more or less shared by different GNN architectures like the GAN with small modifications.</p><ul><li>Transformation: Where the node features are transformed by a weight matrix</li><li>Aggregation: Where the different neighboring nodes are summed and normalized.</li><li>Update: Where bias and the activation function are applied to the aggregated features.</li></ul><p>Thank you for reading my post, and I hope it has helped you better understand how GNNs work.</p><h3>Resources</h3><ul><li><strong>Understanding Graph Attention Networks:</strong> <a href="https://www.youtube.com/watch?v=A-yKQamf2Fc&amp;t=113s">https://www.youtube.com/watch?v=A-yKQamf2Fc&amp;t=113s</a></li><li><strong>A Gentle Introduction to Graph Neural Networks:</strong> <a href="https://distill.pub/2021/gnn-intro/">https://distill.pub/2021/gnn-intro/</a></li><li><strong>Creating Message Passing Networks:</strong> <a href="https://pytorch-geometric.readthedocs.io/en/latest/notes/create_gnn.html">https://pytorch-geometric.readthedocs.io/en/latest/notes/create_gnn.html</a></li><li><strong>Graph: Implement a MessagePassing layer in PyTorch Geometric:</strong> <a href="https://zqfang.github.io/2021-08-07-graph-pyg/">https://zqfang.github.io/2021-08-07-graph-pyg/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adc5c196ea20" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/a-more-intuitive-way-to-understand-graph-neural-networks-with-a-code-example-adc5c196ea20">A More Intuitive Way To Understand Graph Neural Networks With a Code Example</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>