Code Monkey home page Code Monkey logo

Comments (11)

hadifar avatar hadifar commented on June 11, 2024

Hi @Abhinavfreecodecamp In word_index we have values for < START > and < End >.

from grammarcorrection.

Abhinavfreecodecamp avatar Abhinavfreecodecamp commented on June 11, 2024

can you elaborate more ? with example

from grammarcorrection.

Abhinavfreecodecamp avatar Abhinavfreecodecamp commented on June 11, 2024

I don't get first you store words in word then you replace it with index of those words, Then you again enumerate over those words ?

from grammarcorrection.

Abhinavfreecodecamp avatar Abhinavfreecodecamp commented on June 11, 2024

@hadifar please take a look below.
output:
Enter a sentence to correct typo:
hi
your input: hi
hi
746
746
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0


code:
#!/usr/bin/env python

-- coding: utf-8 --

import argparse

import numpy as np

import config
import seq2seq_attention
import general_helper

parser = argparse.ArgumentParser()
parser.add_argument('--cache_dir', default="../data/",
help='Path to cache files')

parser.add_argument('--weights_path', default="../models/weights/KerasAttentionNMT.h5",
help='Path to Weights checkpoint')

args = parser.parse_args()

word_index = np.load(open(args.cache_dir + config.CACHE_WORD_INDEX, 'rb'))
embedding = general_helper.load_embedding_matrix(word_index.item())
word_index = word_index.flatten()[0]
index_word = dict([(value, key) for (key, value) in word_index.items()])

model = seq2seq_attention.getModel(embedding, word_index)

model.load_weights(args.weights_path)

def predict(sentence):
words = sentence.split(' ')
#words = word_index[''] + words + word_index['']
words_id = []

for w in words:
    if w in word_index:
        print(w)
        print(word_index[w])
        words_id.append(word_index[w])
    else:
        words_id.append(word_index['<UNK>'])
words = words_id

ret = ""

m_input = [np.zeros((1, config.MAX_SEQ_LEN)), np.zeros((1, config.MAX_SEQ_LEN))]

for i, w in enumerate(words):
    m_input[0][0, i] = w
    print(w)
#m_input[1][0, 0] = word_index['<START>']

for w_i in range(1, config.MAX_SEQ_LEN):
    out = model.predict(m_input)
    out_w_i = out[0][w_i - 1].argmax()
    print(out_w_i)
    if out_w_i == 0:
        continue

    ret += index_word[out_w_i] + " "
    m_input[1][0, w_i] = out_w_i

return ret

while True:
print ("Enter a sentence to correct typo: ")
sent = input()
print ('your input: ' + sent)
print (predict(sent))
print(20 * '-')

from grammarcorrection.

hadifar avatar hadifar commented on June 11, 2024

It's teacher forcing mechanism. Take a look at here

from grammarcorrection.

Abhinavfreecodecamp avatar Abhinavfreecodecamp commented on June 11, 2024

@hadifar it is giving error that ['<'START'>'] in word_index key not found

from grammarcorrection.

Abhinavfreecodecamp avatar Abhinavfreecodecamp commented on June 11, 2024

@hadifar It would be great if you provide solution as your predict.py code is not working

from grammarcorrection.

hadifar avatar hadifar commented on June 11, 2024

Hi @Abhinavfreecodecamp, I really sorry for late response. Unfortunately I am busy these days. < start > keyword must be present in word_index because we added to each sentence during training. I try to deploy the model on Docker to resolve the issue.

from grammarcorrection.

Abhinavfreecodecamp avatar Abhinavfreecodecamp commented on June 11, 2024

@hadifar Thanks Please Let me know the output

from grammarcorrection.

Abhinavfreecodecamp avatar Abhinavfreecodecamp commented on June 11, 2024

@hadifar Hi Could you please revert back ASAP

from grammarcorrection.

Abhinavfreecodecamp avatar Abhinavfreecodecamp commented on June 11, 2024

@hadifar I got the solution, due to version change fit_on_text converts chars to lower case so is actually coded as .

from grammarcorrection.

Related Issues (5)

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.