Example #1
0
    def __init__(self, params):
        super(Seq2Seq, self).__init__()
        self.embedding_matrix = load_embedding_matrix()
        self.params = params
        self.encoder = Encoder(self.embedding_matrix, params["enc_units"],
                               params["batch_size"])

        self.attention = BahdanauAttention(params["attn_units"])

        self.decoder = Decoder(self.embedding_matrix, params["dec_units"],
                               params["batch_size"])
    def __init__(self, params):
        super(Seq2Seq, self).__init__()
        self.embedding_matrix = load_embedding_matrix()
        self.params = params
        self.encoder = Encoder(params["vocab_size"], params["embed_size"],
                               self.embedding_matrix, params["enc_units"],
                               params["batch_size"])

        self.attention_layer = BahdanauAttention(self.params['attn_units'])
        self.decoder = Decoder(self.params['vocab_size'],
                               self.params['embed_size'],
                               self.embedding_matrix, self.params['dec_units'],
                               self.params['batch_size'])
Example #3
0
    def __init__(self, params):
        super(PGN, self).__init__()
        self.embedding_matrix = load_embedding_matrix(
            max_vocab_size=params['max_vocab_size'])
        self.params = params
        self.encoder = Encoder(self.embedding_matrix, params["enc_units"],
                               params["batch_size"])

        self.attention = BahdanauAttention(params["attn_units"])

        self.decoder = Decoder(self.embedding_matrix, params["dec_units"],
                               params["batch_size"])

        self.pointer = Pointer()
Example #4
0
    def __init__(self, name_scope, params):
        super(Seq2Seq, self).__init__(name_scope)
        self.embedding_matrix = wv_loader.load_embedding_matrix()
        self.params = params
        self.encoder = Encoder('encoder',
                               enc_units=params["enc_units"],
                               batch_size=params["batch_size"],
                               word_vector=self.embedding_matrix)

        self.attention = BahdanauAttention('attention', params["attn_units"])

        self.decoder = Decoder('decoder',
                               dec_units=params["dec_units"],
                               batch_size=params["batch_size"],
                               word_vector=self.embedding_matrix)
    def __init__(self, params, vocab):
        super(Seq2Seq, self).__init__()
        self.embedding_matrix = load_embedding_matrix()
        self.params = params
        self.vocab = vocab
        self.batch_size = params["batch_size"]
        self.enc_units = params["enc_units"]
        self.dec_units = params["dec_units"]
        self.attn_units = params["attn_units"]
        print(self.embedding_matrix)
        print(self.enc_units)
        print(self.batch_size)
        self.encoder = Encoder(self.embedding_matrix, self.enc_units,
                               self.batch_size)

        self.attention = BahdanauAttention(self.attn_units)

        self.decoder = Decoder(self.embedding_matrix, self.dec_units,
                               self.batch_size)
"""
from utils import config
from utils.data_processing import load_dataset
from utils.wv_loader import load_vocab, load_embedding_matrix

import tensorflow as tf
import time
import os

gpus = tf.config.experimental.list_physical_devices('GPU')
for gpu in gpus:
    tf.config.experimental.set_memory_growth(gpu, True)

train_x, train_y, test_x = load_dataset()
vocab, reverse_vocab = load_vocab(config.vocab_path)
embedding_matrix = load_embedding_matrix()

# 训练集的长度
BUFFER_SIZE = len(train_x)

# 输入的长度
max_length_inp = train_x.shape[1]
# 输出的长度
max_length_targ = train_y.shape[1]

BATCH_SIZE = 10

# 训练一轮需要迭代多少步
steps_per_epoch = len(train_x) // BATCH_SIZE

# 词向量维度
Example #7
0
    def call(self, context_vector, dec_hidden, dec_inp):
        return tf.nn.sigmoid(
            self.w_s_reduce(dec_hidden) + self.w_c_reduce(context_vector) +
            self.w_i_reduce(dec_inp))


if __name__ == '__main__':
    # GPU资源配置
    config_gpu()
    # 读取vocab训练
    vocab, reverse_vocab = Vocab.load_vocab(save_wv_model_path)
    # 计算vocab size
    vocab_size = len(vocab)
    # 使用GenSim训练好的embedding matrix
    embedding_matrix = load_embedding_matrix(save_wv_model_path)

    input_sequence_len = 250
    BATCH_SIZE = 64
    embedding_dim = 500
    units = 1024

    # 编码器结构
    encoder = Encoder(vocab_size, embedding_dim, embedding_matrix, units,
                      BATCH_SIZE)
    # example_input
    example_input_batch = tf.ones(shape=(BATCH_SIZE, input_sequence_len),
                                  dtype=tf.int32)
    # sample input
    sample_hidden = encoder.initialize_hidden_state()