Powerful Machine Learning at your fingertips
Mix.install([
{:nx, "~> 0.5.2"},
{:exla, "~> 0.5.2"},
{:bumblebee, "~> 0.3.0"},
# Livebook integration
{:kino_bumblebee, "~> 0.3.0"}
])
Nx.global_default_backend(EXLA.Backend)
What are we looking for?
BigBrain.detect_emotion("The show last night was fantastic!")
#=> "joy"
BigBrain.describe_image("image.jpg")
#=> "a cat sitting on a chair"
BigBrain.transcribe("audio.mp3")
#=> "Hate is yelled, love is felt."
Zooming out
Nx
x = Nx.tensor([[1, 2], [3, 4]])
defn softmax(x) do
Nx.exp(x) / Nx.sum(Nx.exp(x))
end
What we got? => Efficient numerical operations
Axon
model =
Axon.input("input", shape: {nil, 16})
|> Axon.dense(64)
|> Axon.tanh()
|> Axon.dense(10)
|> Axon.softmax()
What we got? => Framework for building Neural Network models
Pre-trained models
{:ok, model_info} = Bumblebee.load_model({:hf, "bert-base-uncased"})
{:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, "bert-base-uncased"})
serving = Bumblebee.Text.fill_mask(model_info, tokenizer)
Nx.Serving.run(serving, "The capital of Portugal is [MASK].")
{:ok, model_info} = Bumblebee.load_model({:hf, "microsoft/resnet-50"})
{:ok, featurizer} = Bumblebee.load_featurizer({:hf, "microsoft/resnet-50"})
serving =
Bumblebee.Vision.image_classification(model_info, featurizer,
compile: [batch_size: 8],
defn_options: [compiler: EXLA]
)
Kino.start_child({Nx.Serving, serving: serving, name: MyServing, partitions: true})
image_input = Kino.Input.image("Image", size: {224, 224})
form = Kino.Control.form([image: image_input], submit: "Run")
frame = Kino.Frame.new()
Kino.async_listen(form, fn %{data: %{image: image}} ->
if image do
Kino.Frame.render(frame, Kino.Text.new("Running..."))
image = image.data |> Nx.from_binary(:u8) |> Nx.reshape({image.height, image.width, 3})
output = Nx.Serving.batched_run(MyServing, image)
output.predictions
|> Enum.map(&{&1.label, &1.score})
|> Kino.Bumblebee.ScoredList.new()
|> then(&Kino.Frame.render(frame, &1))
end
end)
Kino.Layout.grid([form, frame], boxed: true, gap: 16)
Serving everyone
Piecing it together
More
> “With Bumblebee, the intersection of AI and web development becomes a harmonious symphony rather than a cacophony of complexity.” ~ GPT 3.5
Resources
Related talks