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

纯请教 关于if sup #10

Open
magnificent1208 opened this issue Jul 4, 2023 · 3 comments
Open

纯请教 关于if sup #10

magnificent1208 opened this issue Jul 4, 2023 · 3 comments

Comments

@magnificent1208
Copy link

magnificent1208 commented Jul 4, 2023

def process(cls, tokenizer: ChatGLMTokenizer,config, a_ids, b_ids, max_seq_length, sptoken: typing.List,ensure_answer_min_length=1,sup=True):
        input_ids = a_ids[:max_seq_length - len(b_ids) -3 - ensure_answer_min_length] + b_ids
        a_len = len(input_ids) - len(b_ids)
        input_ids = input_ids[:max_seq_length - 3] + [config.eos_token_id]
        if sup:
            labels = [-100] * a_len + input_ids[a_len:]
        else:
            labels = copy.deepcopy(input_ids)
        input_ids = sptoken + input_ids
        labels = [-100] * len(sptoken) + labels

        d = TokenIdsFinal.process(input_ids,labels,max_seq_length,tokenizer)
        return [d]

这个if sup 的含义具体是什么?是pretrian和sft的区别对么?

@ssbuild
Copy link
Owner

ssbuild commented Jul 4, 2023

可以这么理解。

@magnificent1208
Copy link
Author

感谢解答

@magnificent1208
Copy link
Author

magnificent1208 commented Jul 12, 2023

看完您的代码,我的理解是:
pretrain跟finetune其实损失函数计算是一致的,只是构建label的时候不一样

def process(cls, tokenizer: ChatGLMTokenizer,config, a_ids, b_ids, max_seq_length, sptoken: typing.List,sliding_size = None,sup=True): if sliding_size is None: sliding_size = max_seq_length ds = [] input_ids_qa = a_ids + b_ids + [config.eos_token_id] if sup: labels_all = [-100] * len(a_ids) + b_ids else: labels_all = copy.deepcopy(input_ids_qa)
a_ids :问题q
b_ids :答案a
[config.eos_token_id]:结束token标志

如果监督学习,则label是 遮挡了q部分的内容
如果是非监督学习(pretrain),则label是q+a,完整的问答对。

这样的理解是正确的吗?

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

2 participants