# Train a Bert Classifier with more than 2 Input Text Columns

**URL:** <https://discuss.huggingface.co/t/train-a-bert-classifier-with-more-than-2-input-text-columns/59895>\
**Category:** Beginners\
**Created:** [October 25, 2023, 5:53pm UTC](https://discuss.huggingface.co/t/train-a-bert-classifier-with-more-than-2-input-text-columns/59895 "2023-10-25T17:53:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Archan](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/archan/32/28312_2.png) [@Archan](https://discuss.huggingface.co/u/Archan)\
**Post date:** [October 25, 2023, 5:53pm UTC](https://discuss.huggingface.co/t/train-a-bert-classifier-with-more-than-2-input-text-columns/59895/1 "2023-10-25T17:53:40Z")

</div>

Hi Guys, I am trying to train a bert based classifier for a problem that contains 2 text Columns.

The data looks like this:  
Text 1 | Text 2 | Label

It is a multi-class problem. I have tried following this [notebook](https://colab.research.google.com/github/DhavalTaunk08/Transformers_scripts/blob/master/Transformers_multilabel_distilbert.ipynb#scrollTo=StbPlIyKDP9E). But I am having a hard time on using 2 columns together. If someone can point me to the correct resource that would be really helpful.

---

<div class="post-metadata">

**Author:** ![hfreedma](https://avatars.discourse-cdn.com/v4/letter/h/59ef9b/32.png) [@hfreedma](https://discuss.huggingface.co/u/hfreedma)\
**Post date:** [October 25, 2023, 7:41pm UTC](https://discuss.huggingface.co/t/train-a-bert-classifier-with-more-than-2-input-text-columns/59895/2 "2023-10-25T19:41:05Z")

</div>

Is your problem with the tokenizer? You can pass in two input columns in your custom tokenize function, like:

```auto
def tokenize_function(examples):
    return tokenizer(examples["text1"], examples["text2"])

```

I’m not sure what aspect of the classification you are struggling with. I’m somewhat of a beginner myself, so more details and code examples would be helpful to help you better.

---

<div class="post-metadata">

**Author:** ![Archan](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/archan/32/28312_2.png) [@Archan](https://discuss.huggingface.co/u/Archan)\
**Post date:** [October 26, 2023, 3:57am UTC](https://discuss.huggingface.co/t/train-a-bert-classifier-with-more-than-2-input-text-columns/59895/3 "2023-10-26T03:57:32Z")

</div>

Any end to end solution would be helpful because I want to understand the entire process.

---

<div class="post-metadata">

**Author:** ![hfreedma](https://avatars.discourse-cdn.com/v4/letter/h/59ef9b/32.png) [@hfreedma](https://discuss.huggingface.co/u/hfreedma)\
**Post date:** [October 26, 2023, 11:30am UTC](https://discuss.huggingface.co/t/train-a-bert-classifier-with-more-than-2-input-text-columns/59895/4 "2023-10-26T11:30:10Z")

</div>

It would be better if you post the code you’ve tried so far and specify the specific problem that you’re having.  
These forums are usually not for tutorial-type solutions but more for getting help with specific problems.

---

<div class="post-metadata">

**Author:** ![Archan](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/archan/32/28312_2.png) [@Archan](https://discuss.huggingface.co/u/Archan)\
**Post date:** [October 27, 2023, 8:20am UTC](https://discuss.huggingface.co/t/train-a-bert-classifier-with-more-than-2-input-text-columns/59895/5 "2023-10-27T08:20:12Z")

</div>

I tried your way it worked.

````auto
tokenizer = AutoTokenizer.from_pretrained(model_str)
def tokenize_function(examples):
    return tokenizer(examples["ques_resp"], padding="max_length", truncation=True)
tokenized_datasets2 = dataset2.map(tokenize_function, batched=True)
tokenized_dataset_test = dataset_test.map(tokenize_function, batched=True)
small_train_dataset2 = tokenized_datasets2.shuffle(seed=42).select(range(0,3600))
small_eval_dataset2 = tokenized_datasets2.shuffle(seed=42).select(range(3600,3976))
display(small_train_dataset2)
display(small_eval_dataset2)```
````
