char-rnn-tensorflow icon indicating copy to clipboard operation
char-rnn-tensorflow copied to clipboard

Char sequence probability

Open nournia opened this issue 8 years ago • 6 comments

Hi, I'm using char-rnn for computing sentence probability, which is main functionality of language modeling. This piece of code feeds sentence chars one by one and finds out probability of correctly predicting next char:

state = self.cell.zero_state(1, tf.float32).eval(session=session)
char_probas = []
input = np.zeros((1, 1))
for c, char in enumerate(sentence[:-1]):
    input[0, 0] = vocab[char]
    feed = {self.input_data: input, self.initial_state: state}
    [probs, state] = session.run([self.probs, self.final_state], feed)
    char_probas.append(probs[0][vocab[sentence[c+1]]])
probability = np.mean(char_probas)

It works fine and prefers well written sentences from sick ones. But I think it's not optimized for performance. Is it possible to feed one sequence of chars and receive generation probabilities for each one of them given previous chars? Currently, it seems that data transfer between host and device is a major bottleneck.

nournia avatar Jul 12 '16 02:07 nournia

@nournia Does 'log_probability' here give you the sentence probability?

pranjaldaga avatar Jul 28 '16 00:07 pranjaldaga

I've updated that piece of code and removed log from probability computation.

nournia avatar Jul 28 '16 10:07 nournia

It returns 'nan' when I try this piece of code for any sentence. Do you get the floating point probabilities with this @nournia ?

pranjaldaga avatar Jul 29 '16 22:07 pranjaldaga

It works for me. Are you getting proper results from sample.py script?

nournia avatar Aug 02 '16 07:08 nournia

I got the error 'tuple' object has no attribute 'eval' when applying your code. It's 'state = self.cell.zero_state(1, tf.float32).eval(session=session)' that go wrong. Can you help me with handling this?

spectrometerHBH avatar Jul 05 '18 01:07 spectrometerHBH

Why is probability the mean of the character probabilities? Shouldn't it be the product?

abhirut avatar Jan 27 '19 06:01 abhirut