Changing labels into integers

When developing deep learning networks for classification problems, we always use responses or labels in the form of integers. Author names for the train and test text data are stored in trainy and testy, respectively. Both trainy and testy are lists of 2,500 items that contain the names of 50 authors. To change the labels into integers, we can use the following code:

# Train and test labels to integers
trainy <- as.factor(unlist(trainy))
trainy <- as.integer(trainy) -1
testy <- as.factor(unlist(testy))
testy <- as.integer(testy) -1

# Saving original labels
trainy_org <- trainy
testy_org <- testy

As we can see, to convert labels containing author names into integers, we need to unlist them and then use integers from 0 to 49 to represent the 50 authors. We can also use trainy_org and testy_org to save these original integer labels for later use.

Next, we will carry out padding and truncation to make the data on a sequence of integers have an equal length for each article.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset