Code Monkey home page Code Monkey logo

Comments (1)

iceychris avatar iceychris commented on June 6, 2024

Hey!

You can extract alignment information by adding some code after line 886:

# iterate through all timesteps
y_seq, log_p = [], 0.0
for t, h_t_enc in enumerate(encoder_out):
iters = 0
while iters < max_iters:
iters += 1
# h_t_enc is of shape [H]
# go through the joint network
_h_t_pred = h_t_pred[None]
_h_t_enc = h_t_enc[None, None, None]
joint_out = self.joint(
_h_t_pred, _h_t_enc, temp=temp_model, softmax=True, log=False
)
# decode one character
# extra["outs"].append(joint_out.clone())
prob, pred = joint_out.max(-1)
pred = int(pred)
log_p += float(prob)
# if blank, advance encoder state
# if not blank, add to the decoded sequence so far
# and advance predictor state
if pred == self.blank:
break
else:
# fuse with lm
_, prob, pred = fuser.fuse(joint_out, prob, pred, alpha=alpha)
# print(iters)
y_seq.append(pred)
y_one_char[0][0] = pred
# advance predictor
h_t_pred, pred_state = self.predictor(y_one_char, state=pred_state)
# advance lm
fuser.advance(y_one_char, temp=temp_lm)

Save the current encoder timestamp index t (from line 855) together with the current output token pred in a list.

To convert t to seconds, you could use sth like:

# encoder input freq, depends on the model architecture
#  usually 80ms
encoder_freq = 0.08

# rough alignment estimate for an output at encoder output index t
t_seconds = t * encoder_freq

Note that this is just a rough estimate and the actual alignment is usually slightly
off when using RNN-T based models like shown in Figure 1 of this paper.

from libreasr.

Related Issues (7)

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.