tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

Feature request - return better types from `batch`

Open oveddan opened this issue 5 years ago • 2 comments

Currently the method signature for batch always returns a Dataset<TensorContainer> which can be challenging to use again when you want to dig into the batched dataset as you have to cast the type.

For example:

const data = tf.data.array([1, 2, 3, 4, 5]);

// sequences is a Dataset<TensorContainer>
const sequences = data.batch(2, false);

const ioDataset = sequences.map(x => {
   const asTensor = x as Tensor1D;
   
    const inputText = asTensor.slice([0], [asTensor.shape[0] - 1]);
    const outputText = asTensor.slice([1], [asTensor.shape[0] - 1]);

    return [inputText, outputText];
});

It would be nice if the batch function above returned a Dataset<Tensor1D>

oveddan avatar Mar 10 '19 03:03 oveddan

Good point, thanks! I think this is possible but there may be some tricky edge cases-- we'll take a look.

davidsoergel avatar Mar 10 '19 05:03 davidsoergel

And similarly for take() and all the rest :)

davidsoergel avatar Mar 19 '19 16:03 davidsoergel

Hi, @oveddan

Apologize for the delayed response and I see this issue is too old so May I know have we taken care of this feature request or not ? If possible could you please try to replicate this issue with latest version of@tensorflow/[email protected] ? Thank you!

gaikwadrahul8 avatar Apr 29 '23 15:04 gaikwadrahul8

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

google-ml-butler[bot] avatar May 06 '23 15:05 google-ml-butler[bot]

Closing as stale. Please @mention us if this needs more attention.

google-ml-butler[bot] avatar May 13 '23 16:05 google-ml-butler[bot]