Neural networks typically need inputs and targets as tensors, not raw data. Vectorization converts data such as sound, images, or text into that form; some datasets already arrive vectorized. section 6.2.1
Encoding text and labels
Integer sequences representing text can be converted into multi-hot tensors. Categorical labels can remain integers or be represented as one-hot vectors, with a 1 at the label’s index. section 6.2.1 section 4.2.2
Listing 4.13 Encoding the input data
x_train = multi_hot_encode(train_data, num_classes=10000) #1 x_test = multi_hot_encode(test_data, num_classes=10000) #2
See the input-encoding example for converting integer-sequence text into multi-hot training and test arrays. section 4.2.2
Listing 4.14 Encoding the labels
def one_hot_encode(labels, num_classes=46): results = np.zeros((len(labels), num_classes)) for i, label in enumerate(labels): results[i, label] = 1.0 return results y_train = one_hot_encode(train_labels) #1 y_test = one_hot_encode(test_labels) #2
See a one-hot encoding implementation that places a 1 at each label’s index. section 4.2.2

















