liveBook · Manning

Embedding

As explained in Knowledge Graphs and LLMs in Action

A feature vector is a numerical vector whose components represent measurable characteristics of an input for machine learning.

A feature vector is a compact numerical representation of data. In graph machine learning, its components encode measurable properties of nodes, relationships, or whole graphs so conventional machine-learning algorithms can process them. section 9.3 section 10.0

Vectors turn graph structure into an interface for the broader machine-learning ecosystem. Manual feature engineering can produce interpretable values such as node degree, clustering coefficient, centrality, or path-based scores, while representation learning automatically discovers less interpretable features. section 9.3 section 10.0

A practical vector-construction pipeline can proceed as follows:

  • Identify properties relevant to the prediction task, such as node characteristics, graph relationships, or selected metapaths. section 9.3
  • Encode those properties as numerical components; binary components can indicate whether a movie belongs to each genre. section 12.2.2
  • Align vector rows with graph entities and map original identifiers to consecutive indices before constructing graph connectivity. section 12.2.2
  • Use the resulting vectors with downstream tasks such as node classification, link prediction, or graph classification. section 9.3 section 12.2.2

Movie genre vectors

A movie vector uses one column per genre. A value of 1 marks membership and 0 marks absence, so an Adventure movie and a Drama movie receive different components; multiple genre components may be active for one movie. The resulting tensor contains 9,742 rows and 20 genre features. section 12.2.2

Path-based drug–disease feature

A vector for a compound–disease pair can include a metapath feature computed with a degree-weighted path score. For metformin and type 2 diabetes, the CbGaD feature has a DWPC value of 0.0007; selecting useful metapaths reduces computational cost and noise. section 10.2.2

Listing 12.14 Transforming genre information into a vector of features
movies_df = pd.read_csv(movies_path, index_col='movieId')  #1
genres = movies_df['genres'].str.get_dummies('|')  #2
movie_feat = torch.from_numpy(genres.values).to(torch.float) #3
assert movie_feat.size() == (9742, 20)  #4

Inspect the pandas and PyTorch pipeline that converts pipe-separated movie genres into a floating-point feature tensor. section 12.2.2

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Explains vector design, binary encoding, identifier alignment, and path-based scoring, while deferring automated representation learning to later treatment.
Examples
Uses binary movie-genre tensors, user–movie rating graphs, and metapath-based drug–disease scores as concrete vector representations.
What it assumes
Assumes basic graph entities and relationships while demonstrating numerical encoding and identifier mapping during data preparation.
What you can do after
Build it from scratch by encoding domain properties into numerical components and preparing them for graph-based prediction pipelines.
How it connects
Connects feature vectors with feature engineering, representation learning, graph neural networks, node classification, link prediction, and graph classification.

Also explained in

Compare how 47 books explain embedding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Knowledge Graphs and LLMs in Action. The section links point to the parts of the book it draws on.