Skip to content

在训练PPO时遇到的问题 #810

Description

@wuyanjay

hi大佬,今天在学习训练ppo的源码时,手动调用train_ppo.py里面的rep_penalty学习时发现好像对中文的重复惩罚系数计算不正常,想问下大佬是不是我的理解有偏差。以下是我的调用过程

def rep_penalty(text, n=3, cap=0.5):
    toks = re.findall(r"\w+|[^\w\s]", text.lower())
    grams = [tuple(toks[i:i + n]) for i in range(len(toks) - n + 1)]
    return min(cap, (len(grams) - len(set(grams))) * cap * 2 / len(grams)) if grams else 0.0
from transformers import AutoTokenizer
import re

tokenizer = AutoTokenizer.from_pretrained("tokenizer_model")

text = ["你好你好你好你好你好", "hello hello hello hello"]

input_ids = tokenizer(text).input_ids

res = tokenizer.batch_decode(input_ids)

for t in res:
    scores = rep_penalty(t)
    print(scores)
0.0
0.5

以上情况在使用中文语料训练时,会不会导致模型的中文大量重复输出时得不到正确的惩罚?希望大佬不吝赐教

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions