GithubHelp home page GithubHelp logo

Comments (3)

zhaoyingjun avatar zhaoyingjun commented on July 19, 2024

是你的文件编码的问题

from chatbot.

Iron-head avatar Iron-head commented on July 19, 2024

execute.py下的decode_line()函数会把中文词转为二进制表示,所以在词字典中是找不到的,token_ids一直是[3,3,3,3…]

你好,我的也是这样,请问你解决了没

from chatbot.

wdwcn avatar wdwcn commented on July 19, 2024

execute.py下的decode_line()函数会把中文词转为二进制表示,所以在词字典中是找不到的,token_ids一直是[3,3,3,3…]

你好,我的也是这样,请问你解决了没

有点记不清当时都改了哪些地方,我把大佬的代码注释了一部分,绕过了转二进制部分。其他地方有没有修改不是太确定了。

def decode_line(sess, model, enc_vocab, rev_dec_vocab, sentence):
# Get token-ids for the input sentence.
#token_ids = prepareData.sentence_to_token_ids(tf.compat.as_bytes(sentence), enc_vocab)
#token_ids = prepareData.sentence_to_token_ids(sentence, enc_vocab)
def sentence_to_token_ids(sentence, enc_vocab):
token_ids=[]
for word in re.split(r'\s+',sentence):
token_ids.append(enc_vocab.get(word,3))
return(token_ids)
token_ids=sentence_to_token_ids(sentence,enc_vocab)

# Which bucket does it belong to?
bucket_id = min([b for b in xrange(len(_buckets)) if _buckets[b][0] > len(token_ids)])

# Get a 1-element batch to feed the sentence to the model.
encoder_inputs, decoder_inputs, target_weights = model.get_batch({bucket_id: [(token_ids, [])]}, bucket_id)

# Get output logits for the sentence.
_, _, output_logits = model.step(sess, encoder_inputs, decoder_inputs, target_weights, bucket_id, True)

# This is a greedy decoder - outputs are just argmaxes of output_logits.
outputs = [int(np.argmax(logit, axis=1)) for logit in output_logits]

# If there is an EOS symbol in outputs, cut them at that point.
if prepareData.EOS_ID in outputs:
    outputs = outputs[:outputs.index(prepareData.EOS_ID)]

return " ".join([tf.compat.as_str(rev_dec_vocab[output]) for output in outputs])

from chatbot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.