Code Monkey home page Code Monkey logo

kgcn-pytorch's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kgcn-pytorch's Issues

Request to use your code

Hi, zzaebok.

I'm Shichao Song, from Henan University of Economics and Law, China. Your PyTorch implementation of KGCN is brilliant. I am wondering if you could please allow me to modify and cite your code for my thesis. If yes, that will be a great honor to me. Thank you for your patience to read this.

Best regards
Shichao Song

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

When I ran the KGCN.ipynb, I met the errors below.

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[7], line 11
      9 user_ids, item_ids, labels = user_ids.to(device), item_ids.to(device), labels.to(device)
     10 optimizer.zero_grad()
---> 11 outputs = net(user_ids, item_ids)
     12 loss = criterion(outputs, labels)
     13 loss.backward()

File ~/miniconda3/envs/pt/lib/python3.10/site-packages/torch/nn/modules/module.py:1194, in Module._call_impl(self, *input, **kwargs)
   1190 # If we don't have any hooks, we want to skip the rest of the logic in
   1191 # this function, and just call forward.
   1192 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1193         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1194     return forward_call(*input, **kwargs)
   1195 # Do not call functions when jit is used
   1196 full_backward_hooks, non_full_backward_hooks = [], []

File ~/coding/KGCN-pytorch/model.py:62, in KGCN.forward(self, u, v)
     59 # [batch_size, dim]
     60 user_embeddings = self.usr(u).squeeze(dim = 1)
---> 62 entities, relations = self._get_neighbors(v)
     64 item_embeddings = self._aggregate(user_embeddings, entities, relations)
     66 scores = (user_embeddings * item_embeddings).sum(dim = 1)

File ~/coding/KGCN-pytorch/model.py:79, in KGCN._get_neighbors(self, v)
     76 relations = []
     78 for h in range(self.n_iter):
---> 79     neighbor_entities = torch.LongTensor(self.adj_ent[entities[h]]).view((self.batch_size, -1)).to(self.device)
     80     neighbor_relations = torch.LongTensor(self.adj_rel[entities[h]]).view((self.batch_size, -1)).to(self.device)
     81     entities.append(neighbor_entities)

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

As a deep-learning beginer, I cannot tell the details behind those errors, but I sovled it by adding two .cpu() to models.py

BEFORE

KGCN-pytorch/model.py

Lines 79 to 80 in 3b0bb56

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

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)

My Environment:

python==3.10.9
pytorch==1.13.1
pytorch-cuda==11.7

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.