New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vectorized viterbi decoding #1
Conversation
For (20 states, 30k samples) data it makes StructuredPerceptron.fit 4x faster
@@ -48,15 +48,13 @@ def viterbi(Phi, trans, init, final): | |||
dp[0, :] = init + Phi[0, :] | |||
|
|||
backp = np.empty((n_samples, n_states), dtype=np.int32) | |||
_idx = np.mgrid[0:n_states] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this different from arange(n_states)
in any way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arange(n_states) works. I blindly followed an advice from here: http://numpy-discussion.10968.n7.nabble.com/using-numpy-argmax-to-index-into-another-array-td26387.html
Thanks! What's the number of samples? In my profiling runs, I found that Viterbi was actually quite cheap compared to the sparse dot products in |
X is the following:
Viterbi is still a bottleneck in this case, even after vectorizing:
|
ah, sequences are quite long in my case: 30000 samples from the above correspond to just 75 sequences. |
Ok, pulled as aa27b20, thanks! |
Hi,
Here is vectorized viterbi function. I didn't get how to vectorize it using outer products, so I just rewrote inner loop using numpy vectorized operations. For my data (20 states, 30k samples) it makes StructuredPerceptron.fit 4x faster.