🚀 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}
}