Fix convert_freqs.py writing hardcoded oov_prob instead of computed value#576
Open
Chessing234 wants to merge 2 commits intoallenai:mainfrom
Open
Fix convert_freqs.py writing hardcoded oov_prob instead of computed value#576Chessing234 wants to merge 2 commits intoallenai:mainfrom
Chessing234 wants to merge 2 commits intoallenai:mainfrom
Conversation
…type export_umls_json.py prints per-concept summary statistics. The aliases block pairs 'one alias' (== 1) with 'more than one alias' (> 1). The types block pairs 'one type' (== 1) with 'more than one type' (>= 1), so every concept with >= 1 type is counted under both with_one_type_count and with_more_than_one_type_count, inflating the 'more than one type' statistic by the count of single-type concepts. Change >= 1 to > 1 to match the aliases pattern and the variable's name.
…alue
scripts/convert_freqs.py computes the out-of-vocabulary probability
from the input frequencies in read_freqs:
oov_prob = math.log(counts.smoother(0)) - log_total
return probs, oov_prob
and main() already unpacks it:
probs, oov_prob = (
read_freqs(input_path, min_freq=min_word_frequency)
if input_path is not None
else ({}, -20)
)
But the file write then ignores it and hardcodes a specific float:
json.dumps({"lang": "en", "settings": {"oov_prob": -20.502029418945312}})
so every generated lexeme file always reports the same oov_prob
regardless of the corpus. This also contradicts the `-20` default
chosen when `input_path is None` — with the hardcoded value those two
branches produce different files despite going through the same path.
Use the computed/selected `oov_prob` value so the serialized settings
reflect the actual distribution (or the explicit default when no input
is given).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug
`scripts/convert_freqs.py` computes an OOV probability from the input frequency file and unpacks it in `main`:
```python
read_freqs(...)
oov_prob = math.log(counts.smoother(0)) - log_total
return probs, oov_prob
main(...)
probs, oov_prob = (
read_freqs(input_path, min_freq=min_word_frequency)
if input_path is not None
else ({}, -20)
)
```
But the serialization step throws that value away:
```python
json.dumps({"lang": "en", "settings": {"oov_prob": -20.502029418945312}})
```
Root cause
The hardcoded float never changes — every lexeme file the script produces records the same OOV probability regardless of the corpus that was analyzed. That also contradicts the `-20` default chosen a few lines above when `input_path is None`: those two branches are supposed to produce distinct settings but the output file is identical.
Fix
Write the `oov_prob` that was just computed (or the `-20` default if no input was supplied) instead of the frozen literal, so the serialized settings reflect the distribution the script was asked to convert.