🚀 波斯智慧(PersianMind)
波斯智慧(PersianMind)是一款跨語言的波斯語 - 英語大語言模型。該模型在Belebele基準測試的波斯語子集以及ParsiNLU多項選擇問答任務中取得了最先進的成果。在波斯語閱讀理解任務中,它的表現也與GPT - 3.5 - turbo相媲美。
🚀 快速開始
模型使用入門
使用以下代碼開始使用該模型。請注意,要運行此代碼,你需要安裝sentencepiece
和accelerate
庫,以及PyTorch
和🤗Transformers
。
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained(
"universitytehran/PersianMind-v1.0",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
device_map={"": device},
)
tokenizer = AutoTokenizer.from_pretrained(
"universitytehran/PersianMind-v1.0",
)
TEMPLATE = "{context}\nYou: {prompt}\nPersianMind: "
CONTEXT = "This is a conversation with PersianMind. It is an artificial intelligence model designed by a team of " \
"NLP experts at the University of Tehran to help you with various tasks such as answering questions, " \
"providing recommendations, and helping with decision making. You can ask it anything you want and " \
"it will do its best to give you accurate and relevant information."
PROMPT = "در مورد هوش مصنوعی توضیح بده."
model_input = TEMPLATE.format(context=CONTEXT, prompt=PROMPT)
input_tokens = tokenizer(model_input, return_tensors="pt")
input_tokens = input_tokens.to(device)
generate_ids = model.generate(**input_tokens, max_new_tokens=512, do_sample=False, repetition_penalty=1.1)
model_output = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
print(model_output[len(model_input):])
模型量化方法
量化模型可以在資源受限的設備上運行。要對模型進行量化,你需要安裝bitsandbytes
庫。以下是在8位(INT8
)下量化模型的代碼:
model = AutoModelForCausalLM.from_pretrained(
"universitytehran/PersianMind-v1.0",
device_map="auto",
low_cpu_mem_usage=True,
load_in_8bit=True
)
或者,你可以使用以下代碼在4位(NormalFloat4
)下量化模型:
from transformers import BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
)
model = AutoModelForCausalLM.from_pretrained(
"universitytehran/PersianMind-v1.0",
quantization_config=quantization_config,
device_map="auto"
)
量化模型評估
我們對量化模型在各種任務中與原始模型進行了評估。具體來說,我們使用Belebele(波斯語子集)的閱讀理解多項選擇問答基準對所有模型進行了評估,並報告了每個模型的準確率。此外,我們還對模型進行了波斯語到英語和英語到波斯語的翻譯任務評估。為此,我們使用了Flores - 200數據集的波斯語 - 英語子集,並使用Comet指標報告了結果。此外,我們還計算了每個模型在運行翻譯任務時每秒生成的平均標記數。為了瞭解資源效率,我們使用get_memory_footprint()
函數測量了每個模型的內存使用情況。
模型 |
Belebele(波斯語) |
波斯語到英語翻譯 (Comet) |
英語到波斯語翻譯 (Comet) |
模型大小 |
每秒標記數 |
波斯智慧(PersianMind) (BF16 ) |
73.9 |
83.61 |
79.44 |
13.7G |
25.35 |
波斯智慧(PersianMind) (INT8 ) |
73.7 |
82.32 |
78.61 |
7.2G |
11.36 |
波斯智慧(PersianMind) (NF4 ) |
70.2 |
82.07 |
80.36 |
3.9G |
24.36 |
📄 許可證
波斯智慧(PersianMind)遵循Meta的LLaMa2社區許可證。它還根據CC BY - NC - SA 4.0許可,允許非商業使用該模型。商業使用此模型需要獲得版權持有者的書面協議,版權持有者在本頁面中列為開發者。如果你懷疑有任何違規行為,請與我們聯繫。
引用
如果你發現此模型有幫助,請引用以下論文:
BibTeX:
@misc{persianmind,
title={{PersianMind: A Cross-Lingual Persian-English Large Language Model}},
author={Rostami, Pedram and Salemi, Ali and Dousti, Mohammad Javad},
year={2024}
eprint={2401.06466},
archivePrefix={arXiv},
primaryClass={cs.CL}
}