<?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 Sanjaye Elayattu on Medium]]></title>
        <description><![CDATA[Stories by Sanjaye Elayattu on Medium]]></description>
        <link>https://medium.com/@sanjaye?source=rss-74427a93676f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*z_X8IaLzdddfIR_k</url>
            <title>Stories by Sanjaye Elayattu on Medium</title>
            <link>https://medium.com/@sanjaye?source=rss-74427a93676f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 07:02:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanjaye/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[Exploring GNN Architectures for Node Classification, Link Prediction and Parent Node prediction for…]]></title>
            <link>https://medium.com/@sanjaye/exploring-gnn-architectures-for-node-classification-link-prediction-and-parent-node-prediction-for-52237bd00395?source=rss-74427a93676f------2</link>
            <guid isPermaLink="false">https://medium.com/p/52237bd00395</guid>
            <category><![CDATA[graph-neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[retail-technology]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[master-data-management]]></category>
            <dc:creator><![CDATA[Sanjaye Elayattu]]></dc:creator>
            <pubDate>Wed, 18 Dec 2024 04:08:02 GMT</pubDate>
            <atom:updated>2024-12-19T05:29:20.529Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploring GNN Architectures for Node Classification, Link Prediction and Parent Node prediction for Merchandise Hierarchies</h3><p>by <a href="https://medium.com/u/a1976c55b870">Fernando Aguilar</a> and <a href="https://medium.com/u/74427a93676f">Sanjaye Elayattu</a></p><p><strong>Abstract</strong></p><p>Graph based machine learning has emerged as a powerful paradigm for addressing complex relationships and dependencies in structured data. This study explores the application of GraphSAGE, Graph Attention Networks (GAT), and Heterogeneous Graph Neural Networks (HeteroGNNs) to three key tasks: node classification, link prediction, and parent node prediction. To enhance the representation of text-rich node attributes and improve downstream predictive performance, we integrate advanced text embedding techniques, including Sentence Transformer and OpenAI’s state-of-the-art language models. Our approach leverages the strengths of these graph neural network architectures to capture both local and global graph structures while incorporating semantic richness from textual data. Experimental results demonstrate the limitations and efficacy of different methods we employed in this study.</p><p><strong>Introduction</strong></p><p>Assigning merchandise to its appropriate hierarchy within the internal taxonomies of retail and wholesale organizations is a persistent and complex challenge. This study explores the application of GNNs for three key tasks in a merchandise taxonomy: node classification link prediction and parent node prediction. First, we establish a baseline using traditional machine learning methods, such as k-nearest neighbors (KNN), to classify items into their respective classes based solely on text embeddings. We then extend this to GNN-based methods for node classification, where the goal is to predict the items’ class.</p><p>We then explore the efficacy of using GraphSage, GAT and HeteroGNN for link prediction tasks. We finally extend the HeteGNN based embeddings to predict parent nodes for products.</p><p>In the following sections, we will discuss:</p><p>a) Evaluating and comparing baseline traditional machine learning approaches with GNN-based models for classification and prediction tasks.</p><p>b) Experimenting with advanced GNN architectures, including GraphSAGE, Heterogeneous Graph Neural Networks (HeteroGNN) to leverage the hierarchical and multi-relational nature of the taxonomy.</p><p>This study compares different approaches to this real world task and demonstrate the efficiency of GNNs for performing tasks with hierarchical and interconnected data over traditional machine learning models.</p><p><strong>Background</strong></p><p>The private dataset used in this study contains a merchandise taxonomy(also referred to as merchandise hierarchy), which is at the heart of business operations in retail and wholesale organizations. This taxonomy is hierarchical and encompasses multiple levels. In addition to the merchandise taxonomy, the dataset includes vendor relationships, linking the products to the vendors supplying them. This data is essential for category management, product information management, inventory management, ecommerce, search optimization, and logistics tasks. Retailers and Wholesalers typically carry hundreds of thousands of products in their catalog/assortments. Merchandise hierarchy organizes these products into classes, which are further grouped into sub departments, departments, sub categories and categories. Category managers, purchasing managers, inventory managers and store managers use the merchandise hierarchy everyday to perform their tasks.</p><p><strong>Dataset Overview and Statistics</strong></p><p>The dataset contains 39,158 unique items, each assigned to a single class within a multi-level taxonomy. The taxonomy levels include category, subcategory, department, subdepartment, class, and item. In addition to the merchandise taxonomy, the dataset includes vendor information through item relationships. The bar plot below shows the unique counts for each taxonomy term, item, and vendors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/0*EyNeAZe2NErjglTB" /></figure><p><strong>Challenges in the Dataset</strong></p><p><strong>Item descriptions are not unique: </strong>The only information provided about the items can be shared by multiple nodes. This could be because items might differ on product size, quantity, brand, or nay other characteristic but not be reflected in the item description. However, these differing items get their own item id and are assigned to a single class. Hence, nodes with the same item description can be assigned to different classes. For example we noticed that the “Mountain Dew” product comes in 12 packs and 24 packs and belonged to two different classes in our dataset.</p><p><strong>Class Imbalance: </strong>Looking at the table below we can see that most classes have less than 35 items each, while there are some classes with significantly more than that as evidenced by a very large standard deviation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*U25jySAN-elN1rx2dRGrvg.png" /><figcaption>Class imbalance in the private dataset</figcaption></figure><p><strong>Motivation</strong></p><p>Assigning merchandise to its appropriate category within a hierarchical taxonomy is a labor intensive task, often requiring subject matter expertise within the organization since each organization has its own internally developed taxonomy. The main motivation for this project is to address this challenge in an automated, yet efficient and highly accurate way. By training GNNs, we aim to leverage teh relational and hierarchical nature of merchandise data to enable more accurate and scalable solutions for item classification tasks.</p><p><strong>Related Work</strong></p><p>The task of assigning objects to their appropriate categories within hierarchical taxonomies intersects with several research domains, including hierarchical classification, graph neural networks (GNNs), and hierarchical loss functions. Below is an overview of key contributions in these areas:</p><p><strong>Hierarchical Classification and Loss Functions:</strong> Traditional classification methods often treat classes as flat and independent, overlooking hierarchical relationships. To address this, Deng et al. introduced a hierarchical loss function that penalizes misclassifications based on the hierarchical distance between classes, thereby incorporating taxonomy structures into the learning process. Further advancing this concept, Villar et al. proposed a weighted hierarchical cross-entropy loss, effectively encoding hierarchical taxonomies to enhance classification accuracy in complex datasets.</p><p><strong>GNNs for Hierarchical Data:</strong> GNNs have emerged as powerful tools for modeling hierarchical and relational data. Ying et al. developed a hierarchical graph representation learning method with differentiable pooling, enabling GNNs to capture hierarchical structures within graphs.</p><p>Similarly, Sobolevsky proposed Hierarchical Graph Neural Networks that integrate hierarchical information into the GNN architecture, improving performance on tasks with hierarchical data.</p><p><strong>Methodology</strong></p><p>This section outlines the methodological approach for analyzing and predicting relationships in the hierarchical merchandise taxonomy. The study is divided into three phases: baseline classification using traditional machine learning, node classification with Graph Neural Networks (GNNs), and link prediction with GNNs. Each phase is designed to leverage increasingly complex techniques to explore the dataset’s hierarchical and relational structure.</p><p><strong>Traditional ML Classification (KNN)</strong></p><p>As a baseline, we applied the K-Nearest Neighbors (KNN) algorithm to classify items into their respective classes. The item nodes were represented using precomputed text embeddings derived from their descriptions, using OpenAI’s text-embedding-3-small model. KNN was chosen for its simplicity and effectiveness in high-dimensional feature spaces. Given that items can share an item description, this task turned into multi-label classification.</p><p><strong>Features: </strong>Text embeddings of items (dimension: 254). <strong>Model Configuration: </strong>The number of neighbors (k), distance metric, and weights, were tuned using grid search with cross-validation to optimize performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*Q6t6IfYIxulExo4dQuLzMA.png" /></figure><p><strong>Best Parameters:</strong> metric=’cosine’, n_neighbors=3, weights=’distance’.</p><p><strong>Evaluation Metrics: </strong>The F1 score was used to evaluate the model performance. The test f1 score is 61.20% and will be used as the benchmark for the next GNN model architectures.</p><p><strong>Node Classification with GNNs</strong></p><p>In this baseline evaluation, we aimed to predict the classification of nodes into one of several categories: category, subcategory, department, subdepartment, class, product, or vendor. The GNN model utilized, referred to as <strong>GNNStack</strong>, consisted of N convolutional layers, followed by a post-message-passing linear layer and log_softmax layer. The output of the model in this scenario is the predicted node classification. Each convolutional layer incorporated either a GraphSAGE or GAT model, which was then followed by a LeakyReLU activation function and dropout for regularization.</p><p>For the node classification task, we specifically evaluated the performance of <strong>SAGEConv</strong> and <strong>GAT</strong> models with two convolutional layers. Two attention heads were used for the GAT model. The <strong>Negative Log-Likelihood Loss (nll_loss)</strong> function was employed for both training and evaluation. Additionally, we experimented with enhancing the node representations by incorporating embeddings generated from <strong>Sentence Transformers</strong> and <strong>OpenAI embeddings</strong>, based on textual descriptions of the nodes. Our experiments showed a very high test accuarcy for the node classification tasks as detailed in the next section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KiyQF0jI8NdMz7pQ" /></figure><h4><strong>Link Prediction using GraphSAGE and GAT:</strong></h4><p>In this experiment, we do a binary classification to predict the existence of parent-child relationship between the two nodes, in this directional, hierarchical graph. We used the <strong>RandomSplitLink </strong>from PyG to split the datasets into train, validation and test datasets and add an equal number of negative samples during training. In these experiments, we treated the input graph as a homogeneous graph (all nodes and relationships are of the same type) and used GraphSAGE and GAT in the convolution layers. The <strong>GNNStack </strong>model used here, consisted of N convolutional layers, followed by a post-message-passing linear layer. Each convolutional layer incorporated either a GraphSAGE or GAT model, which was then followed by a LeakyReLU activation function and dropout for regularization. The output of this model, however, is the learned node embedding.</p><h4><strong>Link Prediction using HeteroGNN(HGNN)</strong></h4><p>To enhance performance and enable deeper exploration, we employed a Heterogeneous Graph Neural Network (HGNN) model in the convolution layer of the GNNStack. In the HGNN configuration, distinct node types were assigned to represent each level of the merchandise hierarchy and vendor nodes. Additionally, separate relationship types were defined to capture the connections between nodes at different hierarchy levels. For instance, the relationship type (‘subcategory’, ‘child of’, ‘category’) was used to represent the link between subcategories and categories via the edge type child of.</p><p>This hierarchical structure was further extended to describe relationships at other levels, such as subdepartment-department, class-subdepartment, and product-class, all represented by the child of edge type. Similarly, products and vendors were connected using the relationship (‘vendor’, ‘supply’, ‘item’). Importantly, the graph was designed without self-loops or edges connecting nodes at the same level of the hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yQ7_aP5dYs-YRC5u" /></figure><p><strong>Link Prediction Task — Training and Evaluation</strong></p><p>For link prediction tasks, edge scores were calculated using the element-wise product of the node embeddings for the two nodes connected by the edge. The scoring process involved an equal number of positive edges (provided in the graph) and negative edges (generated using the RandomSplitLink function). Training and evaluation were performed as a binary classification task, utilizing Binary Cross Entropy Loss. This approach ensured a balanced assessment of link prediction performance.</p><h3><strong>Parent Node Prediction for Merchandise Hierarchy</strong></h3><p>In the retail and wholesale businesses, merchandise hierarchies are traditionally defined manually by business managers. However, with new products arriving daily, it is essential to develop automated methods for assigning products to the appropriate taxonomy. In this study, we investigate the potential of our node embeddings to identify the parent node for a given product node within the merchandise hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QTgZV3_e4mcPAbOqbQ-wvg.png" /><figcaption>MH GNN pipeline</figcaption></figure><p>For these experiments, we leveraged the same HeteroGNN model described in the previous section. However, the optimization task here is framed as a multi-class classification problem; we named this model MH GNN. Since this task focuses primarily on the product node type, we evaluated the model’s ability to predict the parent node at various levels of the hierarchy, including merchandise class, subdepartment, department, subcategory, and category. The machine learning pipeline included the HeteroGNN model and a parent predictor model (together we call this a MH GNN model). The node embeddings for product and target nodes were used to calculate attention score followed by a linear transformation to output the logits. The diagram above shows the MH GNN pipeline which includes the HeteroGNN followed by the parent predictor.</p><p>Our results revealed that the model demonstrated significantly better performance in predicting higher-level parent nodes (e.g., category, subcategory, and department) compared to immediate parents at lower levels of the hierarchy. We attribute this disparity to the larger number of classes present at lower levels, which introduces greater complexity and challenges for the model to accurately classify lower-level nodes.</p><h3>Experiments and Results</h3><p>This section presents the results of our experiments across three tasks: Node Classification, Link Prediction, and Parent Node Prediction for merchandise hierarchy. For each task, we evaluated multiple GNN architectures and node embedding techniques. The results highlight the performance differences between models and demonstrate the utility of GNNs for capturing hierarchical and relational structures in the merchandise taxonomy.</p><p>The <strong>node classification</strong> task involved predicting the type of a node in the merchandise taxonomy graph (e.g., category, subcategory, department, subdepartment, class, product, or vendor). We evaluated two GNN models, Graph Attention Networks (GAT) and GraphSAGE, using node embeddings derived from two sources: OpenAI text embeddings and Sentence Transformers. The evaluation metric for this task was accuracy for GNNs and F1 score for KNN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*l3I1NrI_zCECY3FAPpCXKw.png" /><figcaption>Node Classification Results</figcaption></figure><p>The results indicate that both GAT and GraphSAGE achieved similar accuracy when using OpenAI embeddings, outperforming models that utilized Sentence Transformer embeddings. This highlights the strength of OpenAI embeddings for representing nodes in the hierarchical structure. However, this is attributed from the lookahead bias since the parent node in the taxonomy, in this case class, is perfectly correlated to the node label and those edges were not removed during training for the masked nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*_LR56xJA4QQVi5v-X5-Xvg.png" /><figcaption>Link Detection — Results</figcaption></figure><p>In the <strong>link prediction</strong> task, we aimed to predict whether a hierarchical “parent-child” relationship exists between two nodes in the merchandise taxonomy. This binary classification problem was evaluated using F1-score, precision, and recall metrics. We experimented with GraphSAGE, GAT, and HeteroGNN (HGNN) architectures, using both OpenAI and Sentence Transformer embeddings.</p><p>HeteroGNN outperformed both GAT and GraphSAGE, achieving the highest F1-score, precision, and recall. Additionally, Sentence Transformer embeddings showed an advantage over OpenAI embeddings in this task, particularly when paired with HeteroGNN. These results demonstrate the effectiveness of heterogeneous modeling and the importance of capturing distinct node and relationship types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*z0it8rULKEQ89eY1RKg0Sw.png" /><figcaption>MH GNN for Parent Node detection</figcaption></figure><p>The <strong>parent node prediction</strong> task evaluated the model’s ability to assign product nodes to their appropriate parent nodes at different levels of the hierarchy. The tasks were to predict merchandise class, sub department, department, sub category levels for a given product. This task was framed as a multi-class classification problem, and the evaluation metric was the prediction accuracy. Our dataset included only one category, so we excluded category prediction from our results. Our experimentation by adding direct edges between the product and its parent nodes at higher level did not yield higher performance. We initially used cosine similarity between the product node embedding and parent node embeddings to get the score. However, our model performed significantly better when we used attention scores followed by a linear transformation for scoring.</p><p>The results indicate that the model performs well at predicting higher-level parent nodes (e.g., subcategories and departments) but struggles with lower-level predictions, such as subdepartments and classes. This is likely due to the increased number of classes and the associated complexity at these levels. Future work will explore strategies to improve predictions at these finer-grained levels.</p><p><strong>Conclusion</strong></p><p>This study evaluated the application of Graph Neural Networks (GNNs) to address critical challenges in hierarchical merchandise taxonomies, with a focus on three tasks: node classification, link prediction, and parent node prediction. By comparing traditional machine learning approaches, such as K-Nearest Neighbors (KNN), with GNN-based methodologies, we demonstrated the superiority of graph-based models in leveraging the relational and hierarchical structure of the data. For node classification, both Graph Attention Networks (GAT) and GraphSAGE achieved high accuracy. However, the results suggested a strong correlation between parent nodes and item classes, which inflated the metrics and points to areas for refinement in future iterations.</p><p>For link prediction, heterogeneous GNNs (HeteroGNNs) demonstrated clear advantages by explicitly modeling node and relationship types. We also note that HeteroGNN models maps more intuitively to our relevant tasks. The inclusion of semantic embeddings and hierarchical relationships significantly improved F1-scores, precision, and recall compared to GAT and GraphSAGE. This highlights the value of heterogeneous modeling in understanding and predicting complex relationships within real-world hierarchical data. These results validate the capability of GNNs to outperform traditional and simpler homogeneous models by capturing the unique graph structures present in the taxonomy.</p><p>We used a modified HeteroGNN model (we called it MH GNN — Merchandise Hierarchy GNN)with different optimization tasks to perform parent prediction tasks. While the model performed just satisfactorily in predicting immediate parent (merchandise class).We attribute the relative performance dip in predicting immediate parents to the imbalance in the merchandise class — product relationship as well large number of “merchandise class” nodes relative to the product nodes in our dataset. Future work will explore techniques like hierarchical loss functions, graph augmentation, and advanced pooling methods to address these challenges.</p><p>The MH GNN model performed much better in predicting parents nodes 2 levels or higher up such as subdepartments, departments and sub categories. From a business perspective, we note that accuracy levels we received on higher level nodes are satisfactory. This study reinforces the efficacy of GNNs for hierarchical data and provides a foundation for further exploration of automated taxonomy management in retail and wholesale domains.</p><p><strong>References</strong></p><p>Deng, J., Krause, J., Berg, A. C., &amp; Fei-Fei, L. (2014). Hierarchical loss functions for classification with hierarchical taxonomies. PLoS ONE, 9(1), e55547. <a href="https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0226222">https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0226222</a></p><p>Villar, J. R., Menéndez, H. D., Morán-Fernández, L., &amp; Herranz, J. F. (2023). Weighted hierarchical cross-entropy loss for encoding taxonomy in classification. arXiv preprint arXiv:2312.02266. <a href="https://arxiv.org/abs/2312.02266">https://arxiv.org/abs/2312.02266</a></p><p>Ying, R., You, J., Morris, C., Ren, X., Hamilton, W. L., &amp; Leskovec, J. (2018). Hierarchical graph representation learning with differentiable pooling. arXiv preprint arXiv:1806.08804. <a href="https://arxiv.org/abs/1806.08804">https://arxiv.org/abs/1806.08804</a></p><p>Sobolevsky, S. (2021). Hierarchical Graph Neural Networks for hierarchical data tasks. arXiv preprint arXiv:2105.03388. <a href="https://arxiv.org/abs/2105.03388">https://arxiv.org/abs/2105.03388</a></p><p>You, J., Ying, R., &amp; Leskovec, J. (2021). Design space for graph neural networks. <em>arXiv</em>. <a href="https://arxiv.org/abs/2011.08843">https://arxiv.org/abs/2011.08843</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52237bd00395" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>