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

Conversation

danpovey
Copy link
Collaborator

@danpovey danpovey commented May 5, 2020

No description provided.

notes/python.txt Outdated

# For composition we can rely on PyTorch's inbuilt autograd
def Compose(a: FsaVec, a_weights: Tensor,
a: FsaVec, b_weights: Tensor):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is b:FsaVec, b_weights:Tensor

notes/python.txt Outdated
# 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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, I guess it is b:FsaVec

notes/python.txt Outdated
class TotalWeight(Function):
"""
Returns the total weight of FSAs (i.e. the log-sum-exp across
paths) as a Tensor with shapee (num_fsas,)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo shape

@@ -50,28 +50,28 @@ struct AuxLabels {
/*
Maps auxiliary labels after an FSA operation where each arc in the output
FSA corresponds to exactly one arc in the input FSA.
@param [in] labels_in Labels on the arcs of the input FSA
@param [in] labels_in int32_ts on the arcs of the input FSA
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the int32_ts means the plural of int32_t? (just a question as I really feel hard to get the meaning of Auxint32_ts from its name)

@@ -34,7 +34,7 @@ namespace k2 {
This allows you to store auxiliary labels (e.g. olabels or ilabels)
on each arc of an Fsa.
*/
struct AuxLabels {
struct Auxint32_ts {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not follow ClassNamingStyle.

// This comparator function compares the weights, but is careful in case of
// ties to ensure deterministic behavior.
bool operator < (const DetStateElement &other) const {
if (weight < other.weight) return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the return value if weight == other.weight ??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't realize I had included this code, it is not finished. I have to get back to this.

}
}

size_t size() const { return cur_output_state_; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it size_t ?

k2/csrc/fsa.h Outdated
language models. Actually we'll template on types like this. There is no
need to actually inherit from this class. */
class DeterministicGenericFsa {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public:

is missing?

int32_t Start();


bool LookupArc(int32_t cur_state,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there no const modifiers for Get ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is an interface for a possibly dynamic object.

private:

int32_t cur_output_state_ { 0 };
std::unordered_map<std::pair<uint64_t, uint64_t>, int32_t, DetStateVectorHasher> map_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DetStateHasher?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, might do that. This code needs to be finished.

@@ -0,0 +1,230 @@
// k2/csrc/fsa_algo.cc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename should be changed.

DetStateElement *elem = d.head;
int32_t seq_len = d.seq_len;
for (int32_t i = 0; i < seq_len; i++) {
a = elem->symbol + 102299 * a;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an error inside the for loop?

elem is never updated.


It should be ++i, not i++.

@danpovey
Copy link
Collaborator Author

danpovey commented May 6, 2020 via email

@danpovey
Copy link
Collaborator Author

danpovey commented May 6, 2020

Merging to avoid future conflicts, although not everything is resolved here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants