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

7.3 'load_metrics' を 'evaluate.load' に更新する #49

Open
skotani-db opened this issue Jan 5, 2025 · 0 comments
Open

7.3 'load_metrics' を 'evaluate.load' に更新する #49

skotani-db opened this issue Jan 5, 2025 · 0 comments

Comments

@skotani-db
Copy link

7.3.1 ROUGE - ROUGEを算出するための実装
datasets ライブラリの変更に伴い、'load_metrics' が廃止されているため、
ImportError: cannot import name 'load_metric' from 'datasets' が発生します。
代替手段として 'evaluate' の使用が推奨されています。以下のように実装を更新してはどうでしょうか。違いとしては、以前の dataset ライブラリでの実装では Precision, Recall も計算されましたが、F値のみが返却される仕様となっておりました。

!pip install evaluate
import evaluate

def compute_rouge(
    # 省略

    # ROUGEメトリクスをロード
    rouge = evaluate.load("rouge")

    # 省略
    
    # ROUGEスコアを計算
    scores = rouge.compute(rouge_types=["rouge1", "rouge2", "rougeL"])

    # 文ごとに辞書で返ってくるのでそのままリターンする
    return scores

# ROUGEを算出した結果を表示する
rouge_results = {
    "生成文1": compute_rouge([pred_wakati1], [ref_wakati]),
    "生成文2": compute_rouge([pred_wakati2], [ref_wakati]),
    "生成文3": compute_rouge([pred_wakati3], [ref_wakati]),
}
df_list = [
    pd.DataFrame.from_dict(rouge_results[k], orient="index", columns=['fmeasure'])
    for k in rouge_results.keys()
]
display(pd.concat(df_list, keys=rouge_results.keys(), axis=1).T)

7.3.2 BLEU - BLEUを算出するための実装
同様に、BLEUの実装も evaluate を使用してはどうでしょうか

import evaluate

def compute_bleu(
    # 省略

    # BLEUメトリクスをロード
    bleu = evaluate.load("bleu")

    # 省略
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