Winter is a time of magic π§ββοΈ. Everyone is waiting for something special at this time, and Data Scientists arenβt different. It is not in the power of software developer to be a magician, but I can help you deploy your models with literally a single command right from your Jupyter notebook (and basically from any place like your command line or Python script).
Sounds like magic? It is! π«
To get some winter season vibes, letβs do some magic ourselves first. Letβs do something that will help us prepare some fun for our friends for the weekends.
To do so, weβll create a model that translates lyrics to emojis. With all due respect to recent advances in NLP and LLM algorithms, itβs still both easier and more fun to convince your friends to do the backward translation:
Ok, Iβm sure humans are up to the challenge!
Alright, just before we get into the actual coding, everything described in this blog post is available on this Google Colab notebook. Now, let's get to it!
First, letβs load an emoji dataset. We need something to base our model on, right?
The secret sauce to creating our emoji language is using a pretrained Distilbert model to tokenize and create embeddings which represent our emoji dictionary:
We can now similarly embed any word and replace it with its βclosestβ emoji embedding to create our textβemoji translator. Using that, βJingle bellsβ should become something like βππβ:
Good start - it guessed half of the emojis correctly!
Our part of magic is done, now to the single command deployment I promised in the beginning. Before we go rogue and deploy it to the cloud, letβs run a Streamlit app locally to test things out:
What happened here? That innocent looking mlem.api.save
method inspected the model object to find all python packages to install did the magic of preparing the model to be used! πͺβ¨
Now you should have a Streamlit app at localhost:80
that looks just like this:
Once we finished playing around with the model locally, letβs cast our final spell for the day π§ββοΈ and deploy the model to fly.io:
Some elvish gibberish is printed to the command line, and you get a deployment up and ready.
Now, before you go, remember that these powers extends to serving models as REST API applications, Streamlit apps, building Docker Images and Python packages, and deploying them to Heroku, Flyio, Kubernetes, and AWS Sagemaker.
Or just go here to get a crash course :)
Top comments (2)
Here are some translations. Check you intuition - are you getting what the neural networks are trying to say to you? Just remember, they aren't cherry-picked, just magical π¦
Song 1
1οΈβ£ππ«, 1οΈβ£ππ« π·
One way ticket, one way ticket to the blues
(Eruption, "One Way Ticket")
Song 2
β¬οΈπ¨οΈ1οΈβ£πππ·
Dashing through the snow, In a one-horse open sleigh
("Jingle Bells")
Song 3
π ββπ₯, ππ
π₯π€π, ππΊοΈ & ππΉ
No more champagne,
And the fireworks are through
Here we are, me and you,
Feeling lost and feeling blue
(ABBA, "Happy New Year")
Song 4
π€ π π² π’, πΉ πββοΈ
π€ π π« πΈ, π€ & π
& π€ π π€ -β π π
I see trees of green
Red roses too
I see them bloom
For me and for you
And I think to myself
What a wonderful world
(Louis Armstrong, "What A Wonderful World")
P.S. Submit wizardry bugs and feature requests to GH:
github.com/iterative/mlem/issues.