【Qwen 2.5】アリババ最新AIモデルの全貌!オープンソースLLMの実力と具体的な使い方を徹底解説

Qwen-2.5 アリババ 最新AIモデル オープンソースLLM 実力 具体的な使い方

2024年9月、アリババクラウドからQwen2.5という大規模言語モデル(LLM)がリリースされました。

なんとQwen2.5は13個のモデルを同時リリースしており、非常に多くの注目を集めています。

Qwen2.5は、多様なタスクに対応する設計となっており、特に、コーディング関連の性能や数学推論力が大きく向上しています。

また、商用利用が可能なオープンソースのライセンスで、29以上の言語に対応する多言語処理能力も大きな特徴です。

最後まで読むことで、使い方や特徴、活用方法まで知ることができます!ぜひ最後までご覧ください。

目次

Qwen2.5の概要

Qwen2.5はアリババ社の子会社、アリババクラウドが発表した大規模言語モデル(LLM)で、

リリースされたモデルは以下です。

  • Qwen2.5:0.5B、1.5B、3B、7B、14B、32B、72B
  • Qwen2.5-Coder:1.5B、7B、32B がリリース予定
  • Qwen2.5-Math:1.5B、7B、および 72B
参考:https://qwenlm.github.io/blog/qwen2.5/

Qwen2.5は、Qwen2と比較して、最大18兆トークンという、従来より多い大規模なデータセットでトレーニングされています。その結果、Qwen2.5は、Qwen2よりも大幅に多くの知識を獲得し、コーディング、数学、指示の理解、長いテキストの生成、構造化データの理解、構造化出力の生成など、様々な能力が大幅に向上しています。

多様なシステムプロンプトに対しても柔軟に対応できるようになり、チャットボットでのロールプレイ実装や条件設定が強化されていました。

さらに、Qwen2.5は、英語や中国語だけでなく日本語やフランス語など29言語をサポートしています。これにより、グローバルな用途にも適応できる点が評価されています。

Qwen2.5の特徴

Qwen2.5は膨大なデータセットでトレーニングされており、上記に挙げたさまざまなサイズの大規模言語モデルです。

コーディングに特化したcoder、数学に特化したmathなどの専門モデルも含まれます。

Qwen2.5-Coderは、コーディング関連のデータのみでトレーニングされており、デバッグやコーディング関連の質問への回答、コードの提案などのコーディングタスクに優れています。その性能は、パラメータ数がはるかに多いLLMよりも優れており、個人用コーディングアシスタントとして最適です。

参考:https://qwenlm.github.io/blog/qwen2.5/

今回リリースされたQwen2.5-CoderQwen1.5-Coderを比較すると、コーディングアプリケーション向けに設計されていることがわかります。

5.5兆トークンのコード関連データでトレーニングされているため、Qwen2.5-Coderの1.5Bなどの小規模なコーディング特化モデルでも、コーディング評価ベンチマークにおいて、大規模な言語モデルと比較しても競争力のあるパフォーマンスを発揮することができます。

また、具体的な数値での比較は提示されていませんが、Qwen2.5-Coderは、サイズが小さいにもかかわらず、より大きな言語モデルよりも優れたコーディング能力を示し、幅広いプログラミング言語とタスクにおいてそれらを凌駕するとされています。

参考:https://qwenlm.github.io/blog/qwen2.5/

Qwen2.5-Mathは、数学関連のデータでトレーニングされており、思考の連鎖(CoT)、思考のプログラム(PoT)、ツール統合推論(TIR)などのさまざまな推論方法をサポートしています。その性能は、Qwen2-MathやGPT4-oを上回り、小規模な専門モデルであるQwen2.5-Math-1.5B-Instructでも、大規模なLLMに対して非常に競争力のある性能を実現しています。

参考:https://qwenlm.github.io/blog/qwen2.5/

さまざまな言語に対応したQwen2.5

Qwen2.5は多言語対応であり、中国語、英語、フランス語、スペイン語、ポルトガル語、ドイツ語、イタリア語、ロシア語、日本語、韓国語、ベトナム語、タイ語、アラビア語など、29以上の言語をサポート

また、長文テキストの生成にも長けており、Qwen2.5は、最大8Kトークンの長いテキストを生成できます。これは、記事の作成やストーリーの執筆などのタスクに役立ちます。

従来のAIモデルとの比較

Qwen2.5の数学特化モデルであるQwen2.5-Mathは、GPT4-oの数学能力を上回るパフォーマンスを示しています。これは、Qwen2.5-Mathが大規模な数学関連データでトレーニングされ、思考の連鎖(CoT)、思考のプログラム(PoT)、ツール統合推論(TIR)など、様々な推論方法を組み込んでいるためと考えられます。

また、Qwen2.5のAPIベースモデルであるQwen-Turboは、オープンソースモデルと比較して非常に競争力のあるパフォーマンスを提供しながら、費用対効果が高く、高速なサービスを提供

Qwen2.5は、一部のモデルを除いてApache 2.0ライセンスでオープンソース化されています。このため、研究者や開発者はQwen2.5のモデルやコードに自由にアクセスし、利用、改変、配布することができます。一方、GPT4-oはクローズドソースのモデルであるため、その内部構造やトレーニングデータに関する情報は公開されていません。

Qwen2.5のライセンス

Qwen2.5のライセンスはApache license2.0です。そのため、基本的には商用利用や私的利用などが可能です。

配布も可能ですが、配布する場合には、ライセンスのコピーを同封すること、変更を加えた場合は、変更したことを明記すること、元の著作権表示、特許表示、商標表示を保持することが義務付けられています。

注意点として、72BモデルはQwenライセンスなので、ユーザー数が1億以下なら商用利用可能です。3Bモデルは商用利用不可であり、アリババに問い合わせてライセンスを取得する必要があります。

利用用途可否
商用利用⭕️
改変⭕️
配布⭕️
特許使用⭕️
私的使用⭕️
参考:https://huggingface.co/Qwen/Qwen2.5-14B-Instruct/blob/main/LICENSE

なお、視覚言語モデルを使って画像からテキスト変換ができるQwen 2-VIについて詳しく知りたい方は、下記の記事を合わせてご確認ください。

WEEL
【Qwen2-Vl】Alibaba Cloudの視覚言語モデルを使って超有名漫画の1コマ解析してみた! | WEEL Qwen2-VLは、アリババクラウドが発表した最新の視覚言語モデルであり、優れた視覚理解能力を持っています。 このモデルは、動画や画像の内容を深く理解し、質疑応答や推論...

Qwen2.5の使い方

Qwen2.5はローカルで実装可能ですし、難しい場合にはDemoが用意されているのでDemoを使ってQwen2.5を体験することもできます。

参考:https://huggingface.co/spaces/Qwen/Qwen2.5

Qwen2.5をgoogle colaboratoryで使う方法

Qwen2.5はgoogle colaboratoryで使うことができます。

14BまでのモデルであればL4GPUで使うことができますが、生成するトークン数に左右される部分もありますので、A100GPUを使うといいでしょう。

■PythonのバージョンPython 3.11以上

■使用ディスク量68.5GB

■システムRAMの使用量 3.6GB

■GPURAMの使用量 20.1GB

また、google colaboratoryで動かす際には、Hugging Faceのトークンが必要なので、まだ取得していない方はHugging Faceのトークンを取得しておきましょう。

実際にgoogle colaboratoryで動かすサンプルコードはこちらです。

必要ライブラリのインストールはこちら
!pip install transformers torch accelerate --upgrade

これだけだと以下のエラーが出ると思うので、バージョンを指定して再インストールします。

ライブラリインストール時のエラー内容はこちら

!pip install transformers torch accelerate --upgrade
Requirement already satisfied: transformers in /usr/local/lib/python3.10/dist-packages (4.44.2)
Requirement already satisfied: torch in /usr/local/lib/python3.10/dist-packages (2.4.0+cu121)
Collecting torch
  Downloading torch-2.4.1-cp310-cp310-manylinux1_x86_64.whl.metadata (26 kB)
Requirement already satisfied: accelerate in /usr/local/lib/python3.10/dist-packages (0.34.2)
Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers) (3.16.0)
Requirement already satisfied: huggingface-hub<1.0,>=0.23.2 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.24.7)
Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from transformers) (1.26.4)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from transformers) (24.1)
Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (6.0.2)
Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers) (2024.9.11)
Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers) (2.32.3)
Requirement already satisfied: safetensors>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.4.5)
Requirement already satisfied: tokenizers<0.20,>=0.19 in /usr/local/lib/python3.10/dist-packages (from transformers) (0.19.1)
Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.10/dist-packages (from transformers) (4.66.5)
Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.10/dist-packages (from torch) (4.12.2)
Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch) (1.13.2)
Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch) (3.3)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch) (3.1.4)
Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch) (2024.6.1)
Collecting nvidia-cuda-nvrtc-cu12==12.1.105 (from torch)
  Downloading nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cuda-runtime-cu12==12.1.105 (from torch)
  Downloading nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cuda-cupti-cu12==12.1.105 (from torch)
  Downloading nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cudnn-cu12==9.1.0.70 (from torch)
  Downloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cublas-cu12==12.1.3.1 (from torch)
  Downloading nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cufft-cu12==11.0.2.54 (from torch)
  Downloading nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-curand-cu12==10.3.2.106 (from torch)
  Downloading nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl.metadata (1.5 kB)
Collecting nvidia-cusolver-cu12==11.4.5.107 (from torch)
  Downloading nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-cusparse-cu12==12.1.0.106 (from torch)
  Downloading nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl.metadata (1.6 kB)
Collecting nvidia-nccl-cu12==2.20.5 (from torch)
  Downloading nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl.metadata (1.8 kB)
Collecting nvidia-nvtx-cu12==12.1.105 (from torch)
  Downloading nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl.metadata (1.7 kB)
Collecting triton==3.0.0 (from torch)
  Downloading triton-3.0.0-1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.metadata (1.3 kB)
Collecting nvidia-nvjitlink-cu12 (from nvidia-cusolver-cu12==11.4.5.107->torch)
  Downloading nvidia_nvjitlink_cu12-12.6.68-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)
Requirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from accelerate) (5.9.5)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch) (2.1.5)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (2.0.7)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->transformers) (2024.8.30)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy->torch) (1.3.0)
Downloading torch-2.4.1-cp310-cp310-manylinux1_x86_64.whl (797.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 797.1/797.1 MB 1.9 MB/s eta 0:00:00
Downloading nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 410.6/410.6 MB 2.6 MB/s eta 0:00:00
Downloading nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.1/14.1 MB 95.6 MB/s eta 0:00:00
Downloading nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 23.7/23.7 MB 91.0 MB/s eta 0:00:00
Downloading nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 823.6/823.6 kB 49.8 MB/s eta 0:00:00
Downloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 664.8/664.8 MB 2.1 MB/s eta 0:00:00
Downloading nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl (121.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 121.6/121.6 MB 18.5 MB/s eta 0:00:00
Downloading nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl (56.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 56.5/56.5 MB 37.6 MB/s eta 0:00:00
Downloading nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl (124.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 124.2/124.2 MB 7.0 MB/s eta 0:00:00
Downloading nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl (196.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 196.0/196.0 MB 5.0 MB/s eta 0:00:00
Downloading nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl (176.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 176.2/176.2 MB 5.1 MB/s eta 0:00:00
Downloading nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (99 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 99.1/99.1 kB 8.3 MB/s eta 0:00:00
Downloading triton-3.0.0-1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (209.4 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 209.4/209.4 MB 4.4 MB/s eta 0:00:00
Downloading nvidia_nvjitlink_cu12-12.6.68-py3-none-manylinux2014_x86_64.whl (19.7 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 19.7/19.7 MB 85.4 MB/s eta 0:00:00
Installing collected packages: triton, nvidia-nvtx-cu12, nvidia-nvjitlink-cu12, nvidia-nccl-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, nvidia-cusparse-cu12, nvidia-cudnn-cu12, nvidia-cusolver-cu12, torch
  Attempting uninstall: nvidia-nccl-cu12
    Found existing installation: nvidia-nccl-cu12 2.23.4
    Uninstalling nvidia-nccl-cu12-2.23.4:
      Successfully uninstalled nvidia-nccl-cu12-2.23.4
  Attempting uninstall: torch
    Found existing installation: torch 2.4.0+cu121
    Uninstalling torch-2.4.0+cu121:
      Successfully uninstalled torch-2.4.0+cu121
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchaudio 2.4.0+cu121 requires torch==2.4.0, but you have torch 2.4.1 which is incompatible.
torchvision 0.19.0+cu121 requires torch==2.4.0, but you have torch 2.4.1 which is incompatible.
バージョン指定してのライブラリインストールはこちら
!pip install torch==2.4.0 torchvision==0.19.0+cu121 torchaudio==2.4.0+cu121 --extra-index-url https://download.pytorch.org/whl/cu121
Hugging Faceのログインはこちら
from huggingface_hub import login

login(token="Yout_token")
サンプルコードはこちら
from transformers import AutoModelForCausalLM, AutoTokenizer

# モデルの名前を設定
model_name = "Qwen/Qwen2.5-14B-Instruct"

# モデルとトークナイザーをロード
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",  # 自動で適切なデータ型を選択
    device_map="auto"    # 自動でデバイス(GPU/CPU)を選択
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# モデルに渡すプロンプトを設定
prompt = "Give me a short introduction to large language models."

# メッセージのテンプレートを設定
messages = [
    {"role": "system", "content": "You are Qwen, created by Alibaba Cloud."},
    {"role": "user", "content": prompt}
]

# トークナイザーを使用してテキストを処理
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)

# モデルに入力するためのテンソルに変換
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# モデルを使用してテキストを生成
generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=128  # 最大生成トークン数
)

# 生成されたトークンをデコードしてテキストに変換
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(generated_text)

サンプルを動かしたときは、トークン数を128にしています。128でもアウトプットされるまで5分以上かかったので、トークン数を512とかにすると、もっと時間がかかるかもしれません。

あとはGPUの性能によってもアウトプットまでの時間は変わります。A100を使用すると20秒程度で出力されます。

Qwen2.5の性能をそれぞれ検証してみた

Qwen2.5にはLLM、math、Coderの三種類が用意されています。そこで、それぞれの性能を検証してみたいと思います。

基本的にはQwen2.5を使う場合、前述したサンプルコードとモデルのダウンロードまでは一緒です。

ダウンロードするモデル名を変更すれば、それぞれのモデルを使うことができます。

Qwen2.5-LLMを使ったサンプルコードはこちら
from transformers import AutoModelForCausalLM, AutoTokenizer

# モデルの名前を設定
model_name = "Qwen/Qwen2.5-14B-Instruct"

# モデルとトークナイザーをロード
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",  # 自動で適切なデータ型を選択
    device_map="auto"    # 自動でデバイス(GPU/CPU)を選択
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
from transformers import AutoModelForCausalLM, AutoTokenizer

# モデルの名前を設定
model_name = "Qwen/Qwen2.5-14B-Instruct"

# モデルとトークナイザーをロード
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",  # 自動で適切なデータ型を選択
    device_map="auto"    # 自動でデバイス(GPU/CPU)を選択
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# モデルに渡すプロンプトを設定
prompt = """以下のメッセージを適切な文章に修正してください
よう!くそパイセン!
昨日の飲み会のせいで2日酔い酷くて朝から死ぬほど頭痛いんで、会社休むわー

今日の俺の業務も代わりにやっといてー
あ、あと明日は会社行けたら行く

よろー
"""
# メッセージのテンプレートを設定
messages = [
    {"role": "system", "content": "You are Qwen, created by Alibaba Cloud."},
    {"role": "user", "content": prompt}
]

# トークナイザーを使用してテキストを処理
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)

# モデルに入力するためのテンソルに変換
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

# モデルを使用してテキストを生成
generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=512  # 最大生成トークン数
)

# 生成されたトークンをデコードしてテキストに変換
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(generated_text)
結果はこちら
system
You are Qwen, created by Alibaba Cloud.
user
以下のメッセージを適切な文章に修正してください
よう!くそパイセン!
昨日の飲み会のせいで2日酔い酷くて朝から死ぬほど頭痛いんで、会社休むわー

今日の俺の業務も代わりにやっといてー
あ、あと明日は会社行けたら行く

よろー

assistant
もちろん、より丁寧な表現に修正しますね。

---

お疲れ様です、先輩方!

昨日の飲み会のせいで二日酔いで頭痛がひどく、今日は体調不良で会社をお休みさせていただきます。

本日の私の業務も可能であれば代わりに行っていただけると助かります。

明日は体調が良ければ出勤いたしますので、よろしくお願いします。

よろしくお願いいたします。

---

このように、挨拶や敬語を使って、相手への配慮を表すことで、より適切なコミュニケーションになります。

Qwen2.5-mathは2018年数学オリンピックの問題を解いてもらいます。ただし、数学オリンピックの問題は日本語なので、英語に翻訳してからQwen2.5のプロンプトに入力します。

Qwen2.5-Math mainly supports solving English and Chinese math problems through CoT and TIR. We do not recommend using this series of models for other tasks.
和訳:Qwen2.5-Math は、主に CoT と TIR を通じて英語と中国語の数学の問題を解くことをサポートしています。このシリーズのモデルを他のタスクに使用することはお勧めしません。

解いてもらう問題はこちらです


問題1. 紙に角形 ABC の外接円を描く.点 D, E をそれぞれ辺 AB, AC にとり AD = AE となるようにとる.BD の途中に一等分線との交点 AB の交点を F, CE の途中に一等分線との交点 AC の交点を G とするとき,直線 DE, FG は平行 (または同一の直線) であることを示せ.

英訳:Problem 1. Draw the circumcircle of triangle ABC on paper. Place points D and E on sides AB and AC respectively, such that AD = AE. Let F be the intersection point of the bisector of BD with AB, and G be the intersection point of the bisector of CE with AC. Show that lines DE and FG are parallel (or the same line).

Qwen2.5-mathを使ったサンプルコードはこちら
from transformers import AutoModelForCausalLM, AutoTokenizer

# モデルの名前を設定
model_name = "Qwen/Qwen2.5-Math-7B-Instruct"

# モデルとトークナイザーをロード
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",  # 自動で適切なデータ型を選択
    device_map="auto"    # 自動でデバイス(GPU/CPU)を選択
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# モデルに渡すプロンプトを設定
prompt = """Problem 1. Draw the circumcircle of triangle ABC on paper. Place points D and E on sides AB and AC respectively, such that AD = AE. Let F be the intersection point of the bisector of BD with AB, and G be the intersection point of the bisector of CE with AC. Show that lines DE and FG are parallel (or the same line)."""
# メッセージのテンプレートを設定
messages = [
    {"role": "system", "content": "You are Qwen, created by Alibaba Cloud."},
    {"role": "user", "content": prompt}
]

# トークナイザーを使用してテキストを処理
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)

# モデルに入力するためのテンソルに変換
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# モデルを使用してテキストを生成
generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=512  # 最大生成トークン数
)

# 生成されたトークンをデコードしてテキストに変換
generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(generated_text)
結果はこちら
system
You are Qwen, created by Alibaba Cloud.
user
Problem 1. Draw the circumcircle of triangle ABC on paper. Place points D and E on sides AB and AC respectively, such that AD = AE. Let F be the intersection point of the bisector of BD with AB, and G be the intersection point of the bisector of CE with AC. Show that lines DE and FG are parallel (or the same line).
assistant
To show that lines \(DE\) and \(FG\) are parallel, we will use the properties of angle bisectors and the fact that \(AD = AE\).

1. **Identify the given conditions:**
   - \(AD = AE\), so \(\triangle ADE\) is isosceles with \(AD = AE\).
   - \(F\) is the intersection of the angle bisector of \(\angle BDC\) with \(AB\).
   - \(G\) is the intersection of the angle bisector of \(\angle CEB\) with \(AC\).

2. **Use the Angle Bisector Theorem:**
   - The Angle Bisector Theorem states that the angle bisector of an angle in a triangle divides the opposite side into segments that are proportional to the adjacent sides.
   - For \(\triangle BDC\), the angle bisector of \(\angle BDC\) intersects \(AB\) at \(F\). Therefore, \(\frac{BF}{FA} = \frac{BD}{DC}\).
   - For \(\triangle CEB\), the angle bisector of \(\angle CEB\) intersects \(AC\) at \(G\). Therefore, \(\frac{CG}{GA} = \frac{CE}{EB}\).

3. **Consider the circumcircle of \(\triangle ABC\):**
   - Since \(D\) and \(E\) are on the circumcircle, \(\angle BDC = 180^\circ - \angle BAC\) and \(\angle CEB = 180^\circ - \angle BAC\).
   - This implies that \(\angle BDC = \angle CEB\).

4. **Use the fact that \(AD = AE\):**
   - Since \(AD = AE\), \(\angle ADE = \angle AED\).
   - Therefore, \(\angle BDC = \angle CEB\) implies that \(\angle BDF = \angle CEG\).

5. **Apply the Angle Bisector Theorem again:**
   - Since \(\angle BDF = \angle CEG\), the triangles \(\triangle BDF\) and \(\triangle CEG\) are similar by the Angle-Angle (AA) similarity criterion.
   - This implies that \(\frac{BF}{FA} = \frac{CG}{GA}\).

6. **Conclusion:**
   - Since \(\frac{BF}{FA} = \frac

Qwen2.5-Coderでは、サンプルコードをそのまま実装してみます。

Hugging Faceにサンプルコードが掲載されています

ただそれだけだとうまく動かないので、GitHubを参考に必要ライブラリをインストールする必要があります。

GitHubのリポジトリから必要ライブラリのダウンロードはこちら
!wget https://raw.githubusercontent.com/QwenLM/Qwen2.5-Coder/main/requirements.txt
!pip install -r requirements.txt
Qwen2.5-Coderのサンプルコードはこちら
from transformers import AutoModelForCausalLM, AutoTokenizer

# モデルの名前を設定
model_name = "Qwen/Qwen2.5-Coder-7B-Instruct"

# モデルとトークナイザーをロード
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",  # 自動で適切なデータ型を選択
    device_map="auto"    # 自動でデバイス(GPU/CPU)を選択
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "write a quick sort algorithm."
messages = [
    {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
結果はこちら
Sure! Here's an implementation of the Quick Sort algorithm in Python:

```python
def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    else:
        pivot = arr[len(arr) // 2]
        left = [x for x in arr if x < pivot]
        middle = [x for x in arr if x == pivot]
        right = [x for x in arr if x > pivot]
        return quick_sort(left) + middle + quick_sort(right)

# Example usage:
arr = [3, 6, 8, 10, 1, 2, 1]
sorted_arr = quick_sort(arr)
print(sorted_arr)
```

### Explanation:
1. **Base Case**: If the array has 0 or 1 elements, it is already sorted, so we return it as is.
2. **Pivot Selection**: We choose the pivot element from the array. In this example, we use the middle element of the array.
3. **Partitioning**: We create three sub-arrays:
   - `left`: All elements less than the pivot.
   - `middle`: All elements equal to the pivot.
   - `right`: All elements greater than the pivot.
4. **Recursive Sorting**: We recursively apply the `quick_sort` function to the `left` and `right` sub-arrays.
5. **Concatenation**: Finally, we concatenate the sorted `left` sub-array, the `middle` sub-array, and the sorted `right` sub-array to get the final sorted array.

This implementation is simple and easy to understand, but it may not be the most efficient in terms of space complexity due to the use of additional lists. For an in-place version of Quick Sort, you can modify the algorithm to sort the array directly within the same list.

Qwen2.5はgoogle colaboratoryで実装でき、モデルサイズが多数用意されているの非常に使い勝手がいいです。

google colaboratoryの無料プランではGPUメモリがオーバーしてしまうので、課金する必要はありますが、それでも性能の高いLLMを手軽に使えるのは、今後の活用が非常に楽しみになりますね。

なお、音声だけで状況認識や多言語翻訳ができるアリババ産LLMについて詳しく知りたい方は、下記の記事を合わせてご確認ください。

WEEL
【Qwen-Audio】音声だけで状況認識や多言語翻訳ができるアリババ産LLMを使ってみた | WEEL WEELメディア事業部テックリサーチャーの藤崎です。 いまやChatGPTを始めとする生成AIは、テキストだけでなく画像やオーディオを認識したり生成することができるようになり...

Qwen2.5がもたらす未来の可能性

2024年9月にリリースされたQwen2.5は、アリババクラウドによる大規模言語モデル(LLM)です。

13種のモデルを同時に提供し、特にコーディングや数学の分野で顕著な性能向上を実現しました。多言語対応やオープンソース化により、研究者や開発者にとってもアクセスしやすく、商用利用が可能な点も大きな利点です。

Qwen2.5-Coderによるコードの自動生成やデバッグ支援、コードの最適化提案などができ、Qwen2.5-Mathでは、複雑な問題を解く過程を生徒に分かりやすく説明するツールとして活用できるでしょう。

また、複数言語での文章生成に対応しているため、マーケティング資料やブログ記事、SNS投稿の自動作成に役立てることも可能です。

Qwen2.5はさまざまなタスクにおいて効率化を促進し、今後多くの業界での導入が期待されます。

最後に

いかがだったでしょうか?

弊社では

・マーケティングやエンジニアリングなどの専門知識を学習させたAI社員の開発
・要件定義・業務フロー作成を80%自動化できる自律型AIエージェントの開発
・生成AIとRPAを組み合わせた業務自動化ツールの開発
・社内人事業務を99%自動化できるAIツールの開発
ハルシネーション対策AIツールの開発
自社専用のAIチャットボットの開発

などの開発実績がございます。

まずは、「無料相談」にてご相談を承っておりますので、ご興味がある方はぜひご連絡ください。

➡︎生成AIを使った業務効率化、生成AIツールの開発について相談をしてみる。

生成AIを社内で活用していきたい方へ

「生成AIを社内で活用したい」「生成AIの事業をやっていきたい」という方に向けて、生成AI社内セミナー・勉強会をさせていただいております。

セミナー内容や料金については、ご相談ください。

また、弊社紹介資料もご用意しておりますので、併せてご確認ください。

投稿者

  • URLをコピーしました!
  • URLをコピーしました!
目次