zzaebok / kgcn-pytorch Goto Github PK
View Code? Open in Web Editor NEWKGCN pytorch model implementation
KGCN pytorch model implementation
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
Line 78 in 1567fa4
adj_rel
Hello, what is the reason for using LabelEncoder? Hope to get your answer
May I ask why the test results of last.fm data set are about 10% higher than those in the paper
Line 28 in 1567fa4
In the case of the music dataset AUC, the original was close to 80%, but this version gets to 85%,
When training the Movielens data set, the training process becomes very slow, even several hours slower than the original TensorFlow version of the code, is there any optimization method? Thank you for your answer
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
Lines 79 to 80 in 3b0bb56
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
Can you give some enviroment requirements about this repository? Thanks~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.