# Combine multiple sentences together during tokenization

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcombine-multiple-sentences-together-during-tokenization%2F3430%3E%5C
**Category:** 🤗Tokenizers\
**Created:** [January 29, 2021, 2:52am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcombine-multiple-sentences-together-during-tokenization%2F3430 "2021-01-29T02:52:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prajjwal1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/prajjwal1/32/2246_2.png) [@prajjwal1](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fprajjwal1)%5C
**Post date:** [January 29, 2021, 2:52am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcombine-multiple-sentences-together-during-tokenization%2F3430%2F1 "2021-01-29T02:52:34Z")

</div>

I want my output to be like `[CLS] [SEP] text1 [SEP] text2 [SEP] text3 [SEP] eos token`. As per the default behaviour, tokenizer expects either a string or a pair of string.  
`tokenizer(sentence1, sentence2) # returns a single vector value for input_ids. I want this but for three sentences `  
I want the pair of string behavior for three sentences. I can pass a list of sentences, but that creates 3 lists of `input_ids`.  
`tokenizer([sentence1, sentence2, sentence3]) # returns three tensors for input_ids `

I want a single tensor representing the output I wrote above.  
Is there any good way of doing it ?

---

<div class="post-metadata">

**Author:** ![valhalla](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/valhalla/32/4179_2.png) [@valhalla](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvalhalla)%5C
**Post date:** [January 29, 2021, 9:12am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcombine-multiple-sentences-together-during-tokenization%2F3430%2F2 "2021-01-29T09:12:11Z")

</div>

I don’t think tokenizer handles this case directly.

You could directly join the sentences using `[SEP]` and then encode it as one single text.

```python
tok = BertTokenizer.from_pretrained("bert-base-cased")
text = "sent1 [SEP] sent2 [SEP] sent3"
ids = tok(text, add_special_tokens=True).input_ids
tok.decode(ids)
=> '[CLS] sent1 [SEP] sent2 [SEP] sent3 [SEP]'
```

---

<div class="post-metadata">

**Author:** ![prajjwal1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/prajjwal1/32/2246_2.png) [@prajjwal1](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fprajjwal1)%5C
**Post date:** [January 29, 2021, 2:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcombine-multiple-sentences-together-during-tokenization%2F3430%2F3 "2021-01-29T14:54:16Z")

</div>

Okay. Thanks. May have to manually add then.

---

<div class="post-metadata">

**Author:** ![bilalghanem](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@bilalghanem](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fbilalghanem)%5C
**Post date:** [February 4, 2022, 11:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcombine-multiple-sentences-together-during-tokenization%2F3430%2F4 "2022-02-04T23:32:22Z")

</div>

@prajjwal1 … I want to highlight a point here: using more than 2 [SEP] tokens with bert is not a g scientific solution. Bert wasn’t trained for that.
