You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using the ProbabilisticGrammarMiner to learn the probability distribution from a set of given inputs, the miner does not return the correct probabilistic grammar. In particular, this bug occurs whenever a grammar is used with a production rule that has an "empty" alternative: ⟨maybe_minus⟩ ::= "" | "-". Somehow the miner does not account for the empty ("") derivation sequence.
To Reproduce
You can reproduce the failure with the following simple grammar and code:
I was able to track down the bug to the function expansion_key(...) which is used by the ProbabilisticGrammarMiner in the function set_expansion_probabilities(...). The function expansion_key does not account for the empty expansion of the production rule "<maybe_minus>": ["", "-"].
Adding the following case to the expansion_key function, solved the issue for me:
# Check for empty list expansionifisinstance(expansion, list) andnotexpansion:
expansion=""
defexpansion_key(symbol: str,
expansion: Union[Expansion,
DerivationTree,
List[DerivationTree]]) ->str:
"""Convert (symbol, `expansion`) into a key "SYMBOL -> EXPRESSION". `expansion` can be an expansion string, a derivation tree, or a list of derivation trees."""ifisinstance(expansion, tuple):
# Expansion or single derivation treeexpansion, _=expansion# Check for empty list expansionifisinstance(expansion, list) andnotexpansion:
expansion=""ifnotisinstance(expansion, str):
# Derivation treechildren=expansionexpansion=all_terminals((symbol, children))
assertisinstance(expansion, str)
returnsymbol+" -> "+expansion
Desktop (please complete the following information):
OS: macOS Ventura 13.0.1
Python version 3.10.9
The text was updated successfully, but these errors were encountered:
Describe the bug
When using the ProbabilisticGrammarMiner to learn the probability distribution from a set of given inputs, the miner does not return the correct probabilistic grammar. In particular, this bug occurs whenever a grammar is used with a production rule that has an "empty" alternative: ⟨maybe_minus⟩ ::= "" | "-". Somehow the miner does not account for the empty ("") derivation sequence.
To Reproduce
You can reproduce the failure with the following simple grammar and code:
The output is the following learned probabilistic grammar:
Expected behavior
However, with the given inputs, we expect the probabilities of the "<maybe_minus>" production rule to be:
Correct probabilistic grammar:
Potential Fix
I was able to track down the bug to the function
expansion_key(...)
which is used by the ProbabilisticGrammarMiner in the functionset_expansion_probabilities(...)
. The functionexpansion_key
does not account for the empty expansion of the production rule "<maybe_minus>": ["", "-"].Adding the following case to the
expansion_key
function, solved the issue for me:Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: