Skip to content
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

Aux labels plus notes on Python interface #29

Merged
merged 7 commits into from
May 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix typos
  • Loading branch information
danpovey committed May 6, 2020
commit 9f764588e5e4569187f01677cde9d9a8daa6a3c3
35 changes: 18 additions & 17 deletions notes/python.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@



# For composition we can rely on PyTorch's inbuilt autograd


# Assumes that A is an acceptor but B may
# have auxiliary symbols (i.e. may be a transducer).
def TransducerCompose(a: FsaVec, a_weights: Tensor,
b: FsaVec, b_weights: Tensor,
b_aux_symbols = None):
c, indexes_a, indexes_b = fsa.FsaVecCompose(a, b)

c_weights = a_weights[indexes_a] + b_weights[indexes_b]
if b_aux_symbols is None:
return c, c_weights
else:
return c, c_weights, fsa.MapAuxSymbols(b_aux_symbols, indexes_b)


def Compose(a: FsaVec, a_weights: Tensor,
a: FsaVec, b_weights: Tensor):
b: FsaVec, b_weights: Tensor):
c, input_indexes1, input_indexes2 = fsa.FsaVecCompose(a, b)

c_weights = a_weights[input_indexes1] + b_weights[input_indexes2]
Expand Down Expand Up @@ -45,24 +60,10 @@



# Composing with transducers. Assumes that A is an acceptor but B may
# have auxiliary symbols.
def TransducerCompose(a: FsaVec, a_weights: Tensor,
a: FsaVec, b_weights: Tensor,
b_aux_symbols = None):
c, indexes_a, indexes_b = fsa.FsaVecCompose(a, b)

c_weights = a_weights[indexes_a] + b_weights[indexes_b]
if b_aux_symbols is None:
return c, c_weights
else:
return c, c_weights, fsa.MapAuxSymbols(b_aux_symbols, indexes_b)


class TotalWeight(Function):
"""
Returns the total weight of FSAs (i.e. the log-sum-exp across
paths) as a Tensor with shapee (num_fsas,)
paths) as a Tensor with shape (num_fsas,)
"""

@staticmethod
Expand Down