🚀 NorGPT-3B-summarization-peft 模型
NorGPT-3B-summarization-peft 是在 NorGPT-3B 模型的基础上,使用 RLHF 策略在 NO-CNN-DailyMail 数据集上训练得到的模型。该模型主要用于文本摘要任务,通过独特的训练方式,能够生成高质量的文本摘要。
🚀 快速开始
运行模型
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "NorGLM/NorGPT-3B-rfhl-summarization"
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenizer.pad_token = tokenizer.eos_token
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map='auto',
torch_dtype=torch.bfloat16
)
在测试集上进行推理
加载模型以在 NO-CNN-DailyMail 数据集的测试集上进行评估:
def generate_texts(model, tokenizer, prompts, max_seq_length=200, do_sample=True, top_p=0.95, top_k=10):
results = []
cnt = 0
for prompt in prompts:
cnt += 1
pro_len = len(prompt.split())
if pro_len>1024:
results.append('')
continue
prompt = 'Summarise the article:\\n' + prompt + ' |||\\n'
model_inputs = tokenizer(prompt, return_tensors='pt').to(torch_device)
output = model.generate(**model_inputs, do_sample=False, max_new_tokens=max_seq_length)
result = tokenizer.decode(output[0], skip_special_tokens=True)
result = result.split("|||\\n")[-1]
results.append(result)
return results
print("--LOADING EVAL DATAS---")
eval_data = load_dataset("NorGLM/NO-CNN-DailyMail", data_files="test.csv")
prompts = eval_data['train']['article']
positive_samples = eval_data['train']['positive_sample']
print("--MAKING PREDICTIONS---")
model.eval()
output_file = <output file name>
with torch.no_grad():
results = generate_texts(model, tokenizer, prompts)
df = pd.DataFrame({'article':prompts, 'generated_text':results, 'positive_sample':positive_samples})
print("Save results to csv file...")
df.to_csv(output_file)
✨ 主要特性
与原始 RLHF 的第二步不同,该模型通过使用 NorBERT 模型估计候选生成文本与人工标注摘要(黄金摘要)之间的语义相似度来训练奖励模型。在奖励模型的训练中,与黄金摘要余弦相似度更高的生成摘要将获得更高的排名。
提示格式
Summarise the article:\\n{article} |||\\n{positive_sample}
推理提示
Summarise the article:\\n{article} |||\\n
📚 详细文档
训练数据划分
该模型在 RLHF 的步骤 1 - 步骤 3 中对数据进行了划分训练,具体划分情况如下:
步骤 |
样本数量 |
步骤 1 |
61181 |
步骤 2 |
16798 |
步骤 3 |
9758 |
📄 许可证
本模型遵循 CC BY-NC-SA 4.0 许可证。
📖 引用信息
如果您觉得我们的工作有帮助,请引用我们的论文:
@article{liu2023nlebench+,
title={NLEBench+ NorGLM: A Comprehensive Empirical Analysis and Benchmark Dataset for Generative Language Models in Norwegian},
author={Liu, Peng and Zhang, Lemei and Farup, Terje Nissen and Lauvrak, Even W and Ingvaldsen, Jon Espen and Eide, Simen and Gulla, Jon Atle and Yang, Zhirong},
journal={arXiv preprint arXiv:2312.01314},
year={2023}
}