RUCAIBox / RecBole

A unified, comprehensive and efficient recommendation library
https://recbole.io/
MIT License
3.42k stars 612 forks source link

Some questions about the attention matrix A_in in KGAT ? #1011

Closed zrg1993 closed 3 years ago

zrg1993 commented 3 years ago

https://github.com/RUCAIBox/RecBole/blob/b7b29954fbc963a406ddbe2f917b4ba56bd7a22b/recbole/model/knowledge_aware_recommender/kgat.py#L156

I read the paper and code in RecBole. Now I have several questions to confirm. Hope you can hlep me make them clear.

  1. Is that right to think the attention score matrix A_inis only calculated when the model initialize and is static for each aggregation layer ? The reason why I have this question is for the GAT model, for each layer we have a different learnable weight matrix to calculate the attention scores. However in the KGAT paper, it seems there is only one A_inmatrix and no learnable weights for calculating A_in.
  2. When will the model update the A_in matrix ? I read the implementation in RecBole, the model will update the A_in when one epoch finished. Is my understanding right ?
Sherry-XLL commented 3 years ago

@zrg1993 We implement the model following the original author in knowledge_graph_attention_network, and the A_in matrix is updated every epoch, as is the same in KGATTrainer.

*********************************************************
Alternative Training for KGAT:
... phase 2: to train the KGE method & update the attentive Laplacian matrix.
"""
if args.model_type in ['kgat']:

    n_A_batch = len(data_generator.all_h_list) // args.batch_size_kg + 1

    if args.use_kge is True:
        # using KGE method (knowledge graph embedding).
        for idx in range(n_A_batch):
            btime = time()

            A_batch_data = data_generator.generate_train_A_batch()
            feed_dict = data_generator.generate_train_A_feed_dict(model, A_batch_data)

            _, batch_loss, batch_kge_loss, batch_reg_loss = model.train_A(sess, feed_dict=feed_dict)

            loss += batch_loss
            kge_loss += batch_kge_loss
            reg_loss += batch_reg_loss

    if args.use_att is True:
        # updating attentive laplacian matrix.
        model.update_attentive_A(sess)

https://github.com/RUCAIBox/RecBole/blob/fad20428ae60a4df4206bb9d7e2c747f93e2c642/recbole/trainer/trainer.py#L537

And I found a problem in my previous reply in #1001 , A_in is attentive laplacian matrix. For model details, you can refer to the author's source code in this repo. If you still have questions about the attention mechanism of the model, it is recommended that you ask questions here.

zrg1993 commented 3 years ago

@Sherry-XLL Thank you very much. I will check the implemention from KGAT authors.