# Iterating over Dataset with type='torch' columns

**URL:** <https://discuss.huggingface.co/t/iterating-over-dataset-with-type-torch-columns/27180>\
**Category:** 🤗Datasets\
**Created:** [December 3, 2022, 1:43pm UTC](https://discuss.huggingface.co/t/iterating-over-dataset-with-type-torch-columns/27180 "2022-12-03T13:43:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JustSaX](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JustSaX](https://discuss.huggingface.co/u/JustSaX)\
**Post date:** [December 3, 2022, 1:43pm UTC](https://discuss.huggingface.co/t/iterating-over-dataset-with-type-torch-columns/27180/1 "2022-12-03T13:43:54Z")

</div>

Hi

I have a Dataset that contains both torch Tensor columns and normal python (text, float) data columns.  
As soon as I change one of the columns to type=‘torch’ I can only iterate over this specific column not all of the columns.

Example:

```auto
import torch
from datasets import Dataset
ds_dict = {'text':['text1','text2'],'tens':torch.Tensor([1,2])}
ds = Dataset.from_dict(ds_dict)
for row in ds:
    print(row)

```

Output:

```auto
{'text': 'text1', 'tens': 1.0}
{'text': 'text2', 'tens': 2.0}

```

Now changing ‘tens’ to torch:

```auto
ds.set_format(type='torch',columns=['tens'])
for row in ds:
    print(row)

```

Ouptut:

```auto
{'tens': tensor(1.)}
{'tens': tensor(2.)}

```

The iteration is now missing column ‘text’

But the column is still in the dataset:

```auto
print(ds)

```

Output:

```auto
Dataset({
    features: ['text', 'tens'],
    num_rows: 2
})

```

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](https://discuss.huggingface.co/u/mariosasko)\
**Post date:** [December 5, 2022, 2:39pm UTC](https://discuss.huggingface.co/t/iterating-over-dataset-with-type-torch-columns/27180/2 "2022-12-05T14:39:27Z")

</div>

Hi! By default, only the columns specified as `columns` are returned after `set_format`. To preserve all the columns, set `output_all_columns=Ture` in the `set_format` call.
