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

Can add additional parameters in calculating scores like rouge? #825

Closed
hookSSi opened this issue Feb 3, 2022 · 3 comments · Fixed by #838
Closed

Can add additional parameters in calculating scores like rouge? #825

hookSSi opened this issue Feb 3, 2022 · 3 comments · Fixed by #838
Assignees
Labels
enhancement New feature or request topic: Text
Milestone

Comments

@hookSSi
Copy link
Contributor

hookSSi commented Feb 3, 2022

🚀 Feature

Add tokenizer, normalizer parameters in calculating scores like rouge

Motivation

I wish I could consider another language when calculating scores like rouge

Because of _normalize_and_tokenize_text, I can only use english.

If only this is supported as a parameter, it will be good to be able to use other languages easily.

Pitch

rouge_score(preds, target, tokenizer, normalizer)
def _normalize_and_tokenize_text(text: str, tokenizer:lambda, normalizer:lambda, stemmer: Optional[Any] = None) -> Sequence[str]:
    """Rouge score should be calculated only over lowercased words and digits. Optionally, Porter stemmer can be
    used to strip word suffixes to improve matching. The text normalization follows the implemantion from `Rouge
    score_Text Normalizition`_
    Args:
        text:
            An input sentence.
        stemmer:
            Porter stemmer instance to strip word suffixes to improve matching.
    """
    # Replace any non-alpha-numeric characters with spaces.
    if normalizer is None:
        text = re.sub(r"[^a-z0-9]+", " ", text.lower())
    text = normalizer(text)

    tokens = re.split(r"\s+", text)
    if stemmer:
        # Only stem words more than 3 characters long.
        tokens = [stemmer.stem(x) if len(x) > 3 else x for x in tokens]

    # One final check to drop any empty or invalid tokens.
    if tokenizer is None:
        tokens = [x for x in tokens if (isinstance(x, str) and re.match(r"^[a-z0-9]+$", x))]
    tokens = tokenizer(text)

    return tokens
@hookSSi hookSSi added the enhancement New feature or request label Feb 3, 2022
@github-actions
Copy link

github-actions bot commented Feb 3, 2022

Hi! thanks for your contribution!, great first issue!

@hookSSi hookSSi changed the title Can add additional parameters in calculating scores like bleu, rouge? Can add additional parameters in calculating scores like rouge? Feb 3, 2022
@SkafteNicki
Copy link
Member

cc: @stancld opinion?

@stancld
Copy link
Contributor

stancld commented Feb 5, 2022

Hi @hookSSi, I think it's a good idea. The sacrebleu implementation of BLEUScore also allows to use of different tokenization techniques depending on the target language, so feel free to open PR. Looking forward :]

@Borda Borda added this to the v0.8 milestone Feb 11, 2022
@Borda Borda added this to the v0.8 milestone May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request topic: Text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants