我遵循本教程(https://colab.research.google.com/github/tensorflow/text/blob/master/docs/guide/subwords_tokenizer.ipynb#scrollTo=kh98DvoDz7Jn)从自定义数据集生成词汇表。在本教程中,该代码大约需要2分钟才能完成:
bert_vocab_args = dict(
# The target vocabulary size
vocab_size = 8000,
# Reserved tokens that must be included in the vocabulary
reserved_tokens=reserved_tokens,
# Arguments for `text.BertTokenizer`
bert_tokenizer_params=bert_tokenizer_params,
# Arguments for `wordpiece_vocab.wordpiece_tokenizer_learner_lib.learn`
learn_params={},
)
pt_vocab = bert_vocab.bert_vocab_from_dataset(
train_pt.batch(1000).prefetch(2),
**bert_vocab_args
)在我的数据集上花了很长时间..。我试着增加批号,减少词汇表的大小,但都没有效果。有什么办法能让事情发展得更快吗?
发布于 2022-04-09 00:30:03
我遇到了同样的问题。我就是这样解决的:
首先,我检查了数据集中的元素数:
examples, metadata = tfds.load('my_dataset', as_supervised=True, with_info=True)
print(metadata)在我的例子中,dataset包含了500多万个元素,这就解释了为什么创建词汇表要花费无尽的时间。
tensorflow示例的葡萄牙语词汇表是使用大约50000个元素构建的。因此,我选择了1%的数据集:
train_tokenize, metadata = tfds.load('my_dataset', split='train[:1%]',as_supervised=True, with_info=True)然后,我使用这个数据集来开发词汇表,大约花了2分钟:
train_en_tokenize = train_tokenize.map(lambda en, ol: en)
train_ol_tokenize = train_tokenize.map(lambda en, ol: ol)
ol_vocab = bert_vocab.bert_vocab_from_dataset(
train_ol_tokenize.batch(1000).prefetch(2),
**bert_vocab_args
)
en_vocab = bert_vocab.bert_vocab_from_dataset(
train_en_tokenize.batch(1000).prefetch(2),
**bert_vocab_args
)在这里,ol代表“另一种语言”,我正在开发这个模型。
https://stackoverflow.com/questions/70787972
复制相似问题