liveBook · Manning

Preprocessing

As explained in Knowledge Graphs and LLMs in Action

Data preparation is the process of selecting, cleaning, transforming, and organizing data for computational use.

Preprocessing converts raw, heterogeneous data into compact numerical structures that computational models can consume. It preserves domain meaning while organizing entities, relationships, features, and labels for learning. section 12.1.2 section 2.3

A practical preprocessing pipeline commonly includes:

  • Map original entity identifiers to consecutive numeric IDs and remove records whose endpoints cannot be mapped. section 12.1.2
  • Represent relationships as edge-index tensors and align feature rows with the new entity IDs. section 12.1.2
  • Encode categorical information numerically, using multi-hot genre vectors or label-encoded classes. section 12.1.2 section 12.2.2
  • For knowledge graphs, define schemas, process documents, disambiguate entities, map ontologies, and generate relationships. section 7.6

User–movie ratings graph

Convert movie genres into a 9,742-by-20 feature tensor, map user and movie IDs to consecutive values, and build an edge_index tensor whose columns represent ratings. section 12.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 transformation that turns pipe-separated genres into numerical features. section 12.2.2

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Explains multi-stage identifier, tensor, feature, label, schema, and ontology transformations with implementation examples.
Examples
Uses financial transactions, illicit-node labels, movie genres, user ratings, medical documents, and ontology mappings.
What it assumes
Assumes familiarity with tabular data and tensors while teaching identifier mapping, categorical encoding, and graph assembly concretely.
What you can do after
Builds numerical graph inputs and structured knowledge-graph data through mappings, encoding, ingestion, and relationship generation.
How it connects
Connects data preparation with graph neural networks, knowledge graphs, ontologies, schemas, feature encoding, and entity disambiguation.

Also explained in

Compare how 22 books explain preprocessing →

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.