Repository: pykeen/pykeen
Issue: Seems like the top prediction function is buggy?
Root cause: Algorithmic Error

### Describe the bug

Seems like the top K predictions are not always correct. I've tried to run

```python3
top_df = get_all_prediction_df(result.model,k=15, triples_factory=result.training)
```

![Screenshot 2021-12-15 214735](https://user-images.githubusercontent.com/19948365/146276734-1275dbae-1ac1-45a5-8751-b4341b2cdb2d.png)


and compare that with

```python3
top_df = get_all_prediction_df(result.model,k=50000, triples_factory=result.training).sort_values(by=['score'], ascending=False).head(15)
```

and get different results
![Screenshot 2021-12-15 214753](https://user-images.githubusercontent.com/19948365/146276744-425b2656-4835-4f4e-b374-26cc2997f053.png)



### How to reproduce

```python3
from pykeen.triples import TriplesFactory
from pykeen.pipeline import pipeline
from pykeen.models.predict import get_all_prediction_df

result = pipeline(
    dataset='HetioNet'
    model='RotatE',
    epochs=5,  # short epochs for testing - you should go higher
)

print(get_all_prediction_df(result.model,k=15, triples_factory=result.training))

print(get_all_prediction_df(result.model,k=50000, triples_factory=result.training).sort_values(by=['score'], ascending=False).head(15))
```

### Environment

| Key             | Value                    |
|-----------------|--------------------------|
| OS              | nt                       |
| Platform        | Windows                  |
| Release         | 10                       |
| Time            | Wed Dec 15 20:51:02 2021 |
| Python          | 3.8.8                    |
| PyKEEN          | 1.6.0                    |
| PyKEEN Hash     | UNHASHED                 |
| PyKEEN Branch   |                          |
| PyTorch         | 1.9.0                    |
| CUDA Available? | true                     |
| CUDA Version    | 11.1                     |
| cuDNN Version   | 8005                     |

### Additional information

I first noticed this on a custom dataset, first I tried to reproduce it on the NATIONS dataset, but it seems to be only relevant on bigger datasets.

For some reason with a small K value, all the head ids are 0.

Hi @tomasonjo ,

thanks for reporting the issue.

I was able to reproduce the erratic behaviour, even on a smaller dataset, `umls`. using

```python
from pykeen.pipeline import pipeline
from pykeen.models.predict import get_all_prediction_df

result = pipeline(
    dataset="umls",
    model="RotatE",
    epochs=5,
)

print(get_all_prediction_df(result.model, k=15, triples_factory=result.training))
print(get_all_prediction_df(result.model, k=50_000, triples_factory=result.training).nlargest(15, columns="score"))
```

which results in 
```
    head_id            head_label  relation_id           relation_label  tail_id                     tail_label     score  in_training
0   0        acquired_abnormality  3            assesses_effect_of       29       cell_or_molecular_dysfunction -3.259243  False      
1   0        acquired_abnormality  35           performs                 105      pathologic_function           -3.273844  False      
2   0        acquired_abnormality  3            assesses_effect_of       92       neoplastic_process            -3.295665  False      
3   0        acquired_abnormality  3            assesses_effect_of       40       disease_or_syndrome           -3.298323  False      
4   0        acquired_abnormality  40           produces                 105      pathologic_function           -3.327644  False      
5   0        acquired_abnormality  32           method_of                40       disease_or_syndrome           -3.333235  False      
6   0        acquired_abnormality  3            assesses_effect_of       50       experimental_model_of_disease -3.333941  False      
7   0        acquired_abnormality  3            assesses_effect_of       87       mental_process                -3.340794  False      
8   0        acquired_abnormality  11           connected_to             105      pathologic_function           -3.356307  False      
9   0        acquired_abnormality  10           conceptually_related_to  89       molecular_function            -3.356986  False      
10  0        acquired_abnormality  20           exhibits                 40       disease_or_syndrome           -3.367249  False      
11  0        acquired_abnormality  29           manifestation_of         40       disease_or_syndrome           -3.370177  True       
12  0        acquired_abnormality  41           property_of              92       neoplastic_process            -3.371210  False      
13  0        acquired_abnormality  3            assesses_effect_of       105      pathologic_function           -3.373059  False      
14  0        acquired_abnormality  40           produces                 40       disease_or_syndrome           -3.375148  False      
```
and
```
    head_id                        head_label  relation_id           relation_label  tail_id                     tail_label     score  in_training
0   29       cell_or_molecular_dysfunction     3            assesses_effect_of       29       cell_or_molecular_dysfunction -3.259243  False      
1   40       disease_or_syndrome               35           performs                 105      pathologic_function           -3.273844  False      
2   92       neoplastic_process                3            assesses_effect_of       92       neoplastic_process            -3.295665  False      
3   40       disease_or_syndrome               3            assesses_effect_of       40       disease_or_syndrome           -3.298323  False      
4   105      pathologic_function               40           produces                 105      pathologic_function           -3.327644  False      
5   40       disease_or_syndrome               32           method_of                40       disease_or_syndrome           -3.333235  False      
6   50       experimental_model_of_disease     3            assesses_effect_of       50       experimental_model_of_disease -3.333941  False      
7   87       mental_process                    3            assesses_effect_of       87       mental_process                -3.340794  False      
8   92       neoplastic_process                11           connected_to             105      pathologic_function           -3.356307  False      
9   86       mental_or_behavioral_dysfunction  10           conceptually_related_to  89       molecular_function            -3.356986  False      
10  105      pathologic_function               20           exhibits                 40       disease_or_syndrome           -3.367249  False      
11  105      pathologic_function               29           manifestation_of         40       disease_or_syndrome           -3.370177  False      
12  50       experimental_model_of_disease     41           property_of              92       neoplastic_process            -3.371210  False      
13  105      pathologic_function               3            assesses_effect_of       105      pathologic_function           -3.373059  False      
14  40       disease_or_syndrome               40           produces                 40       disease_or_syndrome           -3.375148  False   
```

For this smaller example, it seems that only the `head` columns are incorrect, and the `score` column matches exactly. So maybe there is an error in adding the head ids. :thinking: 

I found one error in the calculation of head-ids: https://github.com/pykeen/pykeen/pull/690/commits/152f5e4711fc9d132afb4f3c7ac06f3322758885.
The head ID was set to the within-batch offset, and since the default batch size is 1, this meant we would always see 0s.

This seems to have resolved the issue:
```
    head_id                      head_label  relation_id  ...                        tail_label     score in_training
0     37374               Pathway::PC7_3808           15  ...    Molecular Function::GO:0050136 -3.907408       False
1     12499  Cellular Component::GO:0032807           19  ...    Biological Process::GO:0060742 -3.941525       False
2      7048  Biological Process::GO:0048144           14  ...    Biological Process::GO:1904430 -3.945942       False
3     37212               Pathway::PC7_2661            4  ...                        Gene::5476 -3.953659       False
4      7700  Biological Process::GO:0051464           22  ...                 Compound::DB00344 -3.967933       False
5     29052                     Gene::65061            4  ...    Molecular Function::GO:0008309 -3.972656       False
6     33238                      Gene::9276           16  ...                        Gene::3779 -3.977113       False
7     24995                     Gene::50832           15  ...    Molecular Function::GO:0015142 -3.978388       False
8     17411                      Gene::1375           10  ...                      Gene::375567 -3.980377       False
9      5334  Biological Process::GO:0035860            9  ...             Side Effect::C3495917 -3.980722       False
10    37950               Pathway::PC7_6792           23  ...                       Gene::10092 -3.980762       False
11    33830                      Gene::9826           23  ...  Pharmacologic Class::N0000008953 -3.981608       False
12    37848               Pathway::PC7_6189            5  ...             Side Effect::C0235706 -3.981747       False
13    23791                    Gene::392399            4  ...                      Gene::153201 -3.981879       False
14    14366               Compound::DB01424           19  ...                      Gene::134121 -3.986663       False
```
vs
```
    head_id                      head_label  relation_id  ...                        tail_label     score in_training
0     37374               Pathway::PC7_3808           15  ...    Molecular Function::GO:0050136 -3.907408       False
1     12499  Cellular Component::GO:0032807           19  ...    Biological Process::GO:0060742 -3.941525       False
2      7048  Biological Process::GO:0048144           14  ...    Biological Process::GO:1904430 -3.945942       False
3     37212               Pathway::PC7_2661            4  ...                        Gene::5476 -3.953659       False
4      7700  Biological Process::GO:0051464           22  ...                 Compound::DB00344 -3.967933       False
5     29052                     Gene::65061            4  ...    Molecular Function::GO:0008309 -3.972656       False
6     33238                      Gene::9276           16  ...                        Gene::3779 -3.977113       False
7     24995                     Gene::50832           15  ...    Molecular Function::GO:0015142 -3.978388       False
8     17411                      Gene::1375           10  ...                      Gene::375567 -3.980377       False
9      5334  Biological Process::GO:0035860            9  ...             Side Effect::C3495917 -3.980722       False
10    37950               Pathway::PC7_6792           23  ...                       Gene::10092 -3.980762       False
11    33830                      Gene::9826           23  ...  Pharmacologic Class::N0000008953 -3.981608       False
12    37848               Pathway::PC7_6189            5  ...             Side Effect::C0235706 -3.981747       False
13    23791                    Gene::392399            4  ...                      Gene::153201 -3.981879       False
14    14366               Compound::DB01424           19  ...                      Gene::134121 -3.986663       False
```

Great! Thanks for the swift update!

@tomasonjo #690 is now merged. 

If you find the time, we would appreciate if you could verify that the issue is also solved on your custom dataset.

Until the next release is pushed to pypi, you need to install directly from GitHub to get access to the fix:
```console
$ pip install git+https://github.com/pykeen/pykeen.git
```