Mistral 7B Instruct Uz
模型概述
模型特點
模型能力
使用案例
🚀 Mistral-7B-Instruct-Uz模型
Mistral-7B-Instruct-Uz模型通過公開可用和合成構造的烏茲別克語及英語數據進行持續預訓練和指令微調,在保留原有知識的同時增強了能力。該模型旨在支持烏茲別克語的各種自然語言處理任務,如機器翻譯、文本摘要和對話系統等,確保在這些應用場景中表現出色。
🚀 快速開始
安裝
推薦使用 behbudiy/Mistral-7B-Instruct-Uz
搭配 mistral-inference。執行以下命令進行安裝:
pip install mistral_inference
下載模型
from huggingface_hub import snapshot_download
from pathlib import Path
mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-Uz')
mistral_models_path.mkdir(parents=True, exist_ok=True)
snapshot_download(repo_id="behbudiy/Mistral-7B-Instruct-Uz", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
聊天功能
安裝 mistral_inference
後,環境中會有 mistral-chat
命令。可以使用以下命令與模型進行對話:
mistral-chat $HOME/mistral_models/7B-Instruct-Uz --instruct --max_tokens 256
指令跟隨
from mistral_inference.transformer import Transformer
from mistral_inference.generate import generate
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
from mistral_common.protocol.instruct.messages import UserMessage
from mistral_common.protocol.instruct.request import ChatCompletionRequest
tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
model = Transformer.from_folder(mistral_models_path)
completion_request = ChatCompletionRequest(messages=[UserMessage(content="O'zbekiston haqida ma'lumot ber.")])
tokens = tokenizer.encode_chat_completion(completion_request).tokens
out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
print(result)
使用 transformers
生成文本
如果想使用 Hugging Face transformers
生成文本,可以這樣做:
from transformers import pipeline
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Who are you?"},
]
chatbot = pipeline("text-generation", model="behbudiy/Mistral-7B-Instruct-Uz", device='cuda')
chatbot(messages)
✨ 主要特性
- 該模型經過持續預訓練和指令微調,結合了公開可用和合成構造的烏茲別克語及英語數據,在保留原始知識的同時提升了能力。
- 支持多種烏茲別克語自然語言處理任務,如機器翻譯、文本摘要和對話系統等。
📦 安裝指南
推薦使用 behbudiy/Mistral-7B-Instruct-Uz
搭配 mistral-inference。執行以下命令進行安裝:
pip install mistral_inference
💻 使用示例
基礎用法
from huggingface_hub import snapshot_download
from pathlib import Path
mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-Uz')
mistral_models_path.mkdir(parents=True, exist_ok=True)
snapshot_download(repo_id="behbudiy/Mistral-7B-Instruct-Uz", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
高級用法
from transformers import pipeline
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Who are you?"},
]
chatbot = pipeline("text-generation", model="behbudiy/Mistral-7B-Instruct-Uz", device='cuda')
chatbot(messages)
📚 詳細文檔
模型描述
Mistral-7B-Instruct-Uz 模型經過持續預訓練和指令微調,使用了公開可用和合成構造的烏茲別克語及英語數據,以保留其原始知識並增強能力。該模型旨在支持各種烏茲別克語自然語言處理任務,如機器翻譯、文本摘要和對話系統等,確保在這些應用中表現穩健。 有關與基礎模型相比的性能指標詳情,請參閱 此文章。
開發者信息
性能對比
模型名稱 | 烏茲別克語 - 英語 BLEU (單樣本) | 英語 - 烏茲別克語 BLEU (單樣本) | COMET (烏茲別克語 - 英語) | COMET (英語 - 烏茲別克語) | 烏茲別克語情感分析 | 烏茲別克語新聞分類 | MMLU (英語) (5樣本) |
---|---|---|---|---|---|---|---|
Llama-3.1 8B Instruct | 23.74 | 6.72 | 84.30 | 82.70 | 68.96 | 55.41 | 65.77 |
Llama-3.1 8B Instruct Uz | 27.42 | 11.58 | 85.63 | 86.53 | 82.42 | 60.84 | 62.78 |
Mistral 7B Instruct | 7.47 | 0.67 | 68.14 | 45.58 | 62.02 | 47.52 | 61.07 |
Mistral 7B Instruct Uz | 29.39 | 16.77 | 86.91 | 88.75 | 79.13 | 59.38 | 55.72 |
Mistral Nemo Instruct | 25.68 | 9.79 | 85.56 | 85.04 | 72.47 | 49.24 | 67.62 |
Mistral Nemo Instruct Uz | 30.49 | 15.52 | 87.04 | 88.01 | 82.05 | 58.2 | 67.36 |
Google Translate | 41.18 | 22.98 | 89.16 | 90.67 | — | — | — |
結果表明,針對烏茲別克語優化的模型在 FLORES+ 烏茲別克語 - 英語 / 英語 - 烏茲別克語評估數據集的翻譯基準測試(BLEU 和 COMET)、烏茲別克語情感分析和新聞分類任務中始終優於其基礎模型。 此外,在衡量英語多任務通用語言理解能力的 MMLU 基準測試中,微調後的模型性能沒有顯著下降。(基礎 Llama 模型的 MMLU 得分與官方得分不同,原因在於評估方法。請參考以下鏈接查看評估詳情。)
評估方法信息
翻譯任務評估
在翻譯任務評估中,我們使用了 FLORES+ 烏茲別克語 - 英語 / 英語 - 烏茲別克語數據集,將開發集和測試集合並,為每個烏茲別克語 - 英語和英語 - 烏茲別克語子集創建了更大的評估數據。 我們使用以下提示對基礎模型和針對烏茲別克語優化的模型進行單樣本烏茲別克語 - 英語評估(對於英語 - 烏茲別克語評估,我們交換了 “English” 和 “Uzbek” 這兩個詞的位置)。
prompt = f'''You are a professional Uzbek-English translator. Your task is to accurately translate the given Uzbek text into English.
Instructions:
1. Translate the text from Uzbek to English.
2. Maintain the original meaning and tone.
3. Use appropriate English grammar and vocabulary.
4. If you encounter an ambiguous or unfamiliar word, provide the most likely translation based on context.
5. Output only the English translation, without any additional comments.
Example:
Uzbek: "Bugun ob-havo juda yaxshi, quyosh charaqlab turibdi."
English: "The weather is very nice today, the sun is shining brightly."
Now, please translate the following Uzbek text into English:
"{sentence}"
'''
烏茲別克語情感分析評估
為了評估模型在烏茲別克語情感分析方面的能力,我們使用了 risqaliyevds/uzbek-sentiment-analysis 數據集,並使用 GPT-4o API 為其創建了二進制標籤(0: 負面,1: 正面)(參考 behbudiy/uzbek-sentiment-analysis 數據集)。 我們使用以下提示進行評估:
prompt = f'''Given the following text, determine the sentiment as either 'Positive' or 'Negative.' Respond with only the word 'Positive' or 'Negative' without any additional text or explanation.
Text: {text}"
'''
烏茲別克語新聞分類評估
在烏茲別克語新聞分類任務中,我們使用了 risqaliyevds/uzbek-zero-shot-classification 數據集,並要求模型使用以下提示預測新聞類別:
prompt = f'''Classify the given Uzbek news article into one of the following categories. Provide only the category number as the answer.
Categories:
0 - Politics (Siyosat)
1 - Economy (Iqtisodiyot)
2 - Technology (Texnologiya)
3 - Sports (Sport)
4 - Culture (Madaniyat)
5 - Health (Salomatlik)
6 - Family and Society (Oila va Jamiyat)
7 - Education (Ta'lim)
8 - Ecology (Ekologiya)
9 - Foreign News (Xorijiy Yangiliklar)
Now classify this article:
"{text}"
Answer (number only):"
'''
MMLU 評估
我們使用了 此腳本 進行 MMLU 評估。
更多信息
更多詳細信息和示例,請參考以下基礎模型: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3
🔧 技術細節
訓練數據
- tahrirchi/uz-crawl
- allenai/c4
- MLDataScientist/Wikipedia-uzbek-2024-05-01
- yahma/alpaca-cleaned
- behbudiy/alpaca-cleaned-uz
- behbudiy/translation-instruction
評估指標
- bleu
- comet
- accuracy
模型信息
屬性 | 詳情 |
---|---|
模型類型 | Mistral-7B-Instruct-Uz |
基礎模型 | mistralai/Mistral-7B-Instruct-v0.3 |
庫名稱 | transformers |
任務標籤 | 文本生成 |
📄 許可證
本項目採用 Apache-2.0 許可證。



