Raise a NullMask()
error for degenerate token masks
#27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in #21, there are various scenarios in which token masking results in a LMTokenMask distribution that has a null support. The previous PR partially solved this problem by returning
-inf
, which avoided a crypticValueError
message. However, this still results in an uncaught downstream exception the next timesample()
orobserve()
is called, making it hard to localize the source of the error when debugging.On further reflection, a complete solution to this problem would be to implement tracing -- minimally, for mask objects, but ideally at the level of the
hfppl
itself -- to make it possible to track sequences of stochastic events leading to errors. I think this is a potentially useful approach but would require deeper refactors to the library than I have bandwidth for at the moment.In the spirit of keeping things simple for now, I think it makes sense to introduce a
NullMask()
error that gets raised when observing a degenerate mask. This has the sole purpose of providing a more descriptive error and a clear stack trace for what I've found to be a common corner case inhfppl
programs.