Title: Add `flatten_indices` to `DatasetDict`
Author: maximxlss (CONTRIBUTOR)
State: closed
Created: 2023-05-27T10:55:44Z

Add `flatten_indices` to `DatasetDict` for convinience

Comments:
_The documentation is not available anymore as the PR was closed or merged._

<details>
<summary>Show benchmarks</summary>

PyArrow==8.0.0

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.006192 / 0.011353 (-0.005161) | 0.004410 / 0.011008 (-0.006598) | 0.095990 / 0.038508 (0.057482) | 0.032662 / 0.023109 (0.009553) | 0.322827 / 0.275898 (0.046929) | 0.352542 / 0.323480 (0.029062) | 0.005398 / 0.007986 (-0.002588) | 0.003926 / 0.004328 (-0.000403) | 0.075131 / 0.004250 (0.070880) | 0.046205 / 0.037052 (0.009153) | 0.330957 / 0.258489 (0.072468) | 0.360166 / 0.293841 (0.066325) | 0.027880 / 0.128546 (-0.100666) | 0.008813 / 0.075646 (-0.066833) | 0.327316 / 0.419271 (-0.091955) | 0.050071 / 0.043533 (0.006539) | 0.319939 / 0.255139 (0.064800) | 0.331593 / 0.283200 (0.048393) | 0.096745 / 0.141683 (-0.044938) | 1.445165 / 1.452155 (-0.006990) | 1.515538 / 1.492716 (0.022821) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.209365 / 0.018006 (0.191358) | 0.437007 / 0.000490 (0.436518) | 0.003207 / 0.000200 (0.003007) | 0.000088 / 0.000054 (0.000033) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.027261 / 0.037411 (-0.010151) | 0.105101 / 0.014526 (0.090575) | 0.117163 / 0.176557 (-0.059394) | 0.176237 / 0.737135 (-0.560898) | 0.122559 / 0.296338 (-0.173779) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.406792 / 0.215209 (0.191583) | 4.060831 / 2.077655 (1.983176) | 1.829691 / 1.504120 (0.325571) | 1.633155 / 1.541195 (0.091960) | 1.704817 / 1.468490 (0.236327) | 0.525325 / 4.584777 (-4.059452) | 3.752907 / 3.745712 (0.007194) | 1.857513 / 5.269862 (-3.412349) | 1.222237 / 4.565676 (-3.343439) | 0.065941 / 0.424275 (-0.358334) | 0.012498 / 0.007607 (0.004891) | 0.495009 / 0.226044 (0.268965) | 4.968074 / 2.268929 (2.699145) | 2.277898 / 55.444624 (-53.166727) | 1.936656 / 6.876477 (-4.939821) | 1.970698 / 2.142072 (-0.171374) | 0.635221 / 4.805227 (-4.170006) | 0.140539 / 6.500664 (-6.360125) | 0.064111 / 0.075469 (-0.011358) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.238151 / 1.841788 (-0.603637) | 14.681262 / 8.074308 (6.606954) | 13.405525 / 10.191392 (3.214133) | 0.163225 / 0.680424 (-0.517199) | 0.017282 / 0.534201 (-0.516918) | 0.395526 / 0.579283 (-0.183757) | 0.429156 / 0.434364 (-0.005208) | 0.470806 / 0.540337 (-0.069531) | 0.571290 / 1.386936 (-0.815646) |

</details>
PyArrow==latest

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.006444 / 0.011353 (-0.004909) | 0.004388 / 0.011008 (-0.006621) | 0.075004 / 0.038508 (0.036496) | 0.032904 / 0.023109 (0.009795) | 0.375360 / 0.275898 (0.099462) | 0.413684 / 0.323480 (0.090204) | 0.005854 / 0.007986 (-0.002132) | 0.005504 / 0.004328 (0.001175) | 0.075049 / 0.004250 (0.070799) | 0.047973 / 0.037052 (0.010920) | 0.377943 / 0.258489 (0.119454) | 0.427039 / 0.293841 (0.133198) | 0.028248 / 0.128546 (-0.100298) | 0.008972 / 0.075646 (-0.066674) | 0.081848 / 0.419271 (-0.337424) | 0.047935 / 0.043533 (0.004402) | 0.377980 / 0.255139 (0.122841) | 0.407856 / 0.283200 (0.124656) | 0.103454 / 0.141683 (-0.038229) | 1.469051 / 1.452155 (0.016896) | 1.590657 / 1.492716 (0.097941) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.192380 / 0.018006 (0.174374) | 0.440995 / 0.000490 (0.440505) | 0.004082 / 0.000200 (0.003882) | 0.000096 / 0.000054 (0.000042) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.029584 / 0.037411 (-0.007828) | 0.110051 / 0.014526 (0.095525) | 0.121196 / 0.176557 (-0.055361) | 0.172249 / 0.737135 (-0.564886) | 0.125380 / 0.296338 (-0.170958) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.435218 / 0.215209 (0.220009) | 4.354811 / 2.077655 (2.277156) | 2.102050 / 1.504120 (0.597930) | 1.913454 / 1.541195 (0.372260) | 1.974624 / 1.468490 (0.506134) | 0.529975 / 4.584777 (-4.054802) | 3.801605 / 3.745712 (0.055893) | 3.162408 / 5.269862 (-2.107454) | 1.599576 / 4.565676 (-2.966101) | 0.066710 / 0.424275 (-0.357565) | 0.012158 / 0.007607 (0.004551) | 0.549187 / 0.226044 (0.323142) | 5.489930 / 2.268929 (3.221002) | 2.646787 / 55.444624 (-52.797837) | 2.311915 / 6.876477 (-4.564562) | 2.335645 / 2.142072 (0.193572) | 0.641067 / 4.805227 (-4.164160) | 0.142227 / 6.500664 (-6.358437) | 0.065303 / 0.075469 (-0.010166) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.283209 / 1.841788 (-0.558579) | 15.241809 / 8.074308 (7.167501) | 14.131471 / 10.191392 (3.940079) | 0.143921 / 0.680424 (-0.536503) | 0.017497 / 0.534201 (-0.516704) | 0.402236 / 0.579283 (-0.177047) | 0.418917 / 0.434364 (-0.015447) | 0.461745 / 0.540337 (-0.078593) | 0.560212 / 1.386936 (-0.826724) |

</details>
</details>

![](https://cml.dev/watermark.png#7098922130cabfbfa6b8a3885ff2e6f032d6203d "CML watermark")