楽天が日本語に最適化したLLMを公開したとのことで早速試してみました。
マシン情報
- NVIDIA A100-SXM
- AMD EPYC 7742 64-Core Processor
- 416GB RAM
- Ubuntu 22.04.3 LTS
環境構築
pip3 install transformers
pip3 install torch torchvision torchaudio
pip3 install accelerate
!git clone https://huggingface.co/Rakuten/RakutenAI-7B-chat
実行
readmeにあるコードを基に動かしてみました。
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_path = "Rakuten/RakutenAI-7B-chat"
tokenizer = AutoTokenizer.from_pretrained(model_path)
# モデルをCPUまたはGPUに明示的にロードするようにautoから変更
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained(model_path).to(device)
model.eval()
requests = [
"「馬が合う」はどう言う意味ですか",
"How to make an authentic Spanish Omelette?",
]
system_message = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: {user_input} ASSISTANT:"
for req in requests:
input_req = system_message.format(user_input=req)
input_ids = tokenizer.encode(input_req, return_tensors="pt").to(device)
tokens = model.generate(
input_ids,
max_new_tokens=1024,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
)
out = tokenizer.decode(tokens[0][len(input_ids[0]):], skip_special_tokens=True)
print("USER:\n" + req)
print("ASSISTANT:\n" + out)
print()
print()
実行結果
USER:
「馬が合う」はどう言う意味ですか
ASSISTANT:
「馬が合う」は、性情や考え方が似ている、または気が合う、という意味です。
「馬が合わない」は、性情や考え方が違う、または気が合わない、という意味です。
「馬が合う」「馬が合わない」は、友情、恋愛、仕事など、さまざまな人間関係を説明する時に使われる言葉です。例えば、「私と彼は馬が合うので、仲良し友達です」という使い方ができます。
USER:
How to make an authentic Spanish Omelette?
ASSISTANT:
1 egg for each person, plus one extra, shallots, butter, salt and pepper, small new potatoes, olive oil
2 cloves of garlic, peeled
100g of tin of tunaFry chopped shallot in a mixture of oil and butter, add a little salt and pepper, mix and cook 10 minutes on low heat, stirring often. Add small new potatoes and chopped garlic. Increase to high heat and shake pan once in a while. Fry 10 minutes.
Beat the eggs in a bowl, add some salt and pepper, stir a bit, pour the mix over frying potatoes and mix. Cook for 2 minutes on each side. Serve warm. Open up like a pancake and place tuna on top.
概ね正しいと思います。
さらに別の質問をしてみました。赤字はハルシネーションと思われる部分です。
USER:
三木谷浩史さんは誰ですか
ASSISTANT:
三木谷浩史(みきたに ひろし、英: Hiroshi Mikitani、1965年9月18日 - )は、日本の実業家。楽天株式会社代表取締役会長兼社長の傍ら、楽天グループ各社代表取締役社長も兼任する。父親は三木谷和洋(元大和銀行常務取締役)、母親は三木谷栄(元日本赤十字社副社長)。実弟は三木谷高明(楽天技術研究所所長)。 東京都生まれ。麻布高校を経て、1988年一橋大学経済学部卒業後、ボストン・コンサルティング・グループに入社。1995年に楽天株式会社を設立し、代表取締役社長に就任。2000年にはナスダックを通じて楽天の株式を公開、アメリカやイスラエルに楽天のソフトウェア開発拠点を構え、日本国内外を問わずIT企業の人材採用や海外企業の買収、提携を行うことで楽天の成長を続けた。社長退任後は会長に就任し、2019年3月楽天の株価を1000円から10000円に向けて「中期経営計画」を策定、2020年度までに日本だけでなく、世界を代表するIT企業に育てることをビジョンに掲げている。内閣府の「女性が輝く社会つくり会議」有識者委員、外務省国際情勢審議会委員をも務める。
USER:
Who is Mikitani Hiroshi?
ASSISTANT:
Mikitani Hiroshi is the Founder and CEO of Rakuten, Inc. He is a Japanese entrepreneur and businessman who has been instrumental in the growth and success of Rakuten, one of the world's leading internet service companies.
Mikitani was born on April 10, 1965, in Saitama Prefecture, Japan. He attended Shurei High School in Saitama, and then graduated from Tufts University in Medford, Massachusetts, with a degree in economics.
After graduating from college, Mikitani worked at Merrill Lynch in Tokyo, where he gained valuable experience in the finance industry. In 1996, he left Merrill Lynch to join the online retail startup Rakuten, Inc. at its inception. He became president of the company in 1999, and then CEO and representative director in 2007.
Under Mikitani's leadership, Rakuten has expanded its business to a wide range of internet services, including e-commerce, digital content, and financial services, making it one of the most successful and widely recognized companies in Japan. Rakuten's e-commerce platform, Rakuten Ichiba, is one of the largest online marketplaces in the world, with millions of products and thousands of sellers.
Mikitani has received a number of awards and accolades for his contributions to the e-commerce industry and the Japanese economy. He is known for his visionary leadership, his commitment to innovation, and his focus on customer satisfaction.
In addition to his work at Rakuten, Mikitani is also involved in a number of philanthropic and social initiatives, including the Rakuten Institute of Technology, which conducts research in areas such as artificial intelligence and machine learning, and the Rakuten Foundation, which supports a wide range of social and cultural activities.
モデルに様々な質問を投げかけてみると、日本語の慣用句「馬が合う」の意味を的確に説明し、英語でのスペイン風オムレツの作り方も詳しく回答してくれました。また、楽天の創業者である三木谷浩史氏についても、ある程度正しいプロフィールを提示してくれました。今後の技術進歩が楽しみです。