Sentence-transformers: Input pair length in Cross Encoder

Created on 18 Nov 2020  路  1Comment  路  Source: UKPLab/sentence-transformers

Thank you for your useful and outstanding work!

I have a question when I use the Cross Encoder.

The input of Cross Encoder is a sentences pair or texts pair. And the pair length is max_length= 512.

So, when the length of two texts in the pair are both over 512 (after adding [cls] and [sep] token), the truncation method is only keep the first 510 tokens of text1 and drop all the tokens of text2 OR keep the first 255 tokens of both the two text and add a [SEP] token between them.

Additionally, if the truncation method is the previous one, I want to achieve the latter method锛寃hat will you recommand me to do?

Thanks a lot!

Most helpful comment

Hi @Davin-debug

the cross-encoder uses the 'longest_first' truncation strategy from Hugginface tokenizer:
https://huggingface.co/transformers/preprocessing.html

"This will truncate token by token, removing a token from the longest sequence in the pair until the proper length is reached."

So if text A is e.g. 260 tokens and text B is 500 tokens, A will be truncated to 255 tokens and B will also be truncated to 255 tokens. If text A is only 200 tokens, text B will be truncated to 310 tokens.

>All comments

Hi @Davin-debug

the cross-encoder uses the 'longest_first' truncation strategy from Hugginface tokenizer:
https://huggingface.co/transformers/preprocessing.html

"This will truncate token by token, removing a token from the longest sequence in the pair until the proper length is reached."

So if text A is e.g. 260 tokens and text B is 500 tokens, A will be truncated to 255 tokens and B will also be truncated to 255 tokens. If text A is only 200 tokens, text B will be truncated to 310 tokens.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x01h picture 0x01h  路  3Comments

Barcavin picture Barcavin  路  6Comments

aclifton314 picture aclifton314  路  3Comments

alejandrojcastaneira picture alejandrojcastaneira  路  5Comments

naserahmadi picture naserahmadi  路  3Comments