Skip to content

Commit c4ff723

Browse files
committed
remove unpack_x_y_sample_weight()
1 parent 4c69f8f commit c4ff723

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

R/dataset-utils.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#' @param sample_weight
3030
#' Sample weight for each element.
3131
#'
32-
#' @export
32+
#' @noRd
33+
# @export
3334
#' @family data utils
3435
#' @family utils
3536
# @seealso
@@ -75,7 +76,10 @@ function (x, y = NULL, sample_weight = NULL)
7576
#' @param data
7677
#' A list of the form `(x)`, `(x, y)`, or `(x, y, sample_weight)`.
7778
#'
78-
#' @export
79+
#' @noRd
80+
# This is removed because it has no real purpose in R. Use this instead:
81+
# c(x, y = NULL, sample_weight = NULL) %<-% data
82+
# @export
7983
#' @family data utils
8084
#' @family utils
8185
#' @keywords internal

pkgdown/_pkgdown.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ reference:
414414
- zip_lists
415415
- get_file
416416
- split_dataset
417-
- pack_x_y_sample_weight
418-
- unpack_x_y_sample_weight
417+
# - pack_x_y_sample_weight
418+
# - unpack_x_y_sample_weight
419419

420420
- subtitle: "Serialization Utils"
421421
- contents:

tools/archive/make.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ if(!"source:tools/utils.R" %in% search()) envir::attach_source("tools/utils.R")
1212
## Implemented but Questioning ----
1313

1414

15-
# TODO: pack_x_y_sample_weight() to return an unconverted py tuple?
16-
# Marked @internal for now
17-
# or just remove pack_x_y_sample_weight/unpack_x_y_sample_weight from the namespace?
18-
# No real utility in R since zeallot supports:
19-
# c(x, y = NULL, sample_weight = NULL) %<-% data
20-
2115
# TODO: remove usage of all.equal(<pyobj>, <pyobj>) in examples/code,
2216
# export a better way.
2317
# Exported all.equal S3 methods for KerasTensor and KerasVariable

vignettes-src/custom_train_step_in_tensorflow.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ and we query results from `self$metrics` at the end to retrieve their current va
7676
CustomModel <- new_model_class(
7777
"CustomModel",
7878
train_step = function(data) {
79-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
79+
c(x, y = NULL, sample_weight = NULL) %<-% data
8080
8181
with(tf$GradientTape() %as% tape, {
8282
y_pred <- self(x, training = TRUE)
@@ -150,7 +150,7 @@ CustomModel <- new_model_class(
150150
self$loss_fn <- loss_mean_squared_error()
151151
},
152152
train_step = function(data) {
153-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
153+
c(x, y = NULL, sample_weight = NULL) %<-% data
154154
155155
with(tf$GradientTape() %as% tape, {
156156
y_pred <- self(x, training = TRUE)
@@ -212,7 +212,7 @@ it manually if you don't rely on `compile()` for losses & metrics)
212212
CustomModel <- new_model_class(
213213
"CustomModel",
214214
train_step = function(data) {
215-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
215+
c(x, y = NULL, sample_weight = NULL) %<-% data
216216
217217
with(tf$GradientTape() %as% tape, {
218218
y_pred <- self(x, training = TRUE)
@@ -268,7 +268,7 @@ CustomModel <- new_model_class(
268268
"CustomModel",
269269
test_step = function(data) {
270270
# Unpack the data
271-
c(x, y, sw) %<-% unpack_x_y_sample_weight(data)
271+
c(x, y = NULL, sw = NULL) %<-% data
272272
# Compute predictions
273273
y_pred = self(x, training = FALSE)
274274
# Updates the metrics tracking the loss

vignettes-src/parked/_customizing_what_happens_in_fit.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ it manually if you don't rely on `compile()` for losses & metrics)
216216
custom_model <- new_model_class(
217217
"custom_model",
218218
train_step = function(data) {
219-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
219+
c(x, y = NULL, sample_weight = NULL) %<-% data
220220
221221
with(tf$GradientTape() %as% tape, {
222222
y_pred <- self(x, training = TRUE)
@@ -271,7 +271,7 @@ custom_model <- new_model_class(
271271
"custom_model",
272272
test_step = function(data) {
273273
# Unpack the data
274-
c(x, y, sw) %<-% unpack_x_y_sample_weight(data)
274+
c(x, y = NULL, sw = NULL) %<-% data
275275
# Compute predictions
276276
y_pred = self(x, training = FALSE)
277277
# Updates the metrics tracking the loss

vignettes-src/parked/_intro_to_keras_for_researchers.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ CustomModel <- new_model_class(
826826
self$optimizer <- optimizer_adam(learning_rate=1e-3)
827827
},
828828
train_step = function(data) {
829-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
829+
c(x, y = NULL, sample_weight = NULL) %<-% data
830830
with(tf$GradientTape() %as% tape, {
831831
y_pred <- self(x, training=TRUE)
832832
loss <- self$loss_fn(y = y, y_pred = y_pred, sample_weight=sample_weight)

vignettes/custom_train_step_in_tensorflow.Rmd

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ and we query results from `self$metrics` at the end to retrieve their current va
7878
CustomModel <- new_model_class(
7979
"CustomModel",
8080
train_step = function(data) {
81-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
81+
# unpack data into x, y, and sample_weight
82+
c(x, y = NULL, sample_weight = NULL) %<-% data
8283

8384
with(tf$GradientTape() %as% tape, {
8485
y_pred <- self(x, training = TRUE)
@@ -163,7 +164,8 @@ CustomModel <- new_model_class(
163164
self$loss_fn <- loss_mean_squared_error()
164165
},
165166
train_step = function(data) {
166-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
167+
# unpack data into x, y, and sample_weight
168+
c(x, y = NULL, sample_weight = NULL) %<-% data
167169

168170
with(tf$GradientTape() %as% tape, {
169171
y_pred <- self(x, training = TRUE)
@@ -235,7 +237,8 @@ it manually if you don't rely on `compile()` for losses & metrics)
235237
CustomModel <- new_model_class(
236238
"CustomModel",
237239
train_step = function(data) {
238-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
240+
# unpack data into x, y, and sample_weight
241+
c(x, y = NULL, sample_weight = NULL) %<-% data
239242

240243
with(tf$GradientTape() %as% tape, {
241244
y_pred <- self(x, training = TRUE)
@@ -300,7 +303,7 @@ CustomModel <- new_model_class(
300303
"CustomModel",
301304
test_step = function(data) {
302305
# Unpack the data
303-
c(x, y, sw) %<-% unpack_x_y_sample_weight(data)
306+
c(x, y = NULL, sw = NULL) %<-% data
304307
# Compute predictions
305308
y_pred = self(x, training = FALSE)
306309
# Updates the metrics tracking the loss

vignettes/intro_to_keras_for_researchers.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ CustomModel <- new_model_class(
11061106
self$optimizer <- optimizer_adam(learning_rate=1e-3)
11071107
},
11081108
train_step = function(data) {
1109-
c(x, y, sample_weight) %<-% unpack_x_y_sample_weight(data)
1109+
c(x, y = NULL, sample_weight = NULL) %<-% data
11101110
with(tf$GradientTape() %as% tape, {
11111111
y_pred <- self(x, training=TRUE)
11121112
loss <- self$loss_fn(y = y, y_pred = y_pred, sample_weight=sample_weight)

0 commit comments

Comments
 (0)