我们是否应该使用 huggingface 小写输入数据(预)训练 BERT uncased 模型?

Shall we lower case input data for (pre) training a BERT uncased model using huggingface?

我们是否应该使用 huggingface 小写输入数据(预)训练 BERT uncased 模型?我查看了 Thomas Wolf (https://github.com/huggingface/transformers/issues/92#issuecomment-444677920) 的回复,但不完全确定他是不是这个意思。

如果我们将文本小写会怎样?

我认为无论您传递给模型的是什么,bert-base-uncased 模型都会将文本小写。您也可以尝试玩玩具数据集并使用 BERT 标记器打印标记以进行确认。

Tokenizer 会处理这个。

一个简单的例子:

import torch
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', max_length = 10, padding_side = 'right')

input_ids = torch.tensor(tokenizer.encode('this is a cat', add_special_tokens=True, max_length = 10, pad_to_max_length = True)).unsqueeze(0)
print(input_ids)

input_ids = torch.tensor(tokenizer.encode('This is a Cat', add_special_tokens=True, max_length = 10, pad_to_max_length = True)).unsqueeze(0)
print(input_ids)

输出:

tensor([[ 101, 2023, 2003, 1037, 4937,  102,    0,    0,    0,    0]])
tensor([[ 101, 2023, 2003, 1037, 4937,  102,    0,    0,    0,    0]])

但是如果有的话,

tokenizer = BertTokenizer.from_pretrained('bert-base-cased', max_length = 10, padding_side = 'right')

input_ids = torch.tensor(tokenizer.encode('this is a cat', add_special_tokens=True, max_length = 10, pad_to_max_length = True)).unsqueeze(0)
print(input_ids)

input_ids = torch.tensor(tokenizer.encode('This is a Cat', add_special_tokens=True, max_length = 10, pad_to_max_length = True)).unsqueeze(0)
print(input_ids)
tensor([[ 101, 1142, 1110,  170, 5855,  102,    0,    0,    0,    0]])

tensor([[ 101, 1188, 1110,  170, 8572,  102,    0,    0,    0,    0]])