GithubHelp home page GithubHelp logo

xiangwang1223 / knowledge_graph_attention_network Goto Github PK

View Code? Open in Web Editor NEW
1.0K 13.0 308.0 99.57 MB

KGAT: Knowledge Graph Attention Network for Recommendation, KDD2019

License: MIT License

Python 100.00% Roff 0.01%
recommender-system knowledge-graph graph-attention-networks graph-neural-networks kdd2019 knowledge-based-recommendation knowledge-aware-recommendation explainable-recommendation embedding-propagation high-order-connectivity

knowledge_graph_attention_network'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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

knowledge_graph_attention_network's Issues

A little question about the number of interactions

Thank you very much for sharing the code and data!
When I count the number of interactions in the dataset, it is slightly different from the paper. amazon-book: 846434 ; last-fm: 3034763 ; yelp2018 : 1183610. I got it by counting train.txt and test.txt.

The "gcn" alg_type maybe wrong in your code.

1.In your code ,I find when I choose the "gcn",your code didn't add the former embedding of e_u.
2.When I run the FM and NFM ,the program is always wrong ,I debug it for a long time. Finally, I find the models FM and NFM are wrong. I wonder how you run those baselines, can you release the right code? Or... maybe the code is right and I am wrong somehow. Can you re-run those baselines?Thanks!

If you have time ,Can you answer me these questions?

Thank you! Big fan of u!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

about Attentive Embedding Propagation

Hi, in your work,Attentive Embedding Propagation is only for recommendation training, why not used in the training process of KGE ? Have you conduct any experiment for comparison?

HSRNet related issue

Hi,
I was going through your paper on text to SQL generation on cross-domain databases. Can you help me out?

Reuse entity, item and user embeddings

I'm experimenting with KGAT using my own user-item and KG data.
But I would like to reuse all the embeddings generated during the recommendations in other models and to visualize/clusterize the items.

How can I do that?
Looking at the KGAT.py I see that you keep

all_weights['user_embed']
all_weights['entity_embed']
all_weights['relation_embed']
all_weights['trans_W']

Does it make sense to get the embeddings from the 'entity embed' or since you are using TransR they only make sense when I trasnform with a specific relation?

Thanks

Running KGAT on Customized Dataset

When I trying to run KGAT on a customized dataset, I get this error
GAT-lyy) yunyangli@UBUNTU1604-R940xa:~/knowledge_graph_attention_network/Model$ python Main.py --model_type kgat --alg_type bi --dataset sl --regs [1e-5,1e-5] --layer_size [64,32,16] --embed_size 64 --lr 0.0001 --epoch 1000 --verbose 50 --save_flag 1 --pretrain -1 --batch_size 1024 --node_dropout [0.1] --mess_dropout [0.1,0.1,0.1] --use_att True --use_kge True [n_users, n_items]=[3234, 96393] [n_train, n_test]=[26379, 26187] [n_entities, n_relations, n_triples]=[96397, 27, 4462966] [batch_size, batch_size_kg]=[1024, 178518] convert ratings into adj mat done. convert 50 relational triples into adj mat done. @1.6183s /home/yunyangli/knowledge_graph_attention_network/Model/utility/loader_kgat.py:87: RuntimeWarning: divide by zero encountered in power d_inv = np.power(rowsum, -1).flatten() generate si-normalized adjacency matrix. reordering indices... reorganize all kg data done. sort meta-data done. sort all data done. using xavier initialization #params: 6611344 without pretraining. Traceback (most recent call last): File "Main.py", line 269, in <module> A_batch_data = data_generator.generate_train_A_batch() File "/home/yunyangli/knowledge_graph_attention_network/Model/utility/loader_kgat.py", line 254, in generate_train_A_batch heads, relations, pos_tails, neg_tails = self._generate_train_A_batch() File "/home/yunyangli/knowledge_graph_attention_network/Model/utility/loader_kgat.py", line 190, in _generate_train_A_batch heads = [rd.choice(exist_heads) for _ in range(self.batch_size_kg)] File "/home/yunyangli/knowledge_graph_attention_network/Model/utility/loader_kgat.py", line 190, in <listcomp> heads = [rd.choice(exist_heads) for _ in range(self.batch_size_kg)] File "/home/yunyangli/.conda/envs/KGAT-lyy/lib/python3.6/random.py", line 261, in choice return seq[i] TypeError: 'dict_keys' object does not support indexing

