def build_vocab(train_dir, vocab_dir, vocab_size=5000):
    '根据训练集构建词汇表，存储, x， y'
    (data_train, _) = read_file(train_dir)
    all_data = []
    for content in data_train:
        all_data.extend(content)
    counter = Counter(all_data)
    count_pairs = counter.most_common((vocab_size - 1))
    (words, _) = list(zip(*count_pairs))
    words = (['<PAD>'] + list(words))
    open_file(vocab_dir, mode='w').write(('\n'.join(words) + '\n'))
根据训练集构建词汇表，存储, x， y
def build_vocab(train_dir, vocab_dir, vocab_size=5000):
    
    (data_train, _) = read_file(train_dir)
    all_data = []
    for content in data_train:
        all_data.extend(content)
    counter = Counter(all_data)
    count_pairs = counter.most_common((vocab_size - 1))
    (words, _) = list(zip(*count_pairs))
    words = (['<PAD>'] + list(words))
    open_file(vocab_dir, mode='w').write(('\n'.join(words) + '\n'))