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

What does score_partial_token of HotwordsScorer do ? #76

Open
bruno-hays opened this issue Jun 6, 2022 · 0 comments
Open

What does score_partial_token of HotwordsScorer do ? #76

bruno-hays opened this issue Jun 6, 2022 · 0 comments

Comments

@bruno-hays
Copy link

bruno-hays commented Jun 6, 2022

I'm looking at modifying the base HotwordsScorer to boost short sentences instead of just individual words.
But I fail to understand what the score_partial_token function does. The comment in the code seems to have been copy pasted from the score function and does not help:

def score(self, text: str) -> float:
    """Get total hotword score for input text."""
    return self._weight * len(self._match_ptn.findall(text))

def score_partial_token(self, token: str) -> float:
    """Get total hotword score for input text."""
    if token in self:
        # find shortest unigram starting with the given partial token
        min_len = len(next(self._char_trie.iterkeys(token, shallow=True)))
        # scale score by length of unigram matched so far
        score = self._weight * len(token) / min_len
    else:
        score = 0.0
    return score
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

No branches or pull requests

1 participant