๐ Text Features
Text Features in KDP
Vocabulary-based text vectorization, learned from your own data.
๐ Overview
KDP builds a vocabulary from the text column during the statistics pass, then encodes each row with Keras TextVectorization against that vocabulary. Everything is learned from your corpus — there are no downloaded embeddings and no external model weights.
๐ Basic Usage
from kdp import PreprocessingModel, FeatureType
preprocessor = PreprocessingModel(
path_data="reviews.csv",
features_specs={
"review_text": FeatureType.TEXT,
},
)
preprocessor.build_preprocessor()
By default a text column becomes a 35-token integer sequence, padded with zeros.
โ๏ธ Configuration Parameters
TextFeature forwards its keyword arguments to Keras TextVectorization,
apart from stop_words, which KDP applies itself beforehand.
| Parameter | Type | Default | Description |
|---|---|---|---|
stop_words |
list[str] | [] |
Words stripped before vectorization, by KDP's own text preprocessing layer. |
output_sequence_length |
int | 35 |
Token count per row, and therefore the output width. Applies to output_mode="int" only. |
output_mode |
str | "int" |
"int", "multi_hot" or "count". See the table below. |
max_tokens |
int | — | Caps the vocabulary. Must be at least as large as the vocabulary found in your data, or Keras raises. |
ngrams |
int | tuple | None |
Generate n-grams in addition to single tokens. |
split, standardize |
str | callable | Keras defaults | Passed straight through to TextVectorization. |
Pretrained embeddings and attention are not implemented
Earlier documentation advertised use_pretrained, pretrained_name
(GloVe, word2vec, BERT), tokenizer, use_attention, attention_heads,
attention_dropout, max_sequence_length, embedding_dim and
sequence_length. None of these exist. TextFeature accepts any
keyword without complaint, so they appear to work while changing nothing
— verified by comparing model output with and without each one.
KDP learns its vocabulary from your data; it does not download or load
pretrained language models. To use one, wrap it yourself with
custom preprocessing.
๐ค Output Modes
| Mode | Output width | What each value means |
|---|---|---|
"int" (default) |
output_sequence_length |
Token index at that position; order is preserved. |
"multi_hot" |
vocabulary size | 1 if the token appears anywhere in the row, else 0. Order is discarded. |
"count" |
vocabulary size | How many times the token appears in the row. |
from kdp import PreprocessingModel
from kdp.features import FeatureType, TextFeature
# Bag-of-words instead of a padded sequence
preprocessor = PreprocessingModel(
path_data="reviews.csv",
features_specs={
"review_text": TextFeature(
name="review_text",
feature_type=FeatureType.TEXT,
output_mode="multi_hot",
),
},
)
preprocessor.build_preprocessor()
tf_idf needs weights KDP does not compute
output_mode="tf_idf" requires an IDF weight array alongside the
vocabulary. KDP's statistics pass records the vocabulary only, so this mode
raises a clear Keras error rather than working. Use "count" and apply
your own weighting downstream if you need it.
๐งน Stop Words
TextFeature(
name="review_text",
feature_type=FeatureType.TEXT,
stop_words=["the", "a", "an", "and", "or"],
output_sequence_length=64,
)
Stop words are removed before vectorization, so they never enter the vocabulary and never occupy a token slot.
๐ Combining With Other Features
N-grams for short text
TextFeature(
name="product_title",
feature_type=FeatureType.TEXT,
ngrams=2, # unigrams and bigrams
output_sequence_length=24,
)
Feature selection over text
from kdp import FeatureType, PreprocessingModel
preprocessor = PreprocessingModel(
path_data="reviews.csv",
features_specs={
"review_text": FeatureType.TEXT,
"rating": FeatureType.FLOAT_NORMALIZED,
},
feature_selection_placement="text", # or "all_features"
)
๐ Practical Notes
Sequence length drives width
In "int" mode the output is exactly output_sequence_length columns wide. Long default sequences on short text are mostly padding.
Text needs a statistics pass
The vocabulary comes from your data, so path_data is required and the column is read end to end.
multi_hot for keyword signals
When only presence matters — tags, short titles — "multi_hot" is smaller and easier to learn from than a padded sequence.
max_tokens must fit the data
Keras raises if the cap is below the vocabulary actually found. Set it generously or leave it unset.