Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Canonical Animations as Objects #27

Open
helblazer811 opened this issue Feb 2, 2023 · 3 comments
Open

Make Canonical Animations as Objects #27

helblazer811 opened this issue Feb 2, 2023 · 3 comments

Comments

@helblazer811
Copy link
Owner

Manim has the ability to represent animations as classes. These classes can take parameters and they can wrap around a passed Mobject (in our case this could be a neural network) and then a mobject specific animation is run. You can override such animations like Create (see neural_network.py). It would be interesting to make a generic TrainModel animation that is implemented by various models and emulates the training procedure.

For now, I could implement these animations as functions in the manim_ml/neural_network/animations directory.

@Arbaaz-Mahmood
Copy link

Here is some code I wrote for a generic model training class in manim:

`from manim import *

class ModelTraining(Scene):
def construct(self):
model_title = TextMobject("Model Training")
self.play(Write(model_title))
self.wait()

    training_data = TextMobject("Training Data")
    self.play(Write(training_data))
    self.wait()

    model_training = TextMobject("Training the Model")
    self.play(Write(model_training))
    self.wait()

    accuracy = TextMobject("Accuracy:")
    accuracy_value = TextMobject("100%")
    accuracy_group = VGroup(accuracy, accuracy_value)
    accuracy_group.arrange(RIGHT)
    accuracy_group.to_edge(UP)
    self.play(Write(accuracy_group))
    self.wait()

    testing_data = TextMobject("Testing Data")
    self.play(Write(testing_data))
    self.wait()

    model_testing = TextMobject("Testing the Model")
    self.play(Write(model_testing))
    self.wait()

    test_accuracy = TextMobject("Test Accuracy:")
    test_accuracy_value = TextMobject("99%")
    test_accuracy_group = VGroup(test_accuracy, test_accuracy_value)
    test_accuracy_group.arrange(RIGHT)
    test_accuracy_group.to_edge(UP)
    self.play(Write(test_accuracy_group))
    self.wait()

`

@Arbaaz-Mahmood
Copy link

Here is an example of a simple transformer model implemented which inherits from this class:
`from manim import *
class TransformerModelScene(ModelTrainingScene):
def init(self, **kwargs):
ModelTrainingScene.init(self, **kwargs)
def setup(self):
self.prepare_data()
self.add_data_points()
self.add_transformer_model()
def prepare_data(self):
# Prepare the data for the Transformer model
pass
def add_transformer_model(self):
# Add the Transformer model to the scene
pass
class TransformerModelTraining(Scene):
def construct(self):
self.add(TransformerModelScene())

`
In this example, TransformerModelScene is a subclass of ModelTrainingScene and inherits all of its methods and attributes. The setup method is overridden to prepare the data for the Transformer model and add the model to the scene.

In the TransformerModelScene class, the prepare_data and add_transformer_model methods need to be implemented to prepare the data for the Transformer model and add the model to the scene, respectively.

Finally, TransformerModelTraining is a scene that adds the TransformerModelScene to the animation.

@helblazer811
Copy link
Owner Author

Interesting ideas! I'm especially excited by the idea of creating more animations like ForwardPass with similar syntax to how the animations are done in the core library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants