Diff of /man/reshape_tensor.Rd [000000] .. [409433]

Switch to unified view

a b/man/reshape_tensor.Rd
1
% Generated by roxygen2: do not edit by hand
2
% Please edit documentation in R/preprocess.R
3
\name{reshape_tensor}
4
\alias{reshape_tensor}
5
\title{Reshape tensors for set learning}
6
\usage{
7
reshape_tensor(
8
  x,
9
  y,
10
  new_batch_size,
11
  samples_per_target,
12
  buffer_len = NULL,
13
  reshape_mode = "time_dist",
14
  check_y = FALSE
15
)
16
}
17
\arguments{
18
\item{x}{3D input tensor.}
19
20
\item{y}{2D target tensor.}
21
22
\item{new_batch_size}{Size of first axis of input/targets after reshaping.}
23
24
\item{samples_per_target}{How many samples to use for one target}
25
26
\item{buffer_len}{Only applies if \code{reshape_mode = "concat"}. If \code{buffer_len} is an integer, the subsequences are interspaced with \code{buffer_len} rows. The reshaped x has
27
new maxlen: (\code{maxlen} \eqn{*} \code{samples_per_target}) + \code{buffer_len} \eqn{*} (\code{samples_per_target} - 1).}
28
29
\item{reshape_mode}{\verb{"time_dist", "multi_input"} or \code{"concat"}
30
\itemize{
31
\item If \code{"multi_input"}, will produce \code{samples_per_target} separate inputs, each of length \code{maxlen}.
32
\item If \code{"time_dist"}, will produce a 4D input array. The dimensions correspond to
33
\verb{(new_batch_size, samples_per_target, maxlen, length(vocabulary))}.
34
\item If \code{"concat"}, will concatenate \code{samples_per_target} sequences of length \code{maxlen} to one long sequence
35
}}
36
37
\item{check_y}{Check if entries in \code{y} are consistent with reshape strategy (same label when aggregating).}
38
}
39
\value{
40
A list of 2 tensors.
41
}
42
\description{
43
Reshape input x and target y. Aggregates multiple samples from x and y into single input/target batches.
44
}
45
\examples{
46
\dontshow{if (reticulate::py_module_available("tensorflow")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
47
# create dummy data
48
batch_size <- 8
49
maxlen <- 11
50
voc_len <- 4 
51
x <- sample(0:(voc_len-1), maxlen*batch_size, replace = TRUE)
52
x <- keras::to_categorical(x, num_classes = voc_len)
53
x <- array(x, dim = c(batch_size, maxlen, voc_len))
54
y <- rep(0:1, each = batch_size/2)
55
y <- keras::to_categorical(y, num_classes = 2)
56
y
57
58
# reshape data for multi input model
59
reshaped_data <- reshape_tensor(
60
  x = x,
61
  y = y,
62
  new_batch_size = 2,
63
  samples_per_target = 4,
64
  reshape_mode = "multi_input")
65
66
length(reshaped_data[[1]])
67
dim(reshaped_data[[1]][[1]])
68
reshaped_data[[2]]
69
\dontshow{\}) # examplesIf}
70
}