# Train T5/BART to convert a string into multiple strings

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrain-t5-bart-to-convert-a-string-into-multiple-strings%2F27190%3E%5C
**Category:** 🤗Transformers\
**Created:** [December 3, 2022, 6:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrain-t5-bart-to-convert-a-string-into-multiple-strings%2F27190 "2022-12-03T18:08:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mph](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mph/32/12500_2.png) [@mph](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmph)%5C
**Post date:** [December 3, 2022, 6:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrain-t5-bart-to-convert-a-string-into-multiple-strings%2F27190%2F1 "2022-12-03T18:08:12Z")

</div>

Is it possible to train a seq2seq model like T5 or BART to convert a string into a list of strings? On my first attempt, the tokenizer complained that my 2D list of labels isn’t the correct data type:

```auto
File "/home/matt/miniconda3/envs/nlp/lib/python3.10/site-packages/transformers/tokenization_utils_fast.py", line 429, in _batch_encode_plus
    encodings = self._tokenizer.encode_batch(
TypeError: TextEncodeInput must be Union[TextInputSequence, Tuple[InputSequence, InputSequence]]

```

I suppose I could concatenate the multiple strings in each of my training examples, but then I’d have to use a potentially error-prone splitter to split them up again. Maybe using a special character as a delimiter is the answer here?

It’s not super relevant, but here’s how I’m invoking the tokenizer, using a subclass of `torch.utils.data.Dataset`:

```auto
tokenizer = AutoTokenizer.from_pretrained(args.model_name)
encodings = tokenizer(texts, truncation=True, padding=True, return_tensors='pt')
decodings = tokenizer(labels, truncation=True, padding=True, return_tensors='pt')
dataset_tokenized = Dataset(encodings, decodings)

```

What is relevant is that my `texts` variable is a list of strings, and my `labels` variable is a 2D list of strings, which obviously isn’t allowed.

---

<div class="post-metadata">

**Author:** ![mph](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mph/32/12500_2.png) [@mph](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmph)%5C
**Post date:** [December 10, 2022, 7:24am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrain-t5-bart-to-convert-a-string-into-multiple-strings%2F27190%2F3 "2022-12-10T07:24:46Z")

</div>

Using a special delimiter worked great! I chose the pipe character.

`pairs = [(source, ' | '.join(target)) for source, target in pairs]`
