Repository: pykeen/pykeen
Issue: ValueError: All arrays must be of the same length, While predicting a relation with CompGCN
Root cause: Validation Gap

#### I use CompGCN for link prediction but after training of the model and making the prediction using: 
```python
pred = predict_target(
    model=result.model,
    head="uk",
    tail="poland",
    triples_factory=result.training,
    ) 
```
I get this error:

```python-traceback
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[9], line 16
      7 result = pipeline(
      8     training=NATIONS_TRAIN_PATH,
      9     testing=NATIONS_TEST_PATH,
     10     dataset_kwargs={'create_inverse_triples': True},
     11     model="CompGCN"
     12     )
     15 dataset = get_dataset(dataset="nations")
---> 16 pred = predict_target(
     17     model=result.model,
     18     head="uk",
     19     tail="poland",
     20     triples_factory=result.training,
     21     )

File [~/venv/drep/lib/python3.11/site-packages/torch/utils/_contextlib.py:115](https://file+.vscode-resource.vscode-cdn.net/Users/karim/Nextcloud/Master_LSI/drug_repurposing/~/venv/drep/lib/python3.11/site-packages/torch/utils/_contextlib.py:115), in context_decorator..decorate_context(*args, **kwargs)
    112 @functools.wraps(func)
    113 def decorate_context(*args, **kwargs):
    114     with ctx_factory():
--> 115         return func(*args, **kwargs)

File [~/venv/drep/lib/python3.11/site-packages/pykeen/predict.py:1093](https://file+.vscode-resource.vscode-cdn.net/Users/karim/Nextcloud/Master_LSI/drug_repurposing/~/venv/drep/lib/python3.11/site-packages/pykeen/predict.py:1093), in predict_target(model, head, relation, tail, triples_factory, targets, mode)
   1091 if labels is not None:
   1092     data[f"{target}_label"] = labels
-> 1093 df = pandas.DataFrame(data=data).sort_values("score", ascending=False)
   1094 return TargetPredictions(df=df, factory=triples_factory, target=target, other_columns_fixed_ids=other_col_ids)

File [~/venv/drep/lib/python3.11/site-packages/pandas/core/frame.py:709](https://file+.vscode-resource.vscode-cdn.net/Users/karim/Nextcloud/Master_LSI/drug_repurposing/~/venv/drep/lib/python3.11/site-packages/pandas/core/frame.py:709), in DataFrame.__init__(self, data, index, columns, dtype, copy)
    703     mgr = self._init_mgr(
    704         data, axes={"index": index, "columns": columns}, dtype=dtype, copy=copy
    705     )
    707 elif isinstance(data, dict):
    708     # GH#38939 de facto copy defaults to False only in non-dict cases
--> 709     mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
    710 elif isinstance(data, ma.MaskedArray):
    711     from numpy.ma import mrecords

File [~/venv/drep/lib/python3.11/site-packages/pandas/core/internals/construction.py:481](https://file+.vscode-resource.vscode-cdn.net/Users/karim/Nextcloud/Master_LSI/drug_repurposing/~/venv/drep/lib/python3.11/site-packages/pandas/core/internals/construction.py:481), in dict_to_mgr(data, index, columns, dtype, typ, copy)
    477     else:
    478         # dtype check to exclude e.g. range objects, scalars
    479         arrays = [x.copy() if hasattr(x, "dtype") else x for x in arrays]
--> 481 return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)

File [~/venv/drep/lib/python3.11/site-packages/pandas/core/internals/construction.py:115](https://file+.vscode-resource.vscode-cdn.net/Users/karim/Nextcloud/Master_LSI/drug_repurposing/~/venv/drep/lib/python3.11/site-packages/pandas/core/internals/construction.py:115), in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate)
    112 if verify_integrity:
    113     # figure out the index, if necessary
    114     if index is None:
--> 115         index = _extract_index(arrays)
    116     else:
    117         index = ensure_index(index)

File [~/venv/drep/lib/python3.11/site-packages/pandas/core/internals/construction.py:655](https://file+.vscode-resource.vscode-cdn.net/Users/karim/Nextcloud/Master_LSI/drug_repurposing/~/venv/drep/lib/python3.11/site-packages/pandas/core/internals/construction.py:655), in _extract_index(data)
    653 lengths = list(set(raw_lengths))
    654 if len(lengths) > 1:
--> 655     raise ValueError("All arrays must be of the same length")
    657 if have_dicts:
    658     raise ValueError(
    659         "Mixing dicts with non-Series may lead to ambiguous ordering."
    660     )

ValueError: All arrays must be of the same length
```

### How to reproduce

```python
from pykeen.pipeline import pipeline
from pykeen.datasets import get_dataset
from pykeen.predict import predict_target
from pykeen.datasets.nations import NATIONS_TRAIN_PATH, NATIONS_TEST_PATH

result = pipeline(
    training=NATIONS_TRAIN_PATH,
    testing=NATIONS_TEST_PATH,
    dataset_kwargs={'create_inverse_triples': True},
    model="CompGCN"
    )


dataset = get_dataset(dataset="nations")
pred = predict_target(
    model=result.model,
    head="uk",
    tail="poland",
    triples_factory=result.training,
    )
```
### Environment

it occurs on this:

| Key             | Value                       |
|-----------------|-----------------------------|
| OS              | posix                       |
| Platform        | Linux                       |
| Release         | 3.10.0-1160.45.1.el7.x86_64 |
| Time            | Tue Aug  8 11:57:50 2023    |
| Python          | 3.11.4                      |
| PyKEEN          | 1.10.1                      |
| PyKEEN Hash     | UNHASHED                    |
| PyKEEN Branch   |                             |
| PyTorch         | 2.0.1+cu117                 |
| CUDA Available? | false                       |
| CUDA Version    | 11.7                        |
| cuDNN Version   | 8500                        |


and on this also:
| Key             | Value                    |
|-----------------|--------------------------|
| OS              | posix                    |
| Platform        | Darwin                   |
| Release         | 22.5.0                   |
| Time            | Tue Aug  8 12:08:39 2023 |
| Python          | 3.11.3                   |
| PyKEEN          | 1.10.1                   |
| PyKEEN Hash     | UNHASHED                 |
| PyKEEN Branch   |                          |
| PyTorch         | 2.0.1                    |
| CUDA Available? | false                    |
| CUDA Version    | N/A                      |
| cuDNN Version   | N/A                      |

### Additional information

_No response_

### Issue Template Checks

- [X] This is not a feature request (use a different issue template if it is)
- [X] This is not a question (use the [discussions](https://github.com/pykeen/pykeen/discussions/new) forum instead)
- [X] I've read the text explaining why including environment information is important and understand if I omit this information that my issue will be dismissed

My current best guess would be that this comes from using inverse relations and thus getting scores for both, the "normal" and the inverse relation. Could you verify that this error also occurs when you use a different model but still enable inverse triples?

Thanks @mberr for your reply. 

> Could you verify that this error also occurs when you use a different model but still enable inverse triples?

yes, it is produced also using TransE with inverse relation. I am not interested in inverse relation but it is required to run CompGCN. 

is it fixed now, what should I do to get the fixed code :)

The code at https://github.com/pykeen/pykeen/pull/1304 should fix the issue for your use-case.  You can already install it via
```bash
pip install -U https://github.com/pykeen/pykeen/archive/fix-relation-prediction-with-inverses.zip
```

@mberr 
running this pip command gave me this error:
`
 ERROR: HTTP error 404 while getting https://github.com/pykeen/pykeen/archive/fix-relation-prediction-with-inverses.zip
ERROR: Could not install requirement https://github.com/pykeen/pykeen/archive/fix-relation-prediction-with-inverses.zip because of HTTP error 404 Client Error: Not Found for url: https://codeload.github.com/pykeen/pykeen/zip/fix-relation-prediction-with-inverses for URL https://github.com/pykeen/pykeen/archive/fix-relation-prediction-with-inverses.zip`


I reisnstalled the new version and it is now working. Thank you 😀

Hi @Karimsaber1 , 

> running this pip command gave me this error:

this may be because this PR was already merged at that point, and thus its underlying branch deleted.

Great to hear that your issue is resolved!