見出し画像

日本語も理解できたCohereForAIのオープンソースのLLMモデルを試してみる。

CohereForAIのLLMをGoogle ColabのA100で実行したので紹介していきます。フリーのLLMなのに文章生成、数値計算、英訳、日本語理解力がChatGPTみたく回答されているのに驚きました。

Hugging Faceで、CohereForAIのLLMのc4ai-command-r-v01が上位にランクインしていましましたので試してみることにしました。


今回は、上記にあるコードを少し修正して利用しています。Google Colabの環境は、A100です。LLMをダウンロードするのに時間がかかりますが、A100環境で実行できます。

!pip install transformers bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig

bnb_config = BitsAndBytesConfig(load_in_8bit=True)

model_id = "CohereForAI/c4ai-command-r-v01"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True, quantization_config=bnb_config)

# Format message with the command-r chat template
messages = [{"role": "user", "content": "Hello, how are you?"}]
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>

gen_tokens = model.generate(
    input_ids, 
    max_new_tokens=100, 
    do_sample=True, 
    temperature=0.3,
    )

gen_text = tokenizer.decode(gen_tokens[0])
print(gen_text)

messageのところで、"Hello, how are you?"と聞いています。

Hello! I'm doing well, thank you for asking. I'm excited to assist you with whatever questions or topics you have. How can I help you today?

回答結果

英語で聞いたので英語で返信されていますが、「質問されてうれしい」の旨を回答しています。

このmessageのところを変更して、他にも見て行きます。


messages = [{"role": "user", "content": "Do you introduce yourself?"}]

自己紹介をしてもらいましょう。


Yes, I do! My name is Coral, and I am a brilliant, sophisticated, AI-assistant chatbot trained to assist human users by providing thorough responses. I am powered by Command, a large language model built by Cohere. I'm here to help you in any way I can, whether it's answering questions, offering suggestions, or just having a friendly conversation. I'm always learning and improving, so feel free to give me a try and let me know what you think!

回答結果

Coralという名前が付けられているようです。真意は定かではありませんが。一般的なAI系LLMで出来ること、Cohereによって構築されたことを回答しています。


messages = [{"role": "user", "content": "What do you think of OpenAI?"}]

OpenAIについて、どう思いますかと聞いてみました。

As an AI chatbot, I'm unable to form opinions or preferences, including about organizations like OpenAI. However, OpenAI is a well-known and influential research and development company that focuses on creating artificial intelligence technologies. It was co-founded in 2015 by Elon Musk, who is also the co-founder of Tesla and SpaceX. OpenAI's mission is to develop artificial general intelligence (AGI) and make it beneficial for humanity, and its researchers work on a

回答結果

ここが凄いなと思いましたが、意見や嗜好性を述べることはできませんと回答しているのに驚きました。回答して良いと判断する感覚と回答を避けるべきと判断する感覚を身に着けているのですね。


messages = [{"role": "user", "content": "Please tell me the 1000th prime number."}]

1000番目の素数を教えて下さいと聞いてみます。

The 1000th prime number is 7919. This can be verified using prime number generating software or even simple trial and error, although that would be quite time consuming!

回答結果

7919と回答しています。あらかじめ素数の一覧を学習されている可能性も排除は出来ませんね。


messages = [{"role": "user", "content": "今の日本の首相を教えてください。"}]

日本語も出来るか試してみます。

現在、日本の首相は岸田文雄です。2021年9月29日に第100代内閣総理大臣に就任しました。<|END_OF_TURN_TOKEN|>

回答結果

日本語が理解できることに驚きました。


messages = [{"role": "user", "content": "次の文章を英訳してください。神は細部に宿る。"}]

日本語を英語に訳せるか試してみます。

God is in the details.

回答結果

当然、日本語から英語も出来ました。


messages = [{"role": "user", "content": "c4ai-command-r-v01について、ブログを書きたいので、紹介文章を書いてください。"}]

最後に、少し長い文章を書いてもらいます。

c4ai-command-r-v01は、AIを活用した最新のロボットコマンド制御システムです。このシステムは、ユーザーが自然言語でロボットに命令を出せるように設計されており、より直感的で人間的なインターフェースを提供します。 最新のNLP(自然言語処理)技術を利用して、正確で応答性の高いコマンドをロボットに提供し、よりスムーズで効率的な操作を実現します。 c4ai-command-r-v01は、ロボット工学とAIの融合の力強い例であり、ロボットとのやりとりをより簡単でアクセスしやすく、直感的なものに変えます。 このシステムは、家庭用ロボットから産業用ロボットまで、様々なアプリケーションに適応できるように設計されており、ロボット工学の未来を形作るのに役立つと期待されています。 ブログの読者は、この画期的な新技術について知るために待つ必要はありません。今すぐc4ai-command-r-v01をチェックして、ロボットとの対話の新しい時代を体験してください!

回答結果


この記事が気に入ったらサポートをしてみませんか?