knowledge_graph_attention_network icon indicating copy to clipboard operation
knowledge_graph_attention_network copied to clipboard

Reuse entity, item and user embeddings

Open lfomendes opened this issue 5 years ago • 6 comments

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

lfomendes avatar Jun 19 '20 18:06 lfomendes

And is it possible to save these vectors? The only output for this code is the recommendation metrics?

lfomendes avatar Jun 22 '20 15:06 lfomendes

Yes, you can save these embedding vectors via the codes like: https://github.com/xiangwang1223/knowledge_graph_attention_network/blob/530327a45f96a828459b5cf77d98321deb8e1d95/Model/Main.py#L170-L177

Hope it can be helpful.

xiangwang1223 avatar Jun 22 '20 15:06 xiangwang1223

I will try that Thank you =D

Does the relation and entity make sense alone? Or do I have to combine them in some way? In TransR a projection matrix is used, correct?

lfomendes avatar Jun 22 '20 19:06 lfomendes

I think that storing the relation matrices and entity embeddings separately is reasonable, such that you can combine them later in flexible ways.

xiangwang1223 avatar Jun 23 '20 01:06 xiangwang1223

Thank you for your response =D I got it running and saved the embeddings like you showed me.

But now I'm trying to run with "real" data but I got some errors I'm using my own KG data

I'm running with the following command

!python Main.py --model_type kgat --alg_type bi --dataset bh15 --regs

[1e-5,1e-5] --layer_size [64,32,16] --embed_size 64 --lr 0.001 --epoch 100 --verbose 50 --save_flag 1 --pretrain 1 --batch_size 256 --node_dropout [0.1] --mess_dropout [0.1,0.1,0.1] --use_att True --use_kge True

And this is the data

[n_users, n_items]=[252346, 462485]

[n_train, n_test]=[722370, 80211] [n_entities, n_relations, n_triples]=[483176, 5, 1593039] [batch_size, batch_size_kg]=[256, 564]

And the error:

without pretraining.

Traceback (most recent call last): File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call return fn(*args) File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn target_list, run_metadata) File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[735522,32] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc [[{{node gradients/SparseTensorDenseMatMul_251/SparseTensorDenseMatMul_grad/SparseTensorDenseMatMul}}]] Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

I will try to understand what is happening but if you have any tips I would appreciate it

Thanks

ps: I'm using tensorflow 2 but i dont think this is the problem

On Mon, Jun 22, 2020 at 10:21 PM Xiang Wang [email protected] wrote:

I think that storing the relation matrices and entity embeddings separately is reasonable, such that you can combine them later in flexible ways.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xiangwang1223/knowledge_graph_attention_network/issues/29#issuecomment-647850461, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3D5F232X3GPFUSD6GNOCLRX77SXANCNFSM4OC63TRA .

lfomendes avatar Jun 23 '20 12:06 lfomendes

Thank you for your response =D I got it running and saved the embeddings like you showed me. But now I'm trying to run with "real" data but I got some errors I'm using my own KG data I'm running with the following command !python Main.py --model_type kgat --alg_type bi --dataset bh15 --regs [1e-5,1e-5] --layer_size [64,32,16] --embed_size 64 --lr 0.001 --epoch 100 --verbose 50 --save_flag 1 --pretrain 1 --batch_size 256 --node_dropout [0.1] --mess_dropout [0.1,0.1,0.1] --use_att True --use_kge True And this is the data [n_users, n_items]=[252346, 462485] [n_train, n_test]=[722370, 80211] [n_entities, n_relations, n_triples]=[483176, 5, 1593039] [batch_size, batch_size_kg]=[256, 564] And the error: without pretraining. Traceback (most recent call last): File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call return fn(args) File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn target_list, run_metadata) File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[735522,32] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc [[{{node gradients/SparseTensorDenseMatMul_251/SparseTensorDenseMatMul_grad/SparseTensorDenseMatMul}}]] Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info. I will try to understand what is happening but if you have any tips I would appreciate it Thanks ps: I'm using tensorflow 2 but i dont think this is the problem On Mon, Jun 22, 2020 at 10:21 PM Xiang Wang @.**> wrote: I think that storing the relation matrices and entity embeddings separately is reasonable, such that you can combine them later in flexible ways. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#29 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3D5F232X3GPFUSD6GNOCLRX77SXANCNFSM4OC63TRA .

@lfomendes Hi! I am also facing the same error as this 'ResourceExhaustedError'. Is it means the GPU is short of memory? May I get some help on how did you fix this error?

Thanks a lot!

FrankChengGD avatar Dec 20 '21 19:12 FrankChengGD