I’m now doing things like following, these works, but somehow UGLY.
Elegant solution wanted.
# read data
TEXT = data.Field()
LABELS = data.Field(sequential=False)
# use dataset A to build vocab
vocab_train, _, _ = data.TabularDataset.splits(path=args.vocab,
                                               train='train.csv',
                                               validation='valid.csv',
                                               test='test.csv',
                                               format='csv',
                                               fields=[('text', TEXT), ('label', LABELS)])
TEXT.build_vocab(vocab_train.text, wv_type=args.wv_type, wv_dim=args.wv_dim)
# reuse vocab for dataset B
train, val, test = data.TabularDataset.splits(path=args.data,
                                              train='train.csv',
                                              validation='valid.csv',
                                              test='test.csv',
                                              format='csv',
                                              fields=[('text', TEXT), ('label', LABELS)])
train_iter, val_iter, test_iter = data.BucketIterator.splits((train, val, test),
                                                             batch_sizes=(args.batch_size,
                                                                          4 * args.batch_size,
                                                                          4 * args.batch_size),
                                                             sort_key=lambda x: len(x.text),
                                                             device=0)
LABELS.build_vocab(train.label)