claude.aiで動画を生成する方法

AI

デモ動画


こちらの記事もおすすめ

Claudeを使用してなんJのスレを作成してみた
最近話題のAIチャットボット「Claude」を使って、なんJ風の架空のスレッドを自動生成してみました。Claudeの高度な言語理解と文脈把握能力により、各キャラクターの口調や性格を見事に再現できていると思います。のんのんびよりのキャラクター...
Anthropicとは
AI 安全性研究のフロンティアAnthropic は、AI 技術の発展と社会実装において重要な役割を担う、サンフランシスコに本拠を置く AI 安全性と研究開発の会社です。同社は、AI がもたらす可能性を最大限に引き出しつつ、その安全性と信頼...

コードの生成

claude.ai に mainmベースでコードを生成してもらいます。

Claude
Talk with Claude, an AI assistant from Anthropic

imagine the point of view of a neuron in a really large neural net. think about what the neuron sees and feels. write manim code to animate what is seen and felt from the point of view of a neuron


from manim import *
import random

class NeuronPOV(Scene):
    def construct(self):
        # Create a neuron
        neuron = Circle(radius=0.5, color=BLUE, fill_opacity=1)
        self.play(Create(neuron))
        self.wait()

        # Incoming signals
        num_signals = 10
        signals = VGroup(*[Arrow(start=np.array([0,0,0]), end=np.array([0,0,0]), color=YELLOW) for _ in range(num_signals)])
        signals.arrange_in_grid(rows=2, buff=0.2)
        signals.next_to(neuron, LEFT)

        self.play(Create(signals))
        self.play(*[a.animate.next_to(neuron, LEFT*0.01) for a in signals], run_time=2)
        self.wait()

        # Neuron activation
        self.play(neuron.animate.set_fill(RED))
        self.play(Flash(neuron, color=WHITE, line_length=0.3, num_lines=12))
        self.wait()

        # Outgoing signal
        outgoing_signal = Arrow(start=neuron.get_right(), end=neuron.get_right()+RIGHT*2, color=GREEN)
        self.play(Create(outgoing_signal))
        self.wait()

        # Surrounding activity
        num_surrounding = 30
        surrounding_neurons = VGroup(*[Circle(radius=0.2, color=BLUE, fill_opacity=1) for _ in range(num_surrounding)])
        surrounding_neurons.arrange_in_grid(rows=5, buff=0.5)
        surrounding_neurons.shift(UP*2 + RIGHT*2)

        self.play(Create(surrounding_neurons))
        self.play(LaggedStart(*[Flash(n, color=random_bright_color(), line_length=0.2, num_lines=8) for n in surrounding_neurons], lag_ratio=0.05))
        self.wait()

        # Connection to neighbors
        num_neighbors = 4
        neighbors = VGroup(*random.sample(list(surrounding_neurons), num_neighbors))
        neighbor_connections = VGroup(*[Line(neuron.get_center(), n.get_center(), color=YELLOW) for n in neighbors])

        self.play(Create(neighbor_connections), *[n.animate.set_fill(color=YELLOW) for n in neighbors])
        self.play(*[Flash(n, color=YELLOW, line_length=0.3, num_lines=12) for n in neighbors])
        self.wait()

        # Fade out
        self.play(FadeOut(neighbor_connections), FadeOut(neighbors))
        self.play(*[FadeOut(mob) for mob in self.mobjects])

if __name__ == "__main__":
    scene = NeuronPOV()
    scene.render(output_file="neuron_pov.mp4")

次に、これをGoogleColabで動かします。

必要な依存関係のインストール

スクリプトを実行する前に、必要な依存関係をインストールする必要があります。以下のコマンドを使用して、Ubuntu/Mint/Debianでこれらの依存関係をインストールできます。


!apt update
!apt install build-essential python3-dev libcairo2-dev libpango1.0-dev ffmpeg

次に、pipを使用してManimをインストールします。


!pip install manim

アニメーションの作成

ニューロンの作成

最初のステップでは、Circleオブジェクトを使用してニューロンを作成します。


neuron = Circle(radius=0.5, color=BLUE, fill_opacity=1)
self.play(Create(neuron))

入力シグナルの作成

次に、Arrowオブジェクトを使用して入力シグナルを作成し、ニューロンの左側に配置します。


num_signals = 10
signals = VGroup(*[Arrow(start=np.array([0,0,0]), end=np.array([0,0,0]), color=YELLOW) for _ in range(num_signals)])
signals.arrange_in_grid(rows=2, buff=0.2)
signals.next_to(neuron, LEFT)

self.play(Create(signals))
self.play(*[a.animate.next_to(neuron, LEFT*0.01) for a in signals], run_time=2)

ニューロンの活性化

ニューロンの色を赤に変更し、Flashアニメーションを使用して活性化を表現します。


self.play(neuron.animate.set_fill(RED))
self.play(Flash(neuron, color=WHITE, line_length=0.3, num_lines=12))

出力シグナルの作成

Arrowオブジェクトを使用して、ニューロンから出力シグナルを作成します。


outgoing_signal = Arrow(start=neuron.get_right(), end=neuron.get_right()+RIGHT*2, color=GREEN)
self.play(Create(outgoing_signal))

周囲のニューロンの活動

周囲のニューロンを作成し、ランダムな色でフラッシュさせて活動を表現します。


num_surrounding = 30
surrounding_neurons = VGroup(*[Circle(radius=0.2, color=BLUE, fill_opacity=1) for _ in range(num_surrounding)])
surrounding_neurons.arrange_in_grid(rows=5, buff=0.5)
surrounding_neurons.shift(UP*2 + RIGHT*2)

self.play(Create(surrounding_neurons))
self.play(LaggedStart(*[Flash(n, color=random_bright_color(), line_length=0.2, num_lines=8) for n in surrounding_neurons], lag_ratio=0.05))

近隣ニューロンへの接続

Lineオブジェクトを使用して、ニューロンと近隣のニューロンの間の接続を作成します。


num_neighbors = 4
neighbors = VGroup(*random.sample(list(surrounding_neurons), num_neighbors))
neighbor_connections = VGroup(*[Line(neuron.get_center(), n.get_center(), color=YELLOW) for n in neighbors])

self.play(Create(neighbor_connections), *[n.animate.set_fill(color=YELLOW) for n in neighbors])
self.play(*[Flash(n, color=YELLOW, line_length=0.3, num_lines=12) for n in neighbors])

フェードアウト

最後に、FadeOutアニメーションを使用して、すべてのオブジェクトをフェードアウトさせます。


self.play(FadeOut(neighbor_connections), FadeOut(neighbors))
self.play(*[FadeOut(mob) for mob in self.mobjects])

アニメーションのレンダリング

manimコマンドを使用して、アニメーションをレンダリングし、mp4ファイルとして保存します。


!manim -pqh main.py NeuronPOV
  • -pフラグは、レンダリング後にアニメーションを再生します。
  • -qhフラグは、高品質でレンダリングします。
  • main.pyは、Pythonスクリプトのファイル名です。
  • NeuronPOVは、レンダリングするシーンの名前です。

file

以上が、claude.aiで動画を生成する方法の解説です。このスクリプトは、ニューロンの視点からニューラルネットワークの活動を可視化し、Manimライブラリを使用してアニメーション化します。コードを実行すると、ニューロンの活性化、入力および出力シグナル、周囲のニューロンの活動、および近隣のニューロンへの接続が表示されます。

ノートブック

Google Colaboratory

リポジトリ

GitHub - Sunwood-ai-labs/claude3-video
Contribute to Sunwood-ai-labs/claude3-video development by creating an account on GitHub.

コメント

タイトルとURLをコピーしました