Repository: pykeen/pykeen
Issue: RGCN - ValueError: The number of bases should not exceed the number of relations. (explanation)
Root cause: Documentation Deficiency

I am trying to use the RGCN algorithm and run into the following error.
```ptb
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-231451742934> in <module>
      5 training, testing = tf.split()
      6 
----> 7 pipeline_result = pipeline(
      8     training_triples_factory=training,
      9     testing_triples_factory=testing,

~\anaconda3\envs\pykeen\lib\site-packages\pykeen\pipeline.py in pipeline(dataset, dataset_kwargs, training_triples_factory, testing_triples_factory, validation_triples_factory, evaluation_entity_whitelist, evaluation_relation_whitelist, model, model_kwargs, loss, loss_kwargs, regularizer, regularizer_kwargs, optimizer, optimizer_kwargs, clear_optimizer, training_loop, negative_sampler, negative_sampler_kwargs, training_kwargs, stopper, stopper_kwargs, evaluator, evaluator_kwargs, evaluation_kwargs, result_tracker, result_tracker_kwargs, metadata, device, random_seed, use_testing_data)
    711 
    712     model = get_model_cls(model)
--> 713     model_instance: Model = model(
    714         triples_factory=training_triples_factory,
    715         **model_kwargs,

~\anaconda3\envs\pykeen\lib\site-packages\pykeen\models\unimodal\rgcn.py in __init__(self, triples_factory, embedding_dim, automatic_memory_optimization, loss, predict_with_sigmoid, preferred_device, random_seed, num_bases_or_blocks, num_layers, use_bias, use_batch_norm, activation_cls, activation_kwargs, base_model, sparse_messages_slcwa, edge_dropout, self_loop_dropout, edge_weighting, decomposition, buffer_messages)
    231                 num_bases_or_blocks = triples_factory.num_relations // 2 + 1
    232             if num_bases_or_blocks > triples_factory.num_relations:
--> 233                 raise ValueError('The number of bases should not exceed the number of relations.')
    234         elif self.decomposition == 'block':
    235             if num_bases_or_blocks is None:

ValueError: The number of bases should not exceed the number of relations.
```

I assumed that bases are the same as nodes. When changing the number of relation types to be more than the different number of nodes It seemed to work.

However I want to apply the RGCN approach to a graph with 30 000 different nodes and only 6 different relation types between the nodes. From what I understand about the mathematics behind the RGCN model this should be possible, why is it recommended then in the error to have so many different relation types?

I am also sorry if this is not the platform to ask questions like this, but it seems to be the only platform where I consistently get answers about this package, presumably due to how new it still is. 

Hi @ChristopherMarais ,

`num_bases_or_blocks` is a parameter related to the decomposition of the relation-specific weight matrices (cf. [0], 2.2). There are two different variants:

* bases-decomposition: Each relation-specific weight matrix `W_r` is a weighted combination of set of basis matrices `B_i`
```math
W_r = \alpha_{ri} B_i
```
* block-decomposition: Each relation-specific weight matrix `W_r` is a block-diagonal matrix.

The paper's reasoning for using these decompositions is to have regularization and reduce the number of parameters:

> A central issue with applying (2) to highly multi-relational data is the rapid growth in number of parameters with thenumber of relations in the graph. In practice this can easily lead to overfitting on rare relations and to models of very large size.

Thus, when chosing the number of bases larger than the number of relations, we get <em>more</em> weights than without decomposition. Moreover, since the basis matrices are learned as well, we do not gain any additional expressive power.

Regarding
> I assumed that bases are the same as nodes.

The number of nodes is automatically set using the TriplesFactory's num_entities attribute. You do not have to provide this on your own.

I hope this answers your question.

[0] https://arxiv.org/abs/1703.06103

@mberr 
Oh I see, I must have misunderstood the meaning of the variables. I am still learning how many of these techniques work. I mostly have a biological background and have only spent the past 3 months delving into graph theory and all of the embeddings related to it. 

I really appreciate how much you guys are helping me with your quick responses. 


@ChristopherMarais I'm also a biologist/chemist! Would be curious to see what you're up to if you get the chance to post something on github.