Susan Harkins (406) [Avatar] Offline
#1
Please post errors in the published version of Deep Learning with R here. If necessary, we'll publish a comprehensive list for everyone's convenience. Thank you!

Susan Harkins
Errata Editor
Manning Publications
256385 (47) [Avatar] Offline
#2
The code that demonstrates k-fold validation has an error in the call to cut(). The code should read as follows:

folds <- cut(1:length(indices), breaks = k, labels = FALSE) 


This code is in listing 3.24 as well as listing 4.2
256385 (47) [Avatar] Offline
#3
The code for the naive_relu() and naive_add() functions needs to use the full range of row and column indexes for iteration. The correct code is:

naive_relu <- function(x) {
  for (i in 1:nrow(x))
    for (j in 1:ncol(x))
      x[i, j] <- max(x[i, j], 0)
  x  
}

naive_add <- function(x, y) {
  for (i in 1:nrow(x))
    for (j in 1:ncol(x))
      x[i, j] = x[i, j] + y[i, j]
  x  
}


This code appears in section 2.3.1 Element-wise operations.

256385 (47) [Avatar] Offline
#4
The PDF/eBook version of the book has an incorrect Figure 5.16: Training and validation metrics for fine-tuning. This figure was modified during editing and only the black and white version used in the print book was updated.

The correct color version is attached to this message.


18575 (1) [Avatar] Offline
#5
This may be considered a typo but the code on page 332 reading

"watch -n 5 NVIDIA-smi -a --display=utilization" should be

"watch -n 5 nvidia-smi -a --display=utilization"
553286 (2) [Avatar] Offline
#6
Read the book straight through this past week. Chapter 7 page 240 is the last page of Chapter 7, and the next page is 289 midway through Chapter 8 at 8.5.5. Then Chapter 9 begins at page 293 a few pages later, so I'm missing most of Chapter 8. But that's not all. Chapter 8 appears again after the index. Again it is partway through starting again all over at 8.5.5 followed by Chapter 9 followed by appendix and index again.

Update 2018-03-26: Manning customer support replaced my print book copy, and it arrived today in perfect condition.
Susan Harkins (406) [Avatar] Offline
#7
Oh my! Do you have a print copy?

Susan Harkins
Errata Editor
277944 (2) [Avatar] Offline
#8
PDF version, Page 10, second paragraph, the word Backpropagation has different size of letters just in the middle making it looks like Backpagation

attached capture
553286 (2) [Avatar] Offline
#9
Yes I have a print copy. Fortunately I don’t need GANs and VAEs in chapter 8 yet in my work.
553036 (5) [Avatar] Offline
#10
PDF version, page 197: This yields an MAE of 0.29.
Actually running the code consistently gives me an error of 0.277, perhaps because the data have changed?
EDIT: Around 0.2775 after the other correction below
553036 (5) [Avatar] Offline
#11
In section 6.3 there is an error in the definition of the generator. the +1 needs to be added to line 19 below, otherwise the samples returned always lack the second last observations because the length of the sequence is equal to length.out +1. I don't think It changes the section conclusions.


generator <- function(data, lookback, delay, min_index, max_index,
                      shuffle = FALSE, batch_size = 128, step = 6) {
  if (is.null(max_index)) max_index <- nrow(data) - delay - 1
  i <- min_index + lookback
  function() {
    if (shuffle) {
      rows <- sample(c((min_index+lookback):max_index), size = batch_size)
    } else {
      if (i + batch_size >= max_index)
        i <<- min_index + lookback
      rows <- c(i:min(i+batch_size, max_index))
      i <<- i + length(rows)
    }
    samples <- array(0, dim = c(length(rows),
                                lookback / step,
                                dim(data)[[-1]]))
    targets <- array(0, dim = c(length(rows)))
    for (j in 1:length(rows)) {
      indices <- seq(rows[[j]] - lookback+1, rows[[j]],
                     length.out = dim(samples)[[2]])
      samples[j,,] <- data[indices,]
      targets[[j]] <- data[rows[[j]] + delay,2] #myy
    }
    list(samples, targets)
  }
}
547573 (1) [Avatar] Offline
#12
In the hashFucntion demo of 6.1-one-hot-encoding-of-words-or-characters.Rmd

index <- abs(spooky.32(words[[i]])) %% dimensionality

should be,
index <- abs(spooky.32(words[[j]])) %% dimensionality
256385 (47) [Avatar] Offline
#13
An alternate fix to the generator issue mentioned above is here. This addresses another issue with the selection of rows so is I believe preferable:

generator <- function(data, lookback, delay, min_index, max_index,
                      shuffle = FALSE, batch_size = 128, step = 6) {
  if (is.null(max_index))
    max_index <- nrow(data) - delay - 1
  i <- min_index + lookback
  function() {
    if (shuffle) {
      rows <- sample(c((min_index+lookback):max_index), size = batch_size)
    } else {
      if (i + batch_size >= max_index)
        i <<- min_index + lookback
      rows <- c(i:min(i+batch_size-1, max_index))
      i <<- i + length(rows)
    }
    
    samples <- array(0, dim = c(length(rows), 
                                lookback / step,
                                dim(data)[[-1]]))
    targets <- array(0, dim = c(length(rows)))
                     
    for (j in 1:length(rows)) {
      indices <- seq(rows[[j]] - lookback, rows[[j]]-1, 
                     length.out = dim(samples)[[2]])
      samples[j,,] <- data[indices,]
      targets[[j]] <- data[rows[[j]] + delay,2]
    }            
    
    list(samples, targets)
  }
}


The change is basically to subtract 1 in the expression "i + batch_size - 1" (on line 12) and to also subtract 1 in the expression "rows[[j]]-1" on line 22.
563151 (2) [Avatar] Offline
#14
Figure 4.2 in the print book (p. 90) regarding 3-fold cross-validation: There should just be one validation fold in each row. So while the shading is correct, the labels for the first partition in folds 2 and 3 are incorrect (it reads "Validation" instead of "Training"
563151 (2) [Avatar] Offline
#15
563151 wrote:Figure 4.2 in the print book (p. 90) regarding 3-fold cross-validation: There should just be one validation fold in each row. So while the shading is correct, the labels for the first partition in folds 2 and 3 are incorrect (it reads "Validation" instead of "Training").

Figure 3.9 is the same, I see.
stomioka (6) [Avatar] Offline
#16
E
256385 (47) [Avatar] Offline
#17
In chapter 7 the tensorboard example should be modified to remove the embeddings_freq parameter:

callbacks = list(
  callback_tensorboard(
    log_dir = "my_log_dir",
    histogram_freq = 1
) )
579438 (2) [Avatar] Offline
#18
I encountered an error running Listing 6.13

get_layer(model, index = 1) %>% 
  set_weights(list(embedding_matrix)) %>% 
  freeze_weights()


The error is this:
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  ValueError: You called `set_weights(weights)` on layer "flatten_1" with a  weight list of length 1, but the layer was expecting 0 weights. Provided weights: [array([[ 0.      ,  0.      ,  0.      , ...,  0....

Detailed traceback: 
  File "C:\ANACON~1\lib\site-packages\keras\engine\base_layer.py", line 1062, in set_weights
    str(weights)[:50] + '...')
256385 (47) [Avatar] Offline
#19
Thanks for reporting the error with the pretrained word embeddings. The get_index() should be 1-based but it was originally implemented as 0-based. If you update to the latest development version of keras for R as follows then the code should work as expected:

devtools::install_github("rstudio/keras")
580768 (4) [Avatar] Offline
#20
Errors in Listing 7.1

Hi,

The embeddings in that listing should look like this (changes in lines 3 and 8.):

text_input <- layer_input(shape = list(NULL), dtype = "int32", name = "text")
encoded_text <- text_input %>%
    layer_embedding(input_dim = text_vocabulary_size+1, output_dim = 64) %>%
    layer_lstm(units = 32)

question_input <- layer_input(shape = list(NULL), dtype = "int32", name = "question")
encoded_question <- question_input %>%
    layer_embedding(input_dim = text_vocabulary_size+1, output_dim = 32) %>%
    layer_lstm(units = 16)


BRs,

Mariusz
256385 (47) [Avatar] Offline
#21
Thanks for the report re: the embeddings code. We will add that to the errata page ASAP!
256385 (47) [Avatar] Offline
#22
In listing 7.3, instead of:

embedded_posts <- posts_input %>%
    layer_embedding(input_dim = 256, output_dim = vocabulary_size)


The code should read:

embedded_posts <- posts_input %>%
    layer_embedding(input_dim = vocabulary_size+1, output_dim = 256)
256385 (47) [Avatar] Offline
#23
On page 262, in listing 8.10, the calculation of the loss should be updated as follows:

# This code is no longer required since we don't use layer_dict below
# layer_dict <- model$layers
# names(layer_dict) <- lapply(layer_dict, function(layer) layer$name)

loss <- k_variable(0)
for (layer_name in names(layer_contributions)) {
  coeff <- layer_contributions[[layer_name]]
  activation <- get_layer(model, layer_name)$output
  scaling <- k_prod(k_cast(k_shape(activation), "float32")) 
  loss <- loss + (coeff * k_sum(k_square(activation)) / scaling)
}
Susan Harkins (406) [Avatar] Offline
#24
A comprehensive errata list for Deep Learning with R is available at https://manning-content.s3.amazonaws.com/download/1/6d1e9c3-9483-455c-8a47-54bb4bbd3205/Allaire_DeepLearningwithR_err4.html. Thank you for participating in this process. Your work helps us and other readers.

Regards,
Susan Harkins
Errata Editor