Skip to content

Commit 53e8888

Browse files
Removed experimental flag.
PiperOrigin-RevId: 421709721
1 parent 4675fd8 commit 53e8888

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

site/en/guide/data.ipynb

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,7 @@
25722572
"id": "GxLAr-7p0ATX"
25732573
},
25742574
"source": [
2575-
"To use `tf.data.experimental.sample_from_datasets` pass the datasets, and the weight for each:"
2575+
"To use `tf.data.Dataset.sample_from_datasets` pass the datasets, and the weight for each:"
25762576
]
25772577
},
25782578
{
@@ -2583,7 +2583,7 @@
25832583
},
25842584
"outputs": [],
25852585
"source": [
2586-
"balanced_ds = tf.data.experimental.sample_from_datasets(\n",
2586+
"balanced_ds = tf.data.Dataset.sample_from_datasets(\n",
25872587
" [negative_ds, positive_ds], [0.5, 0.5]).batch(10)"
25882588
]
25892589
},
@@ -2623,15 +2623,15 @@
26232623
"id": "kZ9ezkK6irMD"
26242624
},
26252625
"source": [
2626-
"One problem with the above `experimental.sample_from_datasets` approach is that\n",
2627-
"it needs a separate `tf.data.Dataset` per class. Using `Dataset.filter`\n",
2628-
"works, but results in all the data being loaded twice.\n",
2626+
"One problem with the above `Dataset.sample_from_datasets` approach is that\n",
2627+
"it needs a separate `tf.data.Dataset` per class. You could use `Dataset.filter`\n",
2628+
"to create those two datasets, but that results in all the data being loaded twice.\n",
26292629
"\n",
2630-
"The `data.experimental.rejection_resample` function can be applied to a dataset to rebalance it, while only loading it once. Elements will be dropped from the dataset to achieve balance.\n",
2630+
"The `data.Dataset.rejection_resample` method can be applied to a dataset to rebalance it, while only loading it once. Elements will be dropped from the dataset to achieve balance.\n",
26312631
"\n",
2632-
"`data.experimental.rejection_resample` takes a `class_func` argument. This `class_func` is applied to each dataset element, and is used to determine which class an example belongs to for the purposes of balancing.\n",
2632+
"`data.Dataset.rejection_resample` takes a `class_func` argument. This `class_func` is applied to each dataset element, and is used to determine which class an example belongs to for the purposes of balancing.\n",
26332633
"\n",
2634-
"The elements of `creditcard_ds` are already `(features, label)` pairs. So the `class_func` just needs to return those labels:"
2634+
"The goal here is to balance the lable distribution, and the elements of `creditcard_ds` are already `(features, label)` pairs. So the `class_func` just needs to return those labels:"
26352635
]
26362636
},
26372637
{
@@ -2646,34 +2646,15 @@
26462646
" return label"
26472647
]
26482648
},
2649-
{
2650-
"cell_type": "markdown",
2651-
"metadata": {
2652-
"id": "DdKmE8Jumlp0"
2653-
},
2654-
"source": [
2655-
"The resampler also needs a target distribution, and optionally an initial distribution estimate:"
2656-
]
2657-
},
2658-
{
2659-
"cell_type": "code",
2660-
"execution_count": null,
2661-
"metadata": {
2662-
"id": "9tv0tWNxmkzM"
2663-
},
2664-
"outputs": [],
2665-
"source": [
2666-
"resampler = tf.data.experimental.rejection_resample(\n",
2667-
" class_func, target_dist=[0.5, 0.5], initial_dist=fractions)"
2668-
]
2669-
},
26702649
{
26712650
"cell_type": "markdown",
26722651
"metadata": {
26732652
"id": "YxJrOZVToGuE"
26742653
},
26752654
"source": [
2676-
"The resampler deals with individual examples, so you must `unbatch` the dataset before applying the resampler:"
2655+
"The resampling method deals with individual examples, so in this case you must `unbatch` the dataset before applying that method.\n",
2656+
"\n",
2657+
"The method needs a target distribution, and optionally an initial distribution estimate as inputs."
26772658
]
26782659
},
26792660
{
@@ -2684,7 +2665,12 @@
26842665
},
26852666
"outputs": [],
26862667
"source": [
2687-
"resample_ds = creditcard_ds.unbatch().apply(resampler).batch(10)"
2668+
"resample_ds = (\n",
2669+
" creditcard_ds\n",
2670+
" .unbatch()\n",
2671+
" .rejection_resample(class_func, target_dist=[0.5,0.5],\n",
2672+
" initial_dist=fractions)\n",
2673+
" .batch(10))"
26882674
]
26892675
},
26902676
{
@@ -2693,7 +2679,7 @@
26932679
"id": "L-HnC1s8idqV"
26942680
},
26952681
"source": [
2696-
"The resampler returns creates `(class, example)` pairs from the output of the `class_func`. In this case, the `example` was already a `(feature, label)` pair, so use `map` to drop the extra copy of the labels:"
2682+
"The `rejection_resample` method returns `(class, example)` pairs where the `class` is the output of the `class_func`. In this case, the `example` was already a `(feature, label)` pair, so use `map` to drop the extra copy of the labels:"
26972683
]
26982684
},
26992685
{

0 commit comments

Comments
 (0)