Repository: pykeen/pykeen
Issue: How to retrieve tensors of nodes and relations from PyKEEN TriplesFactory?
Root cause: Documentation Deficiency

### What is your question

Hi,
I am following the instructions found in the documentation here:
https://pykeen.readthedocs.io/en/stable/tutorial/first_steps.html#mapping-entity-and-relation-identifiers-to-their-names

trying to get tensors of entity identifiers by running:
`entity_ids = torch.as_tensor(triples_factory.entity_to_ids([id1, id2]))`

however I am getting the following error: 
**AttributeError: 'TriplesFactory' object has no attribute 'entity_to_ids'**

Is this an existing method or is the correct one the "**entities_to_ids(entities)**" method?
The latest however I think returns the ids rather than the tensor of each provided entity.

How can I retrieve and print the embedding vector of each entity/relation?
(by the way, I would assume that this would be available from a trained embedding model object, rather than the TriplesFactory dictionary, right?)

Thank you!

### Environment

| Key             | Value                    |
|-----------------|--------------------------|
| OS              | posix                    |
| Platform        | Linux                    |
| Release         | 4.9.0-15-amd64           |
| Time            | Thu Mar 24 18:24:13 2022 |
| Python          | 3.7.5                    |
| PyKEEN          | 1.7.0                    |
| PyKEEN Hash     | UNHASHED                 |
| PyKEEN Branch   |                          |
| PyTorch         | 1.10.2+cu102             |
| CUDA Available? | false                    |
| CUDA Version    | 10.2                     |
| cuDNN Version   | 7605                     |

### Issue Template Checks

- [X] This is not a bug report (use a different issue template if it is)
- [X] This is not a feature request (use a different issue template if it is)
- [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

Nice catch finding this typo, in fact it was just reported and fixed yesterday in https://github.com/pykeen/pykeen/pull/846. You can find the updated docs in https://pykeen.readthedocs.io/en/latest.

With respect to actually getting the embedding values, scroll about 1 paragraph down from where you found the typo to https://pykeen.readthedocs.io/en/stable/tutorial/first_steps.html#using-learned-embeddings to see detailed instructions on how to get the embeddings out of a model (note that the triples factory does _not_ store embeddings itself).

I hope this answers your question :) I'm going to close this issue but feel free to comment further if there's residual confusion or open a new one for any related issues

Thank you very much for the quick and efficient reply!

I have one more thing that is not clear to me in the documentation that you have shared:
`entity_embedding_tensor: torch.FloatTensor = entity_embeddings(indices=None)
...
If you’d like to only look up certain embeddings, you can use the indices parameter and pass a torch.LongTensor with their corresponding indices.`
But how can you get the embedding of an entity with a specific id or label (e.g. id="1009" in the TriplesFactory dictionary)?
I am not sure how to fill in the indices parameter in this case.
Could you please add an example for that in the documentation?
thanks again

if you have the IDs, you can directly look them up from the embedding by passing them as a tensor to the `indices` argument. If you have the labels, you can use the example (that was the original subject of this issue) to convert to IDs then do the same. We can add another example of doing this

Hi again,

I am still experiencing a weird error, while trying to get the id (my_id) of a single node.

In specific I am running the following code:
```python
my_id=tf.entity_to_id[my_label]
my_tensor: torch.IntTensor = torch.as_tensor(my_id)
entity_representation_modules: List['pykeen.nn.Representation']  = model.entity_representations
entity_embeddings: pykeen.nn.Embedding  = entity_representation_modules[0]
entity_embedding_tensor: torch.FloatTensor  = entity_embeddings(indices=my_tensor.indices())
```

From what I understand this will retrieve the embedding of the entity with label=my_label, id=my_id.
The error that I get from this execution (even if I run this in a GPU server) is:

```python-traceback
entity_embedding_tensor: torch.FloatTensor  = entity_embeddings(indices=my_tensor.indices())
NotImplementedError: Could not run 'aten::indices' with arguments from the 'CPU' backend. This could be because the operator doesn't exist for this backend, or was omitt
ed during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for
 possible resolutions. 'aten::indices' is only available for these backends: [SparseCPU, SparseCUDA, BackendSelect, Python, Named, Conjugate, Negative, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, AutogradHPU, AutogradNestedTensor, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode].

SparseCPU: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/build/aten/src/ATen/RegisterSparseCPU.cpp:958 [kernel]
SparseCUDA: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/build/aten/src/ATen/RegisterSparseCUDA.cpp:1060 [kernel]
BackendSelect: fallthrough registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/core/BackendSelectFallbackKernel.cpp:3 [backend fallback]
Python: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/core/PythonFallbackKernel.cpp:47 [backend fallback]
Named: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/core/NamedRegistrations.cpp:7 [backend fallback]
Conjugate: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/ConjugateFallback.cpp:18 [backend fallback]
Negative: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/native/NegateFallback.cpp:18 [backend fallback]
ADInplaceOrView: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/ADInplaceOrViewType_1.cpp:2399 [kernel]
AutogradOther: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradCPU: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradCUDA: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradXLA: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradLazy: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradXPU: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradMLC: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradHPU: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradNestedTensor: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradPrivateUse1: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradPrivateUse2: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
AutogradPrivateUse3: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/VariableType_2.cpp:10483 [autograd kernel]
Tracer: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/torch/csrc/autograd/generated/TraceType_2.cpp:11423 [kernel]
UNKNOWN_TENSOR_TYPE_ID: fallthrough registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/autocast_mode.cpp:466 [backend fallback]
Autocast: fallthrough registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/autocast_mode.cpp:305 [backend fallback]
Batched: registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/BatchingRegistrations.cpp:1016 [backend fallback]
VmapMode: fallthrough registered at /opt/conda/conda-bld/pytorch_1640811793227/work/aten/src/ATen/VmapModeRegistrations.cpp:33 [backend fallback]
```

Thank you!

Hi @fotais ,

you do not need to call
```python
my_tensor.indices()
```
but rather directly use `my_tensor`. the `indices` method is a built-in method from PyTorch *only available for sparse tensors*, cf. https://pytorch.org/docs/stable/generated/torch.Tensor.indices.html#torch.Tensor.indices