Giter Club home page Giter Club logo

kgcn-pytorch-updated's Introduction

KGCN-pytorch-updated

This is an updated PyTorch implementation of the KGCN model, building upon two previous works: TensorFlow KGCN and PyTorch KGCN. The former is the offical one while the latter is a PyTorch version implemented by @zzaebok. This repo modifies directly on his PyTorch KGCN.

1.1. KGCN at a Glance

KGCN is Knowledge Graph Convolutional Networks for recommender systems, which uses the technique of graph convolutional networks (GCN) to proces knowledge graphs for the purpose of recommendation.

KGCN Framework

Figure 1: KGCN Framework

Reference:

Knowledge Graph Convolutional Networks for Recommender Systems Hongwei Wang, Miao Zhao, Xing Xie, Wenjie Li, Minyi Guo. In Proceedings of The 2019 Web Conference (WWW 2019)

1.2. Running the Code

For showing result under one specific hyper parameter setting, use KGCN.ipynb or KGCN.py.

For batch experiments, use batch_experiments.ipynb.

p.s. KGCN.ipynb and KGCN.py have the same functionality, but the latter is modularized for easy debugging and reuse.

1.3. Dataset

1.3.1. movie

Raw rating file for movie is too large to be contained in this repo.

Downlad the rating data first

$ wget http://files.grouplens.org/datasets/movielens/ml-20m.zip
$ unzip ml-20m.zip
$ mv ml-20m/ratings.csv data/movie/

1.3.2. music

Nothing to do

1.3.3. product

This dataset is built upon the Rec-Tmall dataset. Check ./data/product/preprocessing.ipynb for more information.

1.3.4. Other Dataset

If you want to use your own dataset, you need to prepare 3 files.

  • Rating Data
    • Each row should contain (user-item-rating)
    • In this repo, it is pandas dataframe structure. (look at data_loader.py)
  • Knowledge Graph
    • Each triple(head-relation-tail) consists of knowledge graph
    • In this repo, it is dictionary type. (look at data_loader.py)
  • Item Index to Entity Index Mapping

1.4. Structure

Core files:

  • data_loader.py
    • data loader class for movie / music dataset
    • you don't need it if you make custom dataset
  • aggregator.py
    • aggregator class which implements 3 aggregation functions
    • and 2 mixers
  • model.py
    • KGCN model network

Dependency Graph

Figure 2: Dependency Graph

1.5. Comparison with PyTorch KGCN

1.5.1. Add a new handcrafted dataset product

1.5.2. Add a new mixer transe

transe mixer has a better performace on divergence speed, time complexity, divergence loss value and AUC value, final-epoch loss value and AUC value in most cases.

See _mix_neighbor_vectors_TransE() in aggregator.py

1.5.3. Add batch_experiments.ipynb for convenient experiment

Automatically conduct multiple experiments.

  1. Config many parameter sets once
  2. Run
  3. Check results in a well-formatted print-out

1.5.4. Fix RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (CPU)

Before

https://github.com/zzaebok/KGCN-pytorch/blob/3b0bb56da4b6759d204de06f1d4547e9b4abe3ce/model.py#L79-L80

After

            neighbor_entities = torch.LongTensor(self.adj_ent[entities[h].cpu()]).view((self.batch_size, -1)).to(self.device)
            neighbor_relations = torch.LongTensor(self.adj_rel[entities[h].cpu()]).view((self.batch_size, -1)).to(self.device)

1.5.5. Fix IndexError: index out of range in self

Before

https://github.com/zzaebok/KGCN-pytorch/blob/3b0bb56da4b6759d204de06f1d4547e9b4abe3ce/model.py#L34-L35

After

        self.adj_ent = torch.zeros(self.num_ent, self.n_neighbor, dtype=torch.long)
        self.adj_rel = torch.zeros(self.num_ent, self.n_neighbor, dtype=torch.long)

kgcn-pytorch-updated's People

Contributors

ki-seki avatar zzaebok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.