8.2.8 Inferring Embeddings for a Supervised GraphWise Model
You can use a trained model to infer embeddings for unseen nodes and store in the database as described in the following code:
Inferring Embeddings Using
JShell
opg4j> var vertexVectors = model.inferEmbeddings(fullGraph, fullGraph.getVertices()).flattenAll();
opg4j> vertexVectors.write().
db().
name("vertex vectors").
tablename("vertexVectors"). // indicate the name of the table in which the data should be stored
overwrite(true). // indicate that if there is a table with the same name, it will be overwritten (truncated)
store();
Inferring Embeddings Using
Java
PgxFrame vertexVectors = model.inferEmbeddings(fullGraph,fullGraph.getVertices()).flattenAll();
vertexVectors.write()
.db()
.name("vertex vectors")
.tablename("vertexVectors") // indicate the name of the table in which the data should be stored
.overwrite(true) // indicate that if there is a table with the same name, it will be overwritten (truncated)
.store();
Inferring Embeddings Using
Python
vertex_vectors = model.infer_embeddings(full_graph, full_graph.get_vertices()).flatten_all()
vertexVectors.write().db(name="vertex vectors", "tablename", overwrite=True)
The schema for the
vertexVectors
will be as follows without flattening (flattenAll
splits the vector column into separate double-valued columns):
+---------------------------------------------------------------+
| vertexId | embedding |
+---------------------------------------------------------------+
Note:
All the preceding examples assume that you are inferring the embeddings for a model in the current logged in database. If you must infer embeddings for the model in a different database then refer to the examples in Inferring Embeddings for a Model in Another Database.