🚀 BODE
BODE是一款專為葡萄牙語設計的大語言模型(LLM),它基於Llama 2模型,通過在Alpaca數據集上進行微調訓練而成,該數據集由Cabrita的作者翻譯為葡萄牙語。此模型可用於葡萄牙語的自然語言處理任務,如文本生成、自動翻譯、文本摘要等。開發BODE的目的是解決葡萄牙語大語言模型稀缺的問題。經典模型(如LLaMa)雖能響應葡萄牙語提示,但存在大量語法錯誤,有時還會生成英語回覆。目前,免費使用的葡萄牙語模型較少,據我們所知,尚無專門使用葡萄牙語數據訓練的、具有130億或更多參數的模型。
點擊論文,瞭解更多關於BODE的信息。
本頁面提供的BODE模型版本是使用Recogna高級研究實驗室的內部資源訓練的。在獲得必要的授權後,我們將盡快發佈在Santos Dumont上訓練的原始模型版本。
🚀 快速開始
我們強烈建議在配備GPU的Kaggle平臺上使用本模型。你可以藉助HuggingFace的Transformers庫輕鬆使用BODE。不過,你需要獲得訪問LLaMa 2的授權。我們還在Google Colab上提供了一個Jupyter Notebook,點擊此處即可訪問。
✨ 主要特性
- 專為葡萄牙語設計:解決了葡萄牙語大語言模型稀缺的問題,能有效處理葡萄牙語自然語言處理任務。
- 基於Llama 2微調:在Alpaca數據集上進行微調,提升了模型在葡萄牙語任務上的性能。
📦 安裝指南
!pip install transformers
!pip install einops accelerate bitsandbytes
!pip install sentence_transformers
!pip install git+https://github.com/huggingface/peft.git
💻 使用示例
基礎用法
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
from peft import PeftModel, PeftConfig
llm_model = 'recogna-nlp/bode-7b-alpaca-pt-br'
hf_auth = 'HF_ACCESS_KEY'
config = PeftConfig.from_pretrained(llm_model)
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, trust_remote_code=True, return_dict=True, load_in_8bit=True, device_map='auto', token=hf_auth)
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path, token=hf_auth)
model = PeftModel.from_pretrained(model, llm_model)
model.eval()
def generate_prompt(instruction, input=None):
if input:
return f"""以下是一個描述任務的指令,以及一個提供更多上下文的輸入。請編寫一個合適的回覆來完成請求。
### 指令:
{instruction}
### 輸入:
{input}
### 回覆:"""
else:
return f"""以下是一個描述任務的指令。請編寫一個合適的回覆來完成請求。
### 指令:
{instruction}
### 回覆:"""
generation_config = GenerationConfig(
temperature=0.2,
top_p=0.75,
num_beams=2,
do_sample=True
)
def evaluate(instruction, input=None):
prompt = generate_prompt(instruction, input)
inputs = tokenizer(prompt, return_tensors="pt")
input_ids = inputs["input_ids"].cuda()
generation_output = model.generate(
input_ids=input_ids,
generation_config=generation_config,
return_dict_in_generate=True,
output_scores=True,
max_length=300
)
for s in generation_output.sequences:
output = tokenizer.decode(s)
print("回覆:", output.split("### 回覆:")[1].strip())
evaluate("詳細回答:什麼是山羊?")
🔧 技術細節
模型詳情
屬性 |
詳情 |
模型類型 |
Llama 2 |
訓練數據 |
Alpaca |
語言 |
葡萄牙語 |
可用版本
訓練與數據
BODE模型是基於Llama 2模型,通過在葡萄牙語Alpaca數據集(一個基於指令的數據集)上進行微調訓練得到的。最初的訓練是在LNCC的超級計算機Santos Dumont上進行的,項目編號為Fundunesp 2019/00697 - 8。本頁面提供的版本是在Recogna內部環境中使用相同數據和參數訓練的副本。
評估結果
指標 |
值 |
平均值 |
53.21 |
ENEM挑戰(無圖像) |
34.36 |
BLUEX(無圖像) |
28.93 |
OAB考試 |
30.84 |
Assin2 RTE |
79.83 |
Assin2 STS |
43.47 |
FaQuAD NLI |
67.45 |
HateBR Binary |
85.06 |
葡萄牙語仇恨言論二分類 |
65.73 |
tweetSentBR |
43.25 |
詳細結果可查看此處。
📄 許可證
本項目採用MIT許可證。
📖 引用
如果您在研究中使用BODE模型,可以引用這篇論文,具體引用格式如下:
@misc{bode2024,
title={Introducing Bode: A Fine-Tuned Large Language Model for Portuguese Prompt-Based Task},
author={Gabriel Lino Garcia and Pedro Henrique Paiola and Luis Henrique Morelli and Giovani Candido and Arnaldo Cândido Júnior and Danilo Samuel Jodas and Luis C. S. Afonso and Ivan Rizzo Guilherme and Bruno Elias Penteado and João Paulo Papa},
year={2024},
eprint={2401.02909},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
🤝 貢獻
歡迎對本模型進行改進的貢獻。您可以自由地提出問題和提交拉取請求。
🙏 致謝
感謝巴西國家科學計算實驗室(LNCC/MCTI)提供超級計算機SDumont的CAD資源。