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

Add FreezableLookup which replaces several lookup tables. #29

Closed
wants to merge 1 commit into from

Conversation

danieldk
Copy link
Owner

@danieldk danieldk commented Nov 9, 2018

This change introduces a single lookup table that replaces:

  • TransitionLookup
  • LookupTable
  • MutableLookupTable

StoredLookupTable is simplified, but still exists as a wrapper around
FreezableLookup to simplify serialization.

FreezableLookup implements three traits:

  • LookupValue: defines the methods to look up an identifier for a value
    and vice versa. In contrast to the lookups that are replaced, values are
    borrowed during lookup and only cloned upon insertion.
  • LookupLen: defines the len method.
  • Lookup: inherits LookupValue and LookupLen and is implemented for any
    type that implements both traits.

In my first iteration, I had a single lookup trait. However, this
sometimes led to type inference problems when the len method was used.
Since len does not use the borrowed type in its signature, the type
parameter for Lookup<B> could not be inferred. So, instead, we make the
len method part of a trait without type parameters.

Fixes #19.

@danieldk danieldk requested review from DiveFish and twuebi November 9, 2018 08:21
@danieldk danieldk force-pushed the lookups branch 2 times, most recently from ef41f66 to f6cef40 Compare November 9, 2018 08:24

match &self.0 {
Fresh(cell) => cell.borrow_mut().add(t),
Frozen(numberer) => numberer.number(t).unwrap_or(0),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fixing unknown to 0 means that padding positions need explicit assignment of different values (Tensor initializes with 0 by default).

Copy link
Owner Author

Choose a reason for hiding this comment

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

I see this as something that the user of lookups should decide, since there are also uses of lookups where there is no padding, such as classes in non-sequence learning tasks. 0 is just a sentinel for 'the value is not present in the lookup'. If this is confusing, maybe lookup should should have start_at as well and this method should return Option for values that are absent.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer the verbose option with returning an Option, as numberer returns an Option anyway. This way the user gets to call unwrap_or and decides which value to assign.

dpar/src/lookup.rs Outdated Show resolved Hide resolved
This change introduces a single lookup table that replaces:

- TransitionLookup
- LookupTable
- MutableLookupTable

StoredLookupTable is simplified, but still exists as a wrapper around
FreezableLookup to simplify serialization.

FreezableLookup implements three traits:

- LookupValue: defines the methods to look up an identifier for a value
  and vice versa.
- LookupLen: defines the `len` method.
- Lookup: inherits LookupValue and LookupLen and is implemented for any
  type that implements both traits.

In my first iteration, I had a single lookup trait. However, this
sometimes led to type inference problems when the `len` method was used.
Since `len` does not use the borrowed type in its signature, the type
parameter for Lookup<B> could not be inferred. So, instead, we make the
`len` method part of a trait without type parameters.

Fixes #19.
@danieldk
Copy link
Owner Author

danieldk commented Jun 5, 2019

I will close this PR, dpar is currently not really my focus. I'll try to do it sometime later when there is time.

@danieldk danieldk closed this Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace various lookups by one data structure
2 participants