🚀 Mistral-7B-Instruct-Uz モデル
Mistral-7B-Instruct-Uz モデルは、ウズベク語と英語の自然言語処理タスクをサポートするために開発されたモデルです。公開データと合成データを用いて事前学習と命令微調整を行い、様々なタスクでの性能を向上させています。
🚀 クイックスタート
このモデルは、ウズベク語の機械翻訳、要約、対話システムなどの自然言語処理タスクに対応しています。以下のセクションでは、モデルのインストール、ダウンロード、使用方法について説明します。
✨ 主な機能
- ウズベク語と英語の自然言語処理タスクをサポート
- 機械翻訳、要約、対話システムなどのタスクで高性能
- 事前学習と命令微調整により、様々なタスクでの性能を向上
📦 インストール
behbudiy/Mistral-7B-Instruct-Uz
を mistral-inference と共に使用することをおすすめします。HF transformers のコードスニペットについては、下の方を参照してください。
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
CLI コマンドが使用可能になります。以下のコマンドでモデルとチャットできます。
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)
高度な使用法
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)
📚 ドキュメント
評価方法に関する情報
翻訳タスクの評価には、FLORES+ Uz-En / En-Uz データセットを使用しました。dev セットと test セットを統合して、Uz-En と En-Uz の各サブセットに対してより大きな評価データを作成しました。
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
このスクリプト を使用しました。
詳細情報
詳細と例については、以下のベースモデルを参照してください。
https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3
🔧 技術詳細
モデル情報
属性 |
详情 |
モデルタイプ |
Mistral-7B-Instruct-Uz |
訓練データ |
tahrirchi/uz-crawl、allenai/c4、MLDataScientist/Wikipedia-uzbek-2024-05-01、yahma/alpaca-cleaned、behbudiy/alpaca-cleaned-uz、behbudiy/translation-instruction |
評価指標 |
BLEU、COMET、Accuracy |
パイプラインタグ |
テキスト生成 |
性能比較
モデル名 |
BLEU Uz-En (ワンショット) |
BLEU En-Uz (ワンショット) |
COMET (Uz-En) |
COMET (Ez-Un) |
ウズベク語感情分析 |
ウズベク語ニュース分類 |
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+ Uz-En / En-Uz 評価データセットでの翻訳ベンチマーク (BLEU と COMET)、ウズベク語の感情分析、ニュース分類において、ベースモデルを上回る性能を示しています。また、英語の複数のタスクでの一般的な言語理解能力を測定する MMLU ベンチマークでも、微調整されたモデルは大幅な性能低下を示していません。
📄 ライセンス
このモデルは、Apache-2.0 ライセンスの下で公開されています。