When running the provided dataset, it's fine. However, when turning into my dataset, I get this weird error. I am running this on python 3.6.3, and everything else is the same as the specified environment.

Movielens 20M

hello, I would like to ask you if there is a reason why you haven't released training code (and results on paper) for the Movielens dataset and if you plan to do it in near future. Thanks.

Question about Embeddings Initialization

The source code you have provided used bpr-mf to initialize the user & item embeddings. Were all the results(including all baselines) in your paper also used bpr-mf to provide initialization? Or not?
If you used bpr-mf to initialize the embeddings, why you said used default Xavier initializer to initialize the model parameters in your paper. Thank you for your answering.

I have a question about memory growth

Hello,I have a question about memory growth. when I run on server, the memory will growth until crashed. I'm trying to restrict the muti-processing, whatever I do, the memory will be crashed. The GPU is tesla p100, with 16g video ram ,and 64g memory.

some questions about the kg extraction process

I followed the process of kb4rec and extracted a subgraph of movie domain for movielens-1m, which considers only the most important 10 relations. However, for a dataset that only contains 3000+ items. The entity number in my extracted first-order subgraph reached 100000+. I found that in most papers, for dataset movielens their number of entity in subgraph is realtively small, maybe about 20000.
Could you please share how you treat the subgraph so that the entity number in the subgraph is small.

Code running issues

Thank you for sharing the code. I use the default parameters to run your data and code without any problems, but after I processed my data like yours, it will automatically exit after 2 epoches of running without error arising. If possible, could you please analyze what might be the reason? Thank you.
Running Exit Photo

Can you offer the code of the mf-pretrain part

Thank you for offer the code of KGAT paper, and it has helped me a lot.I hope to do some futher research based on your work, if you could opensource the code of the pretrain step, it will be great helpful for me.
Thanks again!

movielens dataset

你好,请问能公开用同样方法处理得到的movielens数据集么?以及您在抽取相关三元组的时候用的freebase的大小,是300多G的那个么?

Is the dataset partition same with the one for NGCF repo?

I want to play with the code to reproduce the results and make some comparisons. I found NGCF repo lacks Yelp2018, which is available here. I wonder whether the train/test split is same with that you report on NGCF paper. Thanks!

I don't quite understand how you did CaseStudy.

I don't quite understand how you did CaseStudy. When you calculate the attention score, it is calculated for each triple above the entire CKG. There is no information about the same (user, item) pair as constraint information. So, when KGAT training is complete, your attention score is based on the entire training set. The only way I can think of at the moment is that when you need CaseStudy, you need to retrain KGAT, and CF batch has only one (user, item) pair. Maybe you can provide code about CaseStudy. Thank you!

Could you provide the actual semantics corresponding to each item&entity in KG?

Hi Dr. Wang,

Thanks for you wonderful work. To get more intuitive understanding of your proposed method, I would like to conduct some case study on your provided datasets. However, the actual semantics of the items and entities are not available. Could you provide the actual semantics corresponding to each item&entity in KG?

Best

Questions about dataset LastFM

According the link you provided in the paper, I found the LastFM dataset. But the statistic of datasets are different between the original dataset and the dataset you provided here. For example, the number of users and items are 23565 and 48122, respectively. However, the statistics are 1892 users and 17632 artists in the original dataset. Why? And I also want to ask you that is the item id here is same as the artist id in the original dataset. Is it possible for me to understand that you just sorted the history of individual users into one line? Thank you for your answsering.

How does the directed graph propagation work?

The ego-network of an entity h in your work is the head entity, then how does the following example work?

page 5:
u2 ->i2 ->e1->i1->u1, u2 in u1's 3-layer neighbors

what does the minus relation mean -r1 mean?

ERROR: loss@phase2 is nan

Dear Author,

I got ERROR: loss@phase2 is nan, not `ERROR: loss@phase1 is nan for my custom dataset.
Can you guess which situation is possible to occur this case?

More specifically, the kge_loss is nan and reg_loss is zero.

Thanks!

How did you generate the train and test txt files?

Hi, I noticed that the user id of the training set and the test set is exactly the same, except for the item id. I think this is a more complicated preprocessing process, but I did not find the corresponding code in the code file.

Thank you :)

about the freebase entities' original id

I want to recover the kg from the file kg_final.txt. I don't know how to obtain the original id of entities in the freebase. As far as I know, the entities in the freebase were encoded by mid.

Thanks very much!

about training data

I don't understand the training data, can you give me explanation about it? Thanks very much!

Some questions about batch_size and some parameters

Hello, thank you very much for your contribution, I tried to run your example, but due to the gpu problem, the maximum can only use 512 batch_size, then the problem I found is that the result is not better than NFM, the loss drops very slowly. The example is as follows:
python Main.py --model_type kgat --alg_type bi --dataset last-fm --regs [1e-5,1e-5] --layer_size [64,32,16] --embed_size 64 --lr 0.001 --epoch 400 --verbose 1 --save_flag 1 --pretrain -1 --batch_size 512 --node_dropout [0.1] --mess_dropout [0.1,0.1,0.1] --use_att True --use_kge True

Are the parameters wrong, and is it affected by batch_size? In addition, the source code loss_type, n_memory and using_all_hops did not find the source, how can I use them?

Running KGAT in Google Collab

Hello, is it possible to run this repository in google collab?
I tried to upload this repo to google drive, mount it via google collab and run the amazon example :
(python Main.py --model_type kgat --alg_type bi --dataset amazon-book --regs [1e-5,1e-5] --layer_size [64,32,16] --embed_size 64 --lr 0.0001 --epoch 1000 --verbose 50 --save_flag 1 --pretrain -1 --batch_size 1024 --node_dropout [0.1] --mess_dropout [0.1,0.1,0.1] --use_att True --use_kge True)

However, I get an error message saying it cannot find train.txt in the directory. I put the screenshot of the command I input in collab and error message

I hope you can suggest other way to solve this/ running it on collab, thanks!
image

Can you provide your experimental configuration?

Hello dear author,
Can you provide your experimental configuration? Unfortunately, I couldn't run your code with RTX 2080ti * 2 or RTX 3090, and the code finally returned a resource exhaustion error when updating the attention score.

关于邻接矩阵的构造和合并

  1. lap_list = [_si_norm_lap(adj) for adj in self.adj_list] lap_list是对各个关系下的邻接矩阵行规一化后的集合
  2. config['A_in'] = sum(data_generator.lap_list) 将各个邻接矩阵进行按位相加
    这样A_in这个用于GCN propagation的拉普拉斯矩阵每行没有经过整体的归一化处理,和不为1, 下面是last_fm数据集上A_in每行的和,请问这样合理么?
    [[1.]
    [1.]
    [1.]
    ...
    [1.]
    [5.]
    [3.]]

About epoch's time

请问你们跑一个epoch大概需要多长时间,用的什么机器呢?我用2080ti大概是1340s一个epoch

How to run the code with GPU?

How can I run the code using GPU?

It utilizes GPU on my laptop but does not on a cloud.

How can I force it to use GPU?

Thanks,

about the id mapping

I have a KG, which contains users and items.
I found that your user id mapping and item id mapping both start from 0.
In my situation, the head and target in a triple may have the same id for users and items respectively.

So how should i map the user, item, entity ids? Should i map them together?

Some running questions

Hello, thank you very much for your contribution, I tried to run your example, but I met some problems. The example is as follows:

python Main.py --dataset last-fm --pretrain -1
The error is as follows:
#params: 12049088
without pretraining.
What's the problem? How can I solve it?

The use of func (model.update_attentive_A) maybe wrong in your code.

Thank you for offering the code of KGAT paper, and it helps me a lot.
In running code, I found that the function (model.update_attentive_A) use self.A_in to update the matrix A. But as far as I know, TensorFlow cannot change the value of the variable in the static graph in this way. I found experimentally that whatever self.A_in is assigned, it doesn't change the result of the model. If so, KGAT does not use dynamic weights to implement GAT. Look forward to your reply.

How to generate good ./pretrain data for new datasets?

Hi Dear Author,

I now want to implement KGAT with new KGs, but seems like the direct embedding cannot get good performance. As you mentioned in README.md, load the pretrained embeddings would be better for evaluation. Then for a new incoming KG, how to generate such pertained embeddings?

Can you provide the training log of the dataset "yelp2018"

I have tried reproducing the model on the dataset "yelp2018". The best result of recall@20 is 0.06988 and ndcg@20 is 0.0852, which is inconsistent with the result of 0.0712 and 0.0867 in your paper. Can you provide the training log of the dataset "yelp2018"?

What does Freebase ID mean

I do not know the application and representative meaning of Freebase_id in data set, could you please explain it

ERROR: loss@phase1 is nan.

您好,非常感谢您共享的如此优秀的代码,从github拉取代码后,我使用python Main.py --model_type kgat --alg_type bi --dataset last-fm --regs [1e-5,1e-5] --layer_size [64,32,16] --embed_size 64 --lr 0.0001 --epoch 1000 --verbose 50 --save_flag 1 --pretrain 0 --batch_size 1024 --node_dropout [0.1] --mess_dropout [0.1,0.1,0.1] --use_att True --use_kge True 训练模型,这里pretrain0,结果会报错ERROR: loss@phase1 is nan.。日志如下:

(KGAT) root@c34ffcf30357:/data/knowledge_graph_attention_network/Model# python Main.py --model_type kgat --alg_type bi --dataset last-fm --regs [1e-5,1e-5] --layer_size [64,32,16] --embed_size 64 --lr 0.0001 --epoch 1000 --verbose 50 --save_flag 1 --pretrain 0 --batch_size 1024 --node_dropout [0.1] --mess_dropout [0.1,0.1,0.1] --use_att True --use_kge True
[n_users, n_items]=[23566, 48123]
[n_train, n_test]=[1289003, 423635]
[n_entities, n_relations, n_triples]=[106389, 9, 464567]
[batch_size, batch_size_kg]=[1024, 369]
        convert ratings into adj mat done.
        convert 20 relational triples into adj mat done. @0.3366s
/data/knowledge_graph_attention_network/Model/utility/loader_kgat.py:87: RuntimeWarning: divide by zero encountered in power
  d_inv = np.power(rowsum, -1).flatten()
        generate si-normalized adjacency matrix.
        reordering indices...
        reorganize all kg data done.
        sort meta-data done.
        sort all data done.
using xavier initialization
#params: 8427280
without pretraining.
ERROR: loss@phase1 is nan.

另外当pretrain-1时,也会报这个错:

(KGAT) root@c34ffcf30357:/data/knowledge_graph_attention_network/Model# python Main.py --model_type kgat --alg_type bi --dataset last-fm --regs [1e-5,1e-5] --layer_size [64,32,16] --embed_size 64 --lr 0.0001 --epoch 1000 --verbose 50 --save_flag 1 --pretrain -1 --batch_size 1024 --node_dropout [0.1] --mess_dropout [0.1,0.1,0.1] --use_att True --use_kge True
[n_users, n_items]=[23566, 48123]
[n_train, n_test]=[1289003, 423635]
[n_entities, n_relations, n_triples]=[106389, 9, 464567]
[batch_size, batch_size_kg]=[1024, 369]
        convert ratings into adj mat done.
        convert 20 relational triples into adj mat done. @0.3448s
/data/knowledge_graph_attention_network/Model/utility/loader_kgat.py:87: RuntimeWarning: divide by zero encountered in power
  d_inv = np.power(rowsum, -1).flatten()
        generate si-normalized adjacency matrix.
        reordering indices...
        reorganize all kg data done.
        sort meta-data done.
        sort all data done.
load the pretrained bprmf model parameters.
using pretrained initialization
#params: 8427280
without pretraining.
ERROR: loss@phase1 is nan.

请问该如何解决呢?谢谢,期待您答复

How can I get this article?

It seems that the url of the paper is invalid. I can't find your paper on the Internet. How can I get this article?

不同的batch_size_kg计算方式 + valid数据集问题

1.在load_data.py中,batch_size_kg计算公式如下:self.batch_size_kg = self.n_triples // (self.n_train // self.batch_size)
使用在loader_kgat.py中的def _generate_train_A_batch(self):函数中用于生成kg训练的batch
2.在Main.py中,使用的是args.batch_size_kg, 我看示例parser.py中默认的参数是2048, 运行了示例代码,也是2048
请问batch_size_kg大小为何在两个地方定义不同?

  1. 论文中写到会From the training set, we randomly select 10% of interactions as validation set to tune hyper-parameters,代码中似乎没有这部分的处理代码

谢谢!

I have a question about kg_final.txt

Hello, I have some questions about “kg_final.txt”(e.g. In last-fm dataset). In this file, there is a triple composed of head entity, relationship and tail entity. According to what you described in the article, it should be the relationship triple between item and other no item entities. But according to ID, some triples are between two entities, such as (96619, 1,76285) and others are of item itself, such as (5511, 7,5511). I don't quite understand. I hope you can explain it. Thank you.

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.