MATLAB ユーザーコミュニティー

MATLAB & Simulink ユーザーコミュニティー向け日本語ブログ

DeepSeek モデルをローカルで動かし MATLAB と連携する方法

※この投稿は 2025 年 2 月 4 日に The MATLAB Blog へ 投稿されたものの抄訳です。

DeepSeek-R1 が利用可能になったのとほぼ同時に、DeepSeek-R1 を MATLAB から使用できるかの問い合わせをもらうようになりました。先週の終わりに、MathWorks のソフトウェアテストエンジニアである Vasileios Papanastasiou が LinkedInにその方法を投稿していたので自分のマシンでさっそく試してみました。

ローカルマシンでdeepseek-r1:1.5bを実行する

Large Language Models (LLMS) with MATLAB」アドオンと ollama を使用して、ローカルマシンで小さな deepseek モデルの 1 つを実行し、MATLAB から対話してみます。Vasileios の指示に従って、最初に行ったのは
Ollama のダウンロード&インストール: https://ollama.com/download
Windows マシンで行いました。インストールが完了した後、オペレーティングシステムのコマンドラインを開き下記のコマンドを実行しました。
ollama run deepseek-r1:1.5b
このコマンドにより、15億パラメータのモデルがインストールされます。比較的小さなモデルなので、計算リソース面での制約を心配する必要はなく安心です。大きなモデルはまた機会があれば試すことにします。
さて、次は MATLAB での作業です。Vasileios は GitHub から「Large Language Models (LLMS) with MATLAB」アドオンを取得する方法を記載していましたが、ここでは別の方法を選んでみます。MATLAB R2024b の “環境タブ” でアドオンをクリックします。
アドオンエクスプローラーから「Large Language Models」を検索し、見つけたら「追加」をクリック。これでダウンロードとインストールが完了です。
これでインストールは完了です。さっそく MATLAB で使ってみましょう。まず、ollamaChat オブジェクトを作成します。
chat = ollamaChat(“deepseek-r1:1.5b”)
chat =
ollamaChat with properties:
ModelName: “deepseek-r1:1.5b”
Endpoint: “127.0.0.1:11434”
TopK: Inf
MinP: 0
TailFreeSamplingZ: 1
Temperature: 1
TopP: 1
StopSequences: [0×0 string]
TimeOut: 120
SystemPrompt: []
ResponseFormat: “text”
これで準備完了です。この AI と対話してみましょう。
txt = generate(chat,“What is the speed of light?”)
txt =
“<think>
</think>
The exact value of the speed of light in a vacuum is defined as 299,792,458 meters per second.
This precise definition ensures consistency and accuracy across all scientific measurements and calculations.”
このような LLM モデルの面白いところは、同じ質問を何度も繰り返しても、毎回異なる答えが得られることです。これは、モデルの確率的な性質を反映しています。時には結果がほんの少しだけ異なることもあります。
txt = generate(chat,“What is the speed of light?”)
txt =
“<think>
</think>
The speed of light in a vacuum is approximately 299,792 kilometers (186,282 statute miles) per second.
Light is the fastest thing in the universe with its universal speed limit.”
また場合によっては非常に冗長な回答を返し、多くの「思考」を含んだ答えになることもあります。
txt = generate(chat,“What is the speed of light?”)
txt =
“<think>
Okay, so I’m trying to figure out what the speed of light is. I’ve heard it’s something really important in physics,
especially with relativity and electromagnetism.
Let me see… I remember that it’s called c, but exactly how much is it?
First, I think about units. The speed should be in meters per second because [there’s a big unit for that out there. ‘ …
Maybe like 3 times something—maybe 299 million something? Oh, yeah, the original value was 299,792,458 meters per second.
That seems familiar. Wait, isn’t that what it is now?
But I should check if this number makes sense. Why is it so high compared to the speed of trains or planes?
Because light is such a fast thing, traveling through space at around 300 million meters each second
—it’s way faster than anything else on Earth.
I also recall units in different systems. [It’s not just SI, am I right? Maybe another one.
Wait, in cgs units, which are centimeters and grams, the speed would probably be something times a billion or so cm per second.
But that seems less relevant now.
Now, how was this value first determined? I think it came out of [Maxwell’s equations when considering the speed at which
electric and magnetic fields propagate through space without any medium—so in a vacuum.
That must have been quite a theoretical push by scientists.
Einstein later connected this to special relativity when he needed a way for electrons to accelerate without contradictions.
In everyday terms, c tells us how quickly signals like light or radio waves can move across the universe.
Without it being so fast, life would be very different, especially in astronomy where such vast distances are covered quickly.
It’s like something almost instantaneous but still moving at a significant pace due to its high value.
But wait, is there any way it could change? Is it constant or does light slow down in some circumstances?
I haven’t heard of the speed of light changing so far.
Maybe in extreme conditions, like near superconductors or high temperatures, materials might influence [vacuum’]s properties,
affecting how light travels through them.
But most physicists today would say c is a fundamental, unchanging constant.
I also remember that special relativity deals with how different observers measure time and space when they move relative to each other.
Light speed being invariant means all observers agree on its value regardless of their motion relative to the light,
which helps unify space and time into spacetime.
So putting it all together: c is 299,792,458 meters per second precisely—I should check if that’s accurate.
Maybe I’ve heard it rounded up or kept more decimal places.
Oh yeah, sometimes calculations round it to about 300 million m/s for simplicity, but the correct value has all those digits.
I think c is crucial in so many areas like time dilation and the structure of space-time from general relativity.
It’s the cornerstone we use to solve problems in physics whenever a high-speed scenario comes into play without any medium
to slow things down. Without it being that fast, it wouldn’t be as impactful or as something we can use in equations.
So just recapitulating: The speed of light is approximately three times 10^8 meters per second but precisely calculated to around
299,792,458 m/s. That’s why things moving at that speed sound so rapid compared to everyday experiences.
It’s a constant that underpins the fabric of spacetime and has far-reaching implications in both theoretical physics and applied fields.
</think>
The speed of light is approximately **299,792,458 meters per second**, symbolized by the letter c.
This is a fundamental constant in physics, unchanging at 299,792,458 m/s exactly today.
The unit “m·s−¹” indicates meters per second.
The value of c was determined theoretically as electromagnetic waves travel through a vacuum, where electric and
magnetic fields propagate instantaneously without needing any medium.
It’s crucial in special relativity because it serves as an invariant, meaning all observers agree on its speed
irrespective of their relative motion. In high-speed scenarios like astrophysics, light travels across vast distances
nearly instantaneously due to c’s enormous value.
In practical terms, the speed of light determines how quickly signals move across vast scales, such as in communication
and astronomy. It also plays a key role in spacetime’s theory, particularly in special relativity.
The precise value is derived through detailed calculations from [Maxwell’s equations, which
describe electric and magnetic fields. Without c being this high, time dilation and relativistic effects
would be negligible compared to the universe’]s movement relative to light speed.
In summary, the speed of light remains a constant, significantly impacting various areas of physics and our
understanding of the universe.”
長い!
これは多くの人が「AI slop」と呼ぶものの一例だと思います。しかしどの回答でもモデルは光の速度が299,792,458 m/s であると確信しているようで、これは Wikipedia によれば正しいです。

今回試したものは DeepSeek モデルの中でも非常に小さなモデルですが、それでも役に立つことができそうですし、LLM ベースの AI 技術の強みと弱みを学びに繋がりそうです。

ぜひ試してみて、感想を教えてください。

|
  • print

コメント

コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。

Loading...
Go to top of page