liveBook · Manning

Adapt

As explained in Deep Learning with R, Third Edition

adapt() is a Keras preprocessing-layer method that learns vocabulary or other data-dependent state from supplied data.

adapt() makes a Keras preprocessing layer learn data-dependent state from input data. For TextVectorization, it iterates over a dataset to learn its vocabulary before encoding text. section 14.4.1

Learning an IMDb vocabulary

Create a TextVectorization layer with a 20,000-word limit, remove labels from the training dataset, and call adapt(text_vectorization, train_ds_no_labels). Apply the adapted layer to training, validation, and test datasets to produce multi-hot vectors. section 14.4.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains dataset iteration and vocabulary learning, then stops short of preprocessing-layer internals.
Examples
Demonstrates adapting a 20,000-token TextVectorization layer to IMDb reviews before generating multi-hot datasets.
What it assumes
Assumes familiarity with Keras datasets and preprocessing layers while demonstrating the adaptation call explicitly.
What you can do after
Apply it via Keras to learn vocabulary state and transform text datasets into model-ready vectors.
How it connects
Connects adapt() with TextVectorization, tokenization, vocabulary, multi-hot encoding, and bag-of-words models.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.