Tho Le

A Data Scientist. Looking for knowledge!

Knowledge Graph

13 Feb 2025 » ai, llms, nlp, nn

Knowledge Graph vs Graph Neural Network

AspectGraph Neural Network (GNN)Knowledge Graph (KG)
DefinitionA neural network architecture that operates on graph-structured dataA structured representation of knowledge in the form of entities and relationships
InputGraphs with nodes, edges, and features (often numeric or categorical)Triples: (subject, predicate, object), like (“Product A”, “is_variant_of”, “Product B”)
PurposeLearn representations (embeddings) for nodes, edges, or the entire graphStore and query semantic information, often used for reasoning and inference
Learning?Yes, end-to-end training using backpropagationNot inherently “learning-based”, though can be used alongside ML models
RepresentationDense vectors learned through message passing between nodesSymbolic, usually stored as RDF triples or a property graph (Neo4j, etc.)
ExamplesNode classification, link prediction, graph classificationEntity linking, semantic search, recommendation
ApplicationsSocial Nw analysis: Predict user behavior, friend recommendation. Molecule property prediction: For drug discovery (moledules as graphs) . Recommendation systems: Personalized recommendations by modeling user-item interaction graph. Fraud detection: Detect anomalies in transaction networks.Search engines: Google’s Knowledge Panel (e.g., “Barack Obama → Born In → Hawaii”). Chatbots & QA systems: Semantic understanding and retrieval. Product information management: Unified representation of items and their relationships. Personalization engines: Capture customer interests and intent
Tools & LibrariesPyTorch Geometric, DGL, TensorFlow GNN. Models: GCN, GAT, GraphSAGE, R-GCN, LightGCNGraph DBs: Neo4j, Amazon Neptune, RDFLib. Ontology tools: Protégé

In Ecommerce:

AspectGraph Neural Network (GNN)Knowledge Graph (KG)
What they doLearn powerful embeddings over graphs (users–products, product–product similarity, etc.). Predict next product to buy, bundle offers, or cross-sell suggestionsUnify information across systems (products, customers, categories, brands). Provide semantic reasoning (e.g., “Lingerie is a type of women’s underwear”). Enable personalized recommendations, faceted search, and chatbots
Example Use CasesSession-based recommendation: Use GNNs (e.g., GAT, GCN) to predict what user will click next. Fraud detection: Model user–transaction–device graph to flag suspicious behavior. User embedding learning: Capture deep user interests from interaction patterns. Link prediction: Identify potential connections like “also bought” or “co-viewed”Product enrichment: Build a KG linking SKUs → categories → attributes → usage occasions. Semantic search: “Show me affordable red dresses under $50” → link price, color, category. Customer interest graph: Track product interactions → build a user–product graph. Multi-language/catalog linking: Map equivalent products across locales
Use CaseKnowledge GraphGraph Neural Network
Entity Linking & Search✅ Yes❌ Not designed for this
Recommendation Systems✅ With rules✅ With learning & embeddings
Fraud Detection✅ Especially on transaction graphs
Personalized Experience✅ With semantic relations✅ With behavior modeling
Customer Segmentation✅ Hierarchical structure✅ Graph clustering

Combine GNNs + KGs for Advanced Applications:

  • Knowledge-Enhanced Recommendations:
    • Use KG as input for GNN (e.g., KGAT: Knowledge Graph Attention Network)
    • Products and users embedded into a semantic space for improved relevance
  • Explainable AI:
    • Use KG paths to explain why a product was recommended: “Because you liked X, which is similar to Y”

Example Use Case 1: KG in E-commerce

Business Problem An ecommerce company face:

  • Product data inconsistency (e.g., same T-shirt under multiple SKUs for different colors).
  • Customers searching for “black summer dress” get incomplete results.
  • Hard to recommend complementary items (handbags with dresses, etc.).

Solution Build a KG that can connects related entities to unify and enrich product data.

You can build a KG from the following input in the form of (subject, predicate, object):

(SKU123, "is_variant_of", SKU456)
(SKU123, "has_color", "black")
(CustomerA, "purchased", SKU123)
(SKU123, "belongs_to", "summer collection")
(SKU123, "belongs_to", "dresses")
(SKU123, "frequently_bought_with", SKU456)

And then store it in Neo4j or Amazon Neptune for querying. This can help with:

  • Semantic Search:
  • User types: “black cotton summer dress under $50”
  • The KG connects synonyms & related categories (e.g., “cocktail” → “party dress”).
  • Cross-sell & Up-sell:
  • Via paths connected with relationships: “purchased”, “frequently_bought_with”.
  • Then recommend handbags that were co-purchased.
  • Product QA & Chatbots:
  • Answers questions like “What is the care instruction for this?” by linking to attribute nodes.

Tools used:

  • Neo4j graph database to store and query KG.
  • NLP pipelines to auto-extract relationships from product descriptions.
  • Graph algorithms (like PageRank or community detection) to rank popular products in segments.

Example Use Case 2: GNN in E-commerce Business Problem The same ecommerce company wants to improve personalized recommendations beyond collaborative filtering. They want to capture:

  • Sequential clicks (session-based).
  • Product-Product similarity (from user co-interactions).
  • Social signals (influencer likes, etc.)

Solution Use a GNN to predict the next likely purchase.

Graph Structure:

  • Nodes: Customers, Products.
  • Edges:
  • viewed, added_to_card, purchased.
  • Weighted by recency & frequency.

Models:

  • GNN type: GraphSAGE or GAT (Graph Attention Network).
  • Task: Link Prediction (predict edge from a customer to new products).

Results (Potential Impact):

  • Improved CTR and conversion on recommendations by +12% over classic matrix factorization.
  • More robust to cold-start: new products get embedded via graph strcuture.

Tools used

  • PyTorch Geometric for GNNs.
  • Features: Recency & Frequency of interactions, product category embeddings.
  • Trained with historical sessions.

References

Academic Papers

Knowledge Graphs for E-commerce:

Graph Neural Networks in Recommender Systems:

Libaries & Tools

Blogs & Tutorials

Open Code Examples

Related Posts