Repository: pykeen/pykeen
Issue: AttributeError: 'TransE' object has no attribute 'entity_embeddings'
Root cause: Interface Contract Mismatch

Hi,

When i ran Toy Example
results.plot(er_kwargs=dict(plot_relations=True))
 in results_plots.ipynb with pykeen 1.9.0, I got 
AttributeError: 'TransE' object has no attribute 'entity_embeddings'

Do u know what is going on here?


Hello, thanks for opening the issue. I noticed the same thing too few days ago. I was about to open an issue for it, but preferred to investigate the problem deeply and be sure to describe the problem correctly and propose a solution or modifications.

For best practices, we always need to follow instruction in the repo on how to post an issue, let's first do that : 

## 1. How to reproduce the error (Code) : 

```python
import pykeen
from pykeen.pipeline import pipeline
from matplotlib import pyplot as plt

results = pipeline(
    dataset= 'Nations',
    model = 'TransE',
    model_kwargs=dict(
        embedding_dim=2
    ),
    training_kwargs=dict(use_tqdm_batch=False),
    evaluation_kwargs=dict(use_tqdm=False),
    random_seed=1,
    device='cpu',
)

# Error happen the line below 
results.plot(er_kwargs=dict(plot_relations=True))
plt.savefig('results/imageName.png', dpi=300)
```

## 2. Error : 
```python-traceback
AttributeError: 'ComplEx' object has no attribute 'entity_embeddings'
```

## 3.Environment
| Key             | Value                    |
|-----------------|--------------------------|
| OS              | nt                       |
| Platform        | Windows                  |
| Release         | 10                       |
| Time            | Fri Aug 12 17:29:46 2022 |
| Python          | 3.9.12                   |
| PyKEEN          | 1.9.1-dev                |
| PyKEEN Hash     | UNHASHED                 |
| PyKEEN Branch   |                          |
| PyTorch         | 1.12.1                   |
| CUDA Available? | false                    |
| CUDA Version    | N/A                      |
| cuDNN Version   | N/A                      |

## 4. Describe the bug

While I was reading and playing around with the tutorial "A Toy Example with Translational Distance Models" with the recent version of pykeen (see Environment information below), I noticed that the `plot_er` function wasn't updated to meet the new updates of the model to the new style `ERModel`. Thus, calling `.plot()` on a pipline results in error : `AttributeError: 'TransE' object has no attribute 'entity_embeddings'`.

So far, we notice two things by looking at the error message : 

1. First, we can understand that the attribute `entity_embeddings` is no more supported due to new-style models `ERModels`.
2. Second, I noticed that in the PR (Random updates #376), they did the following fixes for the plotting function `plot_pr()` : 
    - Fix **issue with entity embeddings** in plots 	
    - Make **plot_er** function more configurable

## 5. Additional information ( for us it will be "Suggested solutions", Optional): 
A. After looking into the new style, the KGE (Knowledge Graph Embedding) model store the learned (one or many) Entity.ies/Relation.s representation.s  as a sequences in the `entity_representations` and `relation_representations` attributes. Usually, the “primary” representation (1st element of the sequence) is the "Embedding representation" of type `pykeen.nn.representation.Embedding`. ( But still not sure if it is valid for all the models, didn't check yet if all the model calculate such representation). In this way we could solve the problem as following : 

```python
def entity_embedding_getter_TransE(model) -> pykeen.nn.Embedding:
    entity_representations_embedding = model.entity_representations[0]
    assert isinstance(entity_representations_embedding, pykeen.nn.Embedding)
    return entity_representations_embedding

def relation_embedding_getter_TransE(model) -> pykeen.nn.Embedding:
    relation_representations_embedding = model.relation_representations[0]
    assert isinstance(relation_representations_embedding, pykeen.nn.Embedding)
    return relation_representations_embedding

results.plot(
    er_kwargs=dict(
        plot_relations=True,
        plot_entities=False,        
        entity_embedding_getter = entity_embedding_getter_TransE,
        relation_embedding_getter = relation_embedding_getter_TransE, 
    )
)
```
From the point (2) we could understand that the error is coming from the `plot_er()` function called in `plot() `function. So, As we updated `TransE` model to `ERModel`, we need to change it the polt_er entity/relation_embedding to entity/relation_representations if valid for all the models ( or just make an exception fro the one that calculate embeddings)

B. Another suggestion, is to keep everything as it is and updates the documentation and explain the bult-in `plot() `and `plot_er()` and on how to use the `entity/relation_embedding_getter_TransE(model)->pykeen.nn.Embedding` function to get the correct and needed representation to plot.


Thx for ur reply, I do learned a lot from it ;)

With #1072 merged, this should be fixed on `master` branch. Thanks again @MayloIFERR for the excellent answer / investigation :slightly_smiling_face: