# How to specify labels-column in BERT

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-specify-labels-column-in-bert%2F13649%3E%5C
**Category:** Beginners\
**Created:** [January 13, 2022, 11:46am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-specify-labels-column-in-bert%2F13649 "2022-01-13T11:46:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fogx](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@fogx](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffogx)%5C
**Post date:** [January 13, 2022, 11:46am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-specify-labels-column-in-bert%2F13649%2F1 "2022-01-13T11:46:00Z")

</div>

Hi,  
i’m trying to follow the [huggingface datasets tutorial](https://huggingface.co/docs/datasets/quicktour.html) to finetune a BERT model on a custom dataset for sentiment analysis. The quicktour states:

> rename our label column in labels which is the expected input name for labels in BertForSequenceClassification.

In the [docs](https://huggingface.co/docs/datasets/package_reference/main_classes.html) for `to_tf_dataset` it states:

> label\_cols – Dataset column(s) to load as labels. Note that many models compute loss internally rather than letting Keras do it, in which case it is not necessary to actually pass the labels here, as long as they’re in the input columns.

I am uncertain if `label_cols` can be used to specify labels for differently named columns, or if it only possible to pass labels with a column named `label` inside the `columns` parameter?

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmariosasko)%5C
**Post date:** [January 19, 2022, 3:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-specify-labels-column-in-bert%2F13649%2F2 "2022-01-19T15:55:20Z")

</div>

Hi! It seems like you are following the old documentation. The new docs are available here: [https://huggingface.co/docs/datasets/master](https://huggingface.co/docs/datasets/master) (this is an example with `to_tf_dataset`: [https://huggingface.co/docs/datasets/master/use\_dataset.html#tensorflow](https://huggingface.co/docs/datasets/master/use_dataset.html#tensorflow)).

> I am uncertain if `label_cols` can be used to specify labels for differently named columns, or if it only possible to pass labels with a column named `label` inside the `columns` parameter?

Yes, `label_cols` supports columns not necessarily named `label`.

cc @Rocketknight1

---

<div class="post-metadata">

**Author:** ![fogx](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@fogx](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffogx)%5C
**Post date:** [January 20, 2022, 8:54am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-specify-labels-column-in-bert%2F13649%2F3 "2022-01-20T08:54:58Z")

</div>

thanks for your reply!  
The new documentation also has this quote where `label` is renamed to `labels`. So if i have a dataset where the label column is not called `labels` i have to specify it with `label_cols` right?

---

<div class="post-metadata">

**Author:** ![fogx](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@fogx](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ffogx)%5C
**Post date:** [January 20, 2022, 9:14am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-specify-labels-column-in-bert%2F13649%2F4 "2022-01-20T09:14:27Z")

</div>

I looked at this tutorial as well, where the label column is called `label`, and `label_cols` is not specified here. So these two tutorials seem to show conflicting information 😕  
[https://huggingface.co/docs/transformers/master/custom\_datasets](https://huggingface.co/docs/transformers/master/custom_datasets)

---

<div class="post-metadata">

**Author:** ![Rocketknight1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rocketknight1/32/21055_2.png) [@Rocketknight1](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FRocketknight1)%5C
**Post date:** [January 20, 2022, 1:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-specify-labels-column-in-bert%2F13649%2F5 "2022-01-20T13:05:23Z")

</div>

Hi @fogx, this is a good question! Here’s what’s happening in `to_tf_dataset`: `columns` specifies the list of columns to be passed as the input to the model, and `label_cols` specifies the list of columns to be passed to Keras at the label. For most tasks (including sentiment analysis), you will usually only want one column to be passed here, in which case it doesn’t really matter what it’s called because `to_tf_dataset` will only make the labels a dict when there are multiple label columns.

Sentiment analysis is an example of a ‘text classification’ task, so if you want a tutorial on that specifically, please take a look at [this notebook](https://github.com/huggingface/notebooks/blob/master/examples/text_classification-tf.ipynb) or the [colab link](https://colab.research.google.com/assets/colab-badge.svg).
