suriyadeepan / practical_seq2seq

A simple, minimal wrapper for tensorflow's seq2seq module, for experimenting with datasets rapidly
http://suriyadeepan.github.io/2016-12-31-practical-seq2seq/
GNU General Public License v3.0
569 stars 270 forks source link

How to predict sentence? #25

Closed lucasjinreal closed 6 years ago

lucasjinreal commented 7 years ago

Hi there, this repo is very helpful for NLP beginners, I currently success trained the model, however I don't know how to predict a given sentence by user. I defined a chat function:

def chat():
    # load data from pickle and npy files
    metadata, idx_q, idx_a = data.load_data(PATH='datasets/twitter/')

    w_2_id = dict(metadata['w2idx'])
    id_2_w = metadata['idx2w']

    sent = 'hello, what is your name?'
    sent_token = nltk.word_tokenize(sent)
    sent_index = np.array([data.pad_seq(sent_token, w_2_id, limit['max_q'])])
    print(sent_index)

    # parameters
    x_seq_len = sent_index.shape[-1]
    emb_dim = 400

    model = seq2seq_wrapper.Seq2Seq(xseq_len=x_seq_len,
                                    yseq_len=None,
                                    xvocab_size=None,
                                    yvocab_size=None,
                                    ckpt_path='ckpt/twitter/',
                                    emb_dim=emb_dim,
                                    num_layers=2
                                    )
    sess = model.restore_last_session()
    predict = model.predict(sess=sess, X=sent_index)

    print(predict)
    response = [id_2_w[i] for i in predict]

But I find that to define model I have to send train data x and y into it, I can't set is None, so basically I can not call predict function, is there any snippet that indicates how to predict on certain sentences? I am new to NLP and seq2seq model, and don't know how to edit your original model, any help would be appreciated!

anantbara commented 7 years ago

I'm also looking for the same...Please guide us.

PratsBhatt commented 7 years ago

I am looking for the same. Did anyone have a solution on how to evaluate the test batch and later a per sentence prediction? Thank you.

lucasjinreal commented 7 years ago

@PratsBhatt Are u trying to build a ChatBot or something?

PratsBhatt commented 7 years ago

Yes, I am actually trying to make use of the example. After training I want to utilise the model.

lucasjinreal commented 7 years ago

@PratsBhatt I am also interested in chatbot, I am using seq2seq model implement a QA system but the result isn't good. And I think simple QA is not the future of chatbot, multi dialog acquires more complex model.

PratsBhatt commented 7 years ago

@jinfagang , thanks. You are right multi dialog acquires better result as they are good in remembering the context of the conversation. I think the terminology is Deep Reinforcement Learning (https://arxiv.org/abs/1606.01541). If you have used this code, can you guide me on how to use the predict function, I am failing to do it effectively. Thanks for your help.

lucasjinreal commented 7 years ago

Haven't follow this repo for a while, but you can check original translate example of tensorflow models repo, just change the dataset.

kumiDa commented 7 years ago

@suriyadeepan, could you please help!!!

zvandervelde commented 7 years ago

+1

narutatsuri commented 6 years ago

Are you still looking for the instructions? I have a working code, if you want it.