Give MusFlow a photo, a story or a plain caption and it composes a short music clip. Each input is mapped into the sound space of CLAP, and flow matching draws the audio from there.
Learn how a small model turns pictures and stories into music, with no musical vocabulary from the user: the adapters, the flow, the training recipe and the data it needed.
Switch the image, the story and the caption on and off. Press Make the music. Then slide the flow steps from 1 to 16 and watch the particles settle. Then we build, piece by piece, everything underneath: the shared sound space, the adapters, the flow, the loss, and the dataset the authors had to invent.
You need a feel for vectors (a list of numbers that marks a point in space) and a little Python for the code. We build the rest from zero.
Based on “MusFlow: Multimodal Music Generation via Conditional Flow Matching” by Jiahao Song and Yuzhao Wang (Shanxi University), ACM Multimedia 2025, arXiv:2504.13535. It is a reading for MMAI Lecture 10, Modern Generative AI. Every idea is re-taught here in our own words and devices.
Imagea photo of the Figure 1 scene (the model sees only its CLIP vector)
StoryUnder the blue sky and white clouds, a mother holding a parasol is enjoying the natural scenery with her child on the grass.
CaptionA melodious and gentle musical piece, featuring the violin as the primary instrument, composed in a classical style, evoking feelings of joy and relaxation.
The three texts are the paper’s Figure 1 example. The map is a toy 2-D slice of the real 512-number CLAP space: the regions, the three adapter errors and the 28 target points are illustrative, and the flow uses the exact marginal field for those points. The paper’s own numbers are the FAD scores (lower is better) from Table 1: 3.41 caption, 3.56 story, 3.66 image, 3.36 multimodal.
Chapter 0
See why asking for music in musical language shuts most people out, and what a model must do to accept a photo or a story instead
Picture a friend making a short film about a picnic. A mother sits on the grass with her child, a parasol over them, white clouds above. The film needs quiet background music. Your friend opens a music generator and sees an empty text box.
What do they type? Something like “a slow-paced classical string composition in a major key, 70 beats per minute”. That is how a composer talks. Your friend does not talk that way. They know what the scene feels like. They do not know the words for the music that fits it.
The MusFlow paper starts from this gap. Today’s text-to-music models are good, but they want a music caption: a sentence that names instruments, style and mood. The authors say the user must “think like a composer” while the model only acts as the performer. They want the model to be the composer too. Give it the scene, and it finds the music.
The paper lets the user give any mix of three inputs. A music caption says what the music should sound like: “a melodious and gentle piece, violin, classical, joy and relaxation”. A story text describes a scene and says nothing about sound: “a mother holding a parasol enjoys the scenery with her child on the grass”. An image shows the scene. At least one must be present, and all three together are fine.
The story and the caption are both text, but they are very different jobs. The caption names musical things. The story does not. A model that takes a story must work out for itself that a sunny picnic suggests light strings. That skill is the hard part. The paper calls it music association.
The paper names two walls. The first is the input. Models such as MusicGen, AudioLDM2 and MusicLDM only take text, and they expect musical text. The second is the cost of the few models that do take pictures. They use a large language model (LLM, a huge text model) to read the image and the text, then pass its summary to a separate music generator. That works, but it needs a great deal of memory and compute.
The paper also names a third wall that hides behind the first two: data. To learn music from pictures, a model needs examples where a picture, a story, a caption and a music clip all go together. Existing music datasets hold only a clip and a caption written by a professional. Nobody had such quadruples at scale. The authors had to build them (Chapter 6).
Table 1 of the paper tests six models on four tasks. A model that cannot take an input type is marked N/A. Pick an input below and see who can answer. Each bar is the model’s FAD, the Frechet Audio Distance: a score of how far the generated music is from real music, where lower is better.
Choose what the user gives the model. A short bar is a good score. A grey line of text means the model has no way to accept that input. Try story, then image.
All numbers are the paper’s Table 1 (FAD, lower is better), measured on the authors’ own validation set. The paper does not give a story or an image result for MusicGen, AudioLDM2 or MusicLDM because those models cannot take them.
Look at the pattern. For a caption, all six models can compete, and the scores sit between 3.41 and 5.36. For a story, the gap opens wide: MusicGen scores 7.72 and CoDi 8.45, because a story is not a music caption. For an image, only three of the six can answer at all. MusFlow answers every row, and its four scores stay between 3.36 and 3.66.
One honest note before we go on. These scores come from the authors’ own test split. MusFlow trained on the same kind of data. The paper does not say the baselines saw it. So the table shows that MusFlow works well here. It does not prove it beats every model everywhere. We come back to this in Chapter 7.
MusFlow does one trick twice. First, it turns each input, whether image, story or caption, into a point in the space where music lives, so a story becomes “the music a story like this would have”. Second, it uses a fast generative method, flow matching, to draw a spectrogram of sound from that point. Small adapters do the first step. A light network does the second. No LLM is in the loop.
Chapter 1
Follow one picnic photo through six stations, naming the shape of the data at every hand-off, until it leaves as a waveform
Think of a factory with six stations and one conveyor belt. A photo goes on at one end. A sound file comes off at the other. At each station the thing on the belt changes shape. If you know each shape, you know the whole machine.
The paper splits MusFlow into three stages: feature extraction, feature alignment and fusion, and audio generation. We cut the last stage into three smaller stations, because each one changes the shape again. The device below walks the belt. Step through it, then read on.
Each row is a station. The right side is the shape of what leaves it. Press Next, or click a station, and read the sentence below.
The 512 is the paper’s (every embedding is in R512). The latent C×H×W and the Mel T×F are written only as symbols in the paper, so they stay symbols here. The model sizes are not given in the text we read.
A computer cannot compare a photo to a sound. So the first job is to turn each input into an embedding: a list of numbers, here 512 of them, that stands for the meaning of the input. Similar meanings give lists that point the same way. Chapter 2 builds this idea from zero.
The image and the story go through CLIP-ViT-B/32, a pretrained model that reads both pictures and sentences. The caption goes through CLAP, a pretrained model that reads both sentences and music. The paper uses a CLAP checkpoint trained on music. Each gives a vector: eI, eS and eC, each of size 512.
The vectors from CLIP live in a picture-and-words space. The music lives in a different space. So a small adapter per input (a short stack of linear layers) moves each vector into the CLAP music space. This is the paper’s key move, and it needs no LLM.
Now there are up to three vectors, one per input the user gave. The model takes their plain average. The result is one vector ef of 512 numbers, the fused conditional embedding. If the user gave only a story, the average is over one vector. The belt does not care how many inputs came in.
Here is where the music is born. The model starts from pure random noise, with the same shape as the target. It then moves that noise, step by step, into something that fits ef. The target is not the sound itself. It is a small compressed picture of the sound, called the latent, with shape C×H×W. Chapter 3 explains the moving.
A VAE decoder (a network that unpacks a compressed picture) turns the latent into a Mel-spectrogram: a picture of sound with time across and pitch bands up, size T×F. A vocoder, here HiFi-GAN, turns that picture into a waveform you can play. Both are pretrained and borrowed from MusicLDM.
In training the belt carries a second parcel, the answer. The real music clip goes through the short-time Fourier transform (STFT, a way to cut sound into short windows and measure the pitches in each) and a Mel filter bank, which gives the Mel picture. The VAE encoder squeezes that picture into the target latent Z1. CLAP reads the same clip and gives the target vector eM. So training needs two pretrained encoders on the music side. Inference needs neither.
Count the numbers. A clip of 10 seconds at 16,000 samples a second holds 160,000 numbers. The Mel picture is smaller, and the VAE latent is smaller again. A network that draws 32,000 numbers is cheaper and learns faster than one that draws 160,000. This is the same reason image models work in a latent space. Try the counter below.
The bars use a log scale: each gridline is ten times more. Drag the length, then switch the sample rate to 44.1 kHz and see what the waveform does.
Illustrative. The paper writes only symbols (T×F, C×H×W). The counts use typical AudioLDM-family settings: 100 Mel frames a second, 64 Mel bands, a latent that is 4 times smaller in each direction, with 8 channels. Real MusicLDM settings may differ in detail. The 16 kHz limit is the paper’s Section 5.
At 16 kHz and 10 seconds: 10 × 16,000 = 160,000 samples. The Mel picture has 10 × 100 = 1,000 frames of 64 bands, so 64,000 numbers. The latent is 250 frames by 16 bands by 8 channels, so 32,000 numbers. That is five times fewer than the waveform. At 44.1 kHz the waveform grows to 441,000 numbers and the saving grows to about 14 times. The authors stay at 16 kHz because their pretrained vocoder only works there. It is the first limit they list.
The inference path is short. Every line below is one station. The shapes in the comments follow the paper; the two latent sizes are the symbols C, H, W.
pythondef generate(image=None, story=None, caption=None, steps=N): embs = [] if image is not None: embs.append(adapter_I(clip.encode_image(image))) # (512,) -> (512,) if story is not None: embs.append(adapter_S(clip.encode_text(story))) # (512,) -> (512,) if caption is not None: embs.append(adapter_C(clap.encode_text(caption))) # (512,) -> (512,) e_f = torch.stack(embs).mean(0) # (512,) plain average z = torch.randn(C, H, W) # Z0 ~ N(0, I), the latent's shape for k in range(steps): # follow the arrows from t = 0 to t = 1 (Chapter 3 explains) t = k / steps z = z + (1 / steps) * flow_net(z, t, e_f) # same shape in and out mel = vae.decode(z) # (T, F) return hifigan(mel) # waveform, 16 kHz
One honest gap: the paper says it uses “numerical methods” to follow the flow. It does not name the solver or the step count in the text we have, so the Euler loop above is the simplest stand-in, not a claim about their code.
Chapter 2
Learn what an embedding is, why a story and a song live far apart, and how three small adapters pull the story next to its music
Imagine a huge library where books are shelved not by title but by meaning. Cookbooks sit near each other. Sad poems sit near other sad poems. To find a book, you walk to the right corner. A second library does the same for music: lullabies in one corner, marches in another.
Now suppose a friend hands you a story and asks, “Where would the matching music be shelved?” The story sits in the book library. The music sits in the music library. The corners do not line up. You need a rule that takes a story’s shelf spot and gives the spot in the music library. That rule is an adapter.
An embedding is a list of numbers that gives the position of one thing in such a library. The library has 512 directions, so a spot is 512 numbers. You cannot picture 512 directions, but you can picture two. The rule is the same in both: things with similar meaning get nearby spots.
To say how near two spots are, models use cosine similarity. Draw an arrow from the centre to each spot. If the arrows point the same way, the score is 1. If they stand at a right angle, the score is 0. If they point opposite ways, it is −1. The score is the cosine of the angle between the arrows. Turn the arrow below.
The blue arrow is a music spot. The purple arrow is another spot. Drag the angle and watch the cosine. The dashed mark at 0.3 is the cut the paper uses to filter its data (Chapter 6).
Cosine similarity is exact maths. The paper’s 0.3 is a threshold on its CLIP and CLAP scores; real scores are computed in 512 directions, and the CLIP score in practice may be rescaled, so treat the toy as the idea, not the exact scale.
At 40 degrees the score is 0.77: close. At 73 degrees it is 0.29: just below the paper’s cut. At 90 degrees it is 0. The cut of 0.3 sits near 73 degrees, so it keeps only pairs that lean clearly the same way.
How do you train a library so that meaning decides the shelf? With contrastive learning. Show the model many matched pairs, such as a photo and its caption. Pull each pair’s spots together. Push every non-matching pair apart. After millions of pairs, the shelf order follows meaning.
CLIP did this for pictures and sentences. A photo of a dog and the words “a dog on grass” land near each other. CLAP did the same for music clips and sentences. A violin clip and “a gentle violin piece” land near each other. So both libraries speak of text, but about different things: CLIP’s text is tuned to what things look like, and CLAP’s text is tuned to what things sound like.
That explains the whole design. The user’s caption already lives in CLAP space, close to music. The user’s image and story live in CLIP space, where nothing is tuned for sound. A story about a picnic and a gentle violin piece are far apart there. Something must move them.
The paper gives each of the three inputs its own MLP adapter. An MLP is a stack of simple layers. Figure 2 shows each block as Linear, then ReLU, then LayerNorm, repeated; the hyperparameter section says the network has 4 layers. A linear layer multiplies the vector by a matrix. ReLU sets negative numbers to zero, so the layers can bend the space rather than only rotate it. LayerNorm rescales the numbers to a steady size. Input and output are both 512 numbers.
What should the adapter learn? During training the real music clip is known. Run it through CLAP and you get its true spot, eM. The adapter’s job is to take ei (image, story or caption) and land on eM. The paper calls this the “music association ability”: the skill of hearing in a picture what a person would hear.
The loss is the mean squared error. Read the equation carefully, because the average sits inside the bars.
A worked case in two dimensions, with the target eM = (0.90, 0.50). The adapters return aI = (0.40, 0.85), aS = (1.35, 0.20) and aC = (0.80, 0.62). Their average is ((0.40 + 1.35 + 0.80)/3, (0.85 + 0.20 + 0.62)/3) = (0.85, 0.557). The difference from the target is (0.05, −0.057). Squared and added: 0.0025 + 0.0032 = 0.0057.
Now score each adapter alone. Image: 0.50² + 0.35² = 0.37. Story: 0.45² + 0.30² = 0.29. Caption: 0.10² + 0.12² = 0.024. Their mean is 0.23. The averaged loss is forty times smaller, because the image error and the story error point in opposite directions and cancel. Try it yourself.
Each purple dot is one adapter’s guess for the blue cross, the real music. Drag training from 0 to 100% and watch the dots travel. Switch inputs off to change what is averaged.
Illustrative 2-D toy. The start spots, the final errors and the straight-line training path are made up to show the idea. The loss formula is the paper’s Equation 3, with the average inside the norm. The paper’s adapters work on 512 numbers.
Two lessons hide here. First, the loss only asks that the average be right. Individual adapters are free to be wrong in ways that cancel. That is cheap and it works when inputs are noisy. Second, it means a missing input changes the average. That is why Chapter 5 trains with random missing inputs.
Chapter 3
Learn how a field of arrows can carry a cloud of random noise, step by step, into a cloud shaped like real music
Picture a crowd of 150 people standing in a foggy field at random. A loudspeaker says: “Everyone, walk to your seat.” Nobody sees the stadium. Each person only feels a push in some direction, depending on where they stand and how late it is. If the pushes are right, everyone arrives in a good seat.
That is flow matching. The people are samples. The field is a rule that says “at this spot, at this time, move this way and this fast”. The seats are real data. The model’s job is to learn the rule. Once it has the rule, making new data is just walking.
A vector field vt(x) gives an arrow at every point x and every time t. The arrow says which way to move and how fast. The time t runs from 0 to 1. At t = 0 the crowd is noise: points drawn from a standard Gaussian (a bell-shaped cloud centred on zero, thickest in the middle), written p0 = N(0, I). At t = 1 the crowd should look like real data: p1. In MusFlow, the data are the VAE latents of real music clips.
A flow φt(x) is the position of the person who started at x, after time t. It obeys an ODE (ordinary differential equation), which only says “your speed is whatever the arrow at your spot says”.
This is the paper’s Equation 4. The paper’s name for the family is continuous normalizing flow (CNF). Its main selling point over a diffusion model is that the path is deterministic: there is no fresh random noise injected at each step. The same start always gives the same end.
A computer cannot walk continuously. It takes small hops. The simplest rule is Euler’s method: take N equal hops, and in each hop move by (arrow at the current spot) × (1/N). Written in code, it is the loop you saw in Chapter 1: z = z + (1/N) * v(z, t).
More hops follow the true curve more closely but cost one network call each. So the number of steps is a price: more steps cost more compute. This is the “sampling efficiency” the paper cites. Straight paths let the hops be few, because a straight road does not need many small hops.
Take one dimension. Real data sits at two spots: −0.8 and +0.8, equally often. A person starts at x = −0.2. We use the exact field (derived in Chapter 4) and a tiny leftover noise, σmin = 0.01.
One hop. At t = 0 both seats look equally likely, so the field points to their average, 0. The arrow is +0.20 and the hop lands at −0.002. The person ends in the middle, a seat nobody has.
Four hops. The person first drifts toward the middle (−0.151, −0.115), but at t = 0.75 the field has sharpened: the left seat is 91% likely, and the arrow is −2.06. The last hop lands at −0.646. Much closer.
Eight hops reach −0.783, and 64 hops reach −0.789. The seat is at −0.8. So the few-step sampler is blurry in a particular way: it lands between modes. Play with it below, in two dimensions.
Blue dots are real data in two clusters. Warm dots are 150 noise samples being carried by the exact flow field. Set the steps, then press Flow. Try 1, then 4, then 16.
Illustrative toy. The data are 12 made-up points in two clusters. The field is the exact FM-OT marginal field of the paper’s Equation 7 for those points, with σmin = 0.01. The real model learns this field with a network, in thousands of dimensions, and the paper does not state its step count.
At one step, every particle lands near the average of all data, in the empty middle. At four, most have picked a side, with some still stuck between. At sixteen, the paths curve visibly to the seats and the particles sit on the clusters. The paths also bend most near t = 1, where each person finally learns which seat is theirs.
Why does the arrow point to the middle at the start? Because many roads cross there. Each real data point x1 would send a person along its own straight line. At a crossing, the loudspeaker cannot know which line this person is on. The best single arrow is the weighted average of all the lines through that spot, with more weight on the likelier ones. That average is the marginal vector field. As time passes, the lines separate, fewer cross at each spot, and the average sharpens. This single idea explains the whole behaviour you just saw.
So the true target, vt(x), is an average over all data points, and a network cannot compute it directly. The next chapter shows the trick the paper uses to train on one data point at a time and still learn the average.
Chapter 4
Derive the training target from a straight line between a noise point and a music latent, then run one full training step with every number shown
Chapter 3 ended with a problem. The perfect arrow at each spot is an average over every real music clip. No one can compute that average for millions of clips. So how do you train a network to produce it?
Here is the trick. Stop asking for the average. Show the network one walk at a time. Pick one real latent z1 and one noise sample z0. Draw the straight line between them. Pick a random moment t on that line. Ask the network: “Standing here at this moment, which way am I walking?” We know the answer, because we drew the line.
One walk alone is a poor teacher. But the network sees the same spot from many walks, each with a different answer. To minimise squared error, it learns the average of those answers. That average is exactly the marginal field. Training on single walks recovers the average for free.
The paper writes the ideal loss as Equation 5: the squared gap between the network vθ(x, t) and the true field vt(x). The true field is unknown, so the paper uses conditional flow matching (CFM, Equation 6). It conditions on one data point z and replaces the unknown field with the known conditional one, vt(x | z). The paper cites the result that the two losses have the same gradient: ∇θLFM = ∇θLCFM. Training on the easy loss moves the weights the same way as the hard one.
There are many ways to draw the walk. The paper picks FM-OT (flow matching with an optimal-transport path). The condition z is the data point x1. The position at time t is a Gaussian blob that slides and shrinks:
A note on notation. The paper’s text writes the variance as σt2(x1) = 1 − (1 − σmin)t. The loss it prints in Equation 7 follows from the standard-deviation form σt = 1 − (1 − σmin)t, as in the original flow-matching paper (Lipman et al.), so that is what we use. Only the standard-deviation form gives that exact target, so we treat the squared version in the text as a typo.
Now the velocity. It is the rate at which xt changes with t. Take the derivative of the line above: the first term t·x1 gives x1, and the second term gives −(1 − σmin)·x0. So the target velocity is
That is the heart of the paper’s Equation 7. In MusFlow the sample is the music latent, so the loss is Equation 8:
Use two numbers per point, so we can draw it. The real latent is z1 = (1.00, 0.40). The noise is z0 = (−0.50, 1.00). Take σmin = 0.01 and the random time t = 0.3.
Step 1, the width. σt = 1 − 0.99 × 0.3 = 0.703.
Step 2, the spot. zt = 0.3 × (1.00, 0.40) + 0.703 × (−0.50, 1.00) = (0.300 − 0.352, 0.120 + 0.703) = (−0.052, 0.823).
Step 3, the target. u = (1.00, 0.40) − 0.99 × (−0.50, 1.00) = (1.00 + 0.495, 0.40 − 0.99) = (1.495, −0.590).
Step 4, the guess. Say the network returns (1.20, −0.30). The gap is (−0.295, 0.290). Squared and added: 0.087 + 0.084 = 0.171. That is the loss for this one sample. The optimiser nudges θ to shrink it.
A sanity check proves the target is right. Walk from zt along u for the remaining 0.7 of time: (−0.052 + 0.7 × 1.495, 0.823 + 0.7 × (−0.590)) = (0.995, 0.410). The blob centre at the end is z1 + σmin z0 = (0.995, 0.410). They match. Now try your own numbers.
The grey dot is noise z0, the blue dot is the real latent z1. The warm dot is where this training sample stands at time t. The green arrow is the correct velocity. The purple arrow is the network’s guess. Drag t, then the guess error.
Toy numbers from the worked example. The network’s error direction is fixed, and 100% error is the vector (−0.5, +0.5). The sigma-min slider reaches 0.5 only to make the effect visible; the paper does not state its value.
Slide t and watch: the warm dot moves along the line, but the green arrow never changes. That is the “constant speed, straight line” property the paper credits to FM-OT. A network that learns it only has to learn a direction that depends on where you stand, not a speed that changes with time. Raise σmin and the end of the walk stops short of the data point: the blob keeps width.
pythondef cfm_loss(flow_net, z1, e_f, sigma_min): # z1: (B, C, H, W) VAE latents of real clips; e_f: (B, 512) fused condition B = z1.shape[0] z0 = torch.randn_like(z1) # noise, N(0, I) t = torch.rand(B, 1, 1, 1) # one random time per sample sigma_t = 1 - (1 - sigma_min) * t z_t = t * z1 + sigma_t * z0 # the spot on the walk target = z1 - (1 - sigma_min) * z0 # the correct arrow pred = flow_net(z_t, t.flatten(), e_f) # (B, C, H, W): same shape as z return ((pred - target) ** 2).mean() # mean squared error
Three design choices are worth naming. The network is a Transformer-UNet, a network that squeezes the picture down and rebuilds it, with attention layers inside; the settings come from MusicLDM. It predicts a velocity, not the noise. And the condition ef is an extra input; the paper does not say how it enters the network (for example by concatenation or cross-attention), so we do not claim a mechanism.
Chapter 5
See why the authors train the pointer first, the painter second and both together last, and why they hide inputs from the model on purpose
An apprentice painter has two skills to learn. One is to read a client’s request and say what kind of picture they want. The other is to paint it. If you teach both at once, from nothing, each skill chases a moving target. The painter is learning to paint from requests that the reader of requests still gets wrong.
So a good teacher goes in order. First the apprentice learns to read requests. Then, with that skill fixed, they learn to paint. Last, both are polished together. MusFlow trains the same way.
Stage 1: alignment training. Only the MLP adapters learn. The loss is the alignment loss ℒA from Chapter 2. The flow network is not involved. The goal is a good pointer: a function from image, story or caption to a spot in the music space. This takes 50 epochs. (An epoch is one full pass over the training set.)
Stage 2: generation training. Now the adapters are frozen, which means their weights stop changing. The flow network learns with the generation loss ℒG from Chapter 4. Because the condition ef no longer drifts, the flow network studies a stable signal. The paper says this stage needs the most epochs, and the hyperparameter section gives 250.
Stage 3: joint training. Both parts learn together for 100 epochs. The loss is the sum of the two:
Why a third stage? The paper says joint training removes the “accumulated errors from separate training”. In stage 2 the flow network learned to trust adapter outputs that still carry small mistakes. In stage 3 the adapters can shift a little so that their outputs help the flow most. The λ term stops them from drifting away from the real music space while they do so.
A worked number. Take the single sample from Chapter 4, with ℒG = 0.171, and the alignment loss from Chapter 2, ℒA = 0.0057. If λ were 1 (an illustrative choice), ℒJ = 0.171 + 0.0057 = 0.1767. If λ were 10, the alignment term would count 0.057 and matter more. Click through the stages below.
Now count the work. Training uses about 29.56 thousand clips (Chapter 6). At batch size 24, one epoch is 29,560 divided by 24, about 1,232 updates. Over 400 epochs that is roughly 493,000 updates, all on one RTX 4090. The count is our arithmetic from the paper’s numbers. It shows why stage 2 dominates the budget: it holds 62.5% of all updates.
Each row is one stage. Warm means that part is learning. Grey means it is frozen. The bar width is the share of the 400 epochs.
Epoch counts (50, 250, 100) and the setup (one RTX 4090, AdamW, learning rate 1e-4, batch size 24, 4-layer adapters) are the paper’s Section 4.1.2. The 400 total is their sum. The pretrained encoders, the VAE and the vocoder are used as given; Section 3.3 names only the adapters and the flow module as trained.
There is a second problem. A user may give only a photo. Or a story and a caption. If the model always saw all three during training, it would never learn what an average over one or two looks like, and it could stumble on partial input.
So in each batch the authors hide some inputs at random, but always keep at least one. With three inputs there are 23 − 1 = 7 possible non-empty sets: I, S, C, I+S, I+C, S+C and I+S+C. Over many epochs the same sample is seen under many of them. The paper adds a side benefit: “improving both data efficiency and model generalization”, since one clip teaches seven situations.
When an input is hidden, the average in Station 3 is taken over only the inputs that remain. That is why the averaging design is handy: it works for any subset with no change.
Each bar is one of the seven input sets. Press Draw a batch to give 24 samples a random set each, with equal chance.
We read the paper’s “equal probability” as each of the 7 non-empty sets being equally likely; the text does not spell out the exact sampling.
Draw 200 batches and every set gets close to 24 ÷ 7 = 3.4 samples per batch. No set is left out. That is the point: every combination a user could type is something the model has practised.
pythondef sample_mask(): while True: m = [random.random() < 0.5 for _ in range(3)] # I, S, C, each on or off if any(m): return m # keep at least one: 7 sets, equal chance for stage, epochs in [("align", 50), ("generate", 250), ("joint", 100)]: adapters.requires_grad_(stage != "generate") # frozen only in stage 2 flow_net.requires_grad_(stage != "align") # untouched in stage 1 for batch in loader(batch_size=24): e_f = fuse(adapters, batch, sample_mask()) # mean over the inputs kept L_A = ((batch.e_M - e_f) ** 2).sum(-1).mean() L_G = cfm_loss(flow_net, batch.z1, e_f, sigma_min) loss = {"align": L_A, "generate": L_G, "joint": L_G + lam * L_A}[stage] loss.backward(); opt.step(); opt.zero_grad()
Note one detail the paper leaves open: whether the mask is also applied during stage 1. The text describes the mask as part of training in general. The code above applies it in every stage, which is our reading.
Chapter 6
Follow a film-crew workflow of four small models that writes stories, checks them, composes music captions and finds matching clips
To teach a model to hear music in a photo, you need many examples where a photo, a story about it, a musical caption and a matching clip all sit together. Before this paper, almost nobody had these. Music datasets held a clip and a caption written by a professional, and no pictures or stories. Hiring people to write four-part records for tens of thousands of clips would cost too much.
The authors borrow an idea from film. A film crew has jobs: an art department makes scenes, a writer writes the script, an editor checks it, a composer writes the score, and a music librarian finds the right track. So they build the same crew from four small models and let them make the records. The paper calls this a multi-agent workflow: several programs that each do one job and hand work to the next.
1. Script Writing Agent. Input: an image. Output: a story text that describes the scene. This is image captioning, so the paper uses BLIP, a pretrained captioning model. Note that a caption of an image says “a woman on grass with a parasol”, not anything about sound. That is exactly what a story text should be.
2. Script Review Agent. Input: the image and its story. Output: keep or drop. It uses CLIP: compute the CLIP score (how similar the image and the sentence are in CLIP space, the cosine idea from Chapter 2). Pairs under a threshold of 0.3 are dropped. This removes captions that BLIP got wrong.
3. Music Composition Agent. Input: the image and the story. Output: a music caption such as “soft strings, classical, calm”. This is the creative step. It needs a model that sees and writes. The paper picks Qwen2-VL-7B, a vision-language model, but first fine-tunes it, as the next section shows.
4. Music Filtering Agent. Input: the music caption. Output: a clip from a public music collection. It computes the CLAP score between the caption and every clip, takes the highest, and accepts it only if the score exceeds 0.3 again.
Put the four together and you get a loop that walks from a bare image to a full record: image, story, music caption, clip. The paper’s Figure 3 draws exactly this, with an impressionist painting of a seaside cottage as its example. The writer agent describes it as “a small cottage surrounded by lush greenery overlooks the ocean”. The composer agent answers “a soothing acoustic composition blending gentle guitar arpeggios, warm cello harmonies, and distant chimes”. Now play with the two thresholds.
Each dot is one candidate record. Across: its review score from agent 2. Up: its music-match score from agent 4. Green dots pass both filters. Red dots fail at least one. Drag each threshold and count the survivors.
The 40 candidates and their scores are made up to show the trade-off. The paper’s own setting is 0.3 for both agents (Section 4.1.1). It does not report how many candidates each filter removed.
Raise either line and fewer records survive but each survivor is more trustworthy. Lower them and the dataset grows but admits bad matches. That is a plain precision versus quantity dial, and the authors chose 0.3.
A general vision-language model is not a good composer. It has seen little music writing. So the authors first build a small training set. They take four existing datasets that already link music to pictures: Music2Image, extended-MusicCaps, MelBench and MUImage. They run agents 1 and 2 on them to add stories and filter. That leaves about 10,000 samples (the paper’s round figure; its Table 2 lists 10.85 thousand for these four sources), each an image, a story and a human-written music caption.
They then fine-tune Qwen2-VL-7B on those with QLoRA: a method that freezes the big model, stores it in compressed form, and trains only a small set of extra matrices. The rank sets how big those matrices are. The authors use rank 8, for 20 epochs. GPU memory kept them from going higher, which they list as a limitation. Chapter 8 shows what the fine-tune bought.
With the fine-tuned composer in place, the authors run the whole crew on a new pairing. Images come from ArtGraph, a collection of artworks. Music comes from FMA-Medium, a public music collection. The result is ArtMusic. Joining ArtMusic with the 10k reused samples gives MMusSet.
| Source | Samples (k) | Hours |
|---|---|---|
| Music2Image | 1.50 | 4.17 |
| MusicCaps | 4.54 | 12.60 |
| MelBench | 0.98 | 2.69 |
| MUImage | 3.83 | 10.64 |
| ArtMusic | 22.46 | 62.39 |
| MMusSet (total) | 33.31 | 92.49 |
Check the table with arithmetic: 33.31 thousand clips of 10 seconds each is 333,100 seconds, which is 92.5 hours. It matches. And two thirds of the dataset (22.46 of 33.31, 67%) is ArtMusic, the part the crew built alone.
The split is by source. Training uses extended-MusicCaps, MelBench, MUImage and 90% of ArtMusic. Evaluation uses all of Music2Image and the other 10% of ArtMusic. The counts: training = 4.54 + 0.98 + 3.83 + 0.9 × 22.46 = 29.56 thousand; evaluation = 1.50 + 0.1 × 22.46 = 3.75 thousand. See it below.
The top bar is all of MMusSet by source. The bottom bar shows how the paper splits it. Switch the view to see the numbers behind each colour.
Source sizes are the paper’s Table 2. The 90/10 split of ArtMusic and the use of Music2Image for evaluation are from Section 4.1.1. The training and evaluation totals are our arithmetic from those numbers.
Look hard at ArtMusic. The paintings and the music were never made for each other. A clip is paired with a painting only because the composer agent wrote a caption that the CLAP score said was close. So the “truth” the model trains on is the opinion of a fine-tuned captioner and a similarity score, not a human who heard both. This is our reading, not a claim the paper makes. It is also the reason for the modest, honest results claim: MusFlow does well on data that shares the crew’s taste.
Chapter 7
Learn what each score measures, read Tables 1 and 3 cell by cell, and separate what they prove from what they only suggest
Imagine a baking contest with two kinds of judges. A machine weighs and measures each cake. Twenty people taste it. A good report says which judge said what, and what a gap of one point really means. This chapter reads MusFlow’s results that way.
FAD, the Frechet Audio Distance. Take many real clips and many generated clips. Turn each into an embedding. Fit a bell-curve cloud to each group. FAD is the distance between the two clouds. Lower is better: generated music that looks like real music in the embedding has a small FAD.
KL divergence. A classifier labels clips (“violin”, “drums”). KL measures how much the label mix of the generated clips differs from the real ones. Lower is better.
CLAP score. Cosine similarity (Chapter 2) between the CLAP vector of the generated audio and the CLAP vector of the input text. Higher is better. It checks that the music matches the words.
IB score (ImageBind). The same idea for images: the similarity between the generated audio and the input image in ImageBind’s shared space. Higher is better.
OVL and REL, the human scores. Twenty people rated 50 random samples from each model, for overall quality (OVL) and for relevance to the input (REL). Higher is better. The paper does not state the rating scale; the values run up to about 78, so it looks like 0 to 100.
Table 1 has six models and four tasks. Pick a task and a metric below. The device ranks the models and tells you the size of MusFlow’s lead over the best of the others.
Choose a task, then a metric. Bars are sorted best first. The warm bar is MusFlow. Models that cannot take that input are not shown.
All values are the paper’s Table 1. FAD and KL: lower is better. CLAP and IB scores: higher is better. The multimodal task has no KL column in the paper. The percentage gap is our arithmetic.
Caption to music. MusFlow has the best FAD (3.41) and KL (2.56). Its CLAP score, 0.32, is a little below MusicLDM’s 0.34. The paper says so plainly. The FAD gain over MusicLDM is 3.4%: small.
Story to music. MusFlow is best on all three: FAD 3.56, KL 2.78, CLAP 0.31. MusicLDM is the closest, at FAD 3.98. The lead is 10.6%. Models built for caption-style text do worse here (MusicGen 7.72, CoDi 8.45), as Chapter 0 predicted.
Image to music. Only CoDi and M2UGen can compete. MusFlow wins by a wide margin: FAD 3.66 against M2UGen’s 6.24 (41% lower), and IB score 0.82 against 0.71.
Multimodal. With any mix of inputs, MusFlow reaches FAD 3.36 against M2UGen’s 6.36 (47% lower), CLAP 0.33 against 0.25, and IB 0.83 against 0.68. Note that going from one input to all three barely moves FAD (3.41, 3.56, 3.66 become 3.36). Extra inputs help a little, not a lot.
| Model | OVL (quality) | REL (relevance) |
|---|---|---|
| MusicGen | 64.82 | 62.11 |
| AudioLDM2-Music | 69.55 | 72.39 |
| MusicLDM | 76.45 | 73.25 |
| CoDi | 62.37 | 63.49 |
| M2UGen | 70.54 | 69.23 |
| MusFlow | 78.25 | 74.12 |
MusFlow leads both columns. The margin over MusicLDM is 1.80 points on quality and 0.87 on relevance. With 20 raters and 50 samples each, and no spread reported, that is a small gap. The order of the models is more informative than the exact numbers: MusicLDM and MusFlow sit well above the rest.
One more reading tip. In the paper’s Table 1, the bold numbers mark the best in each column. Look at the caption CLAP cell: the bold there belongs to MusicLDM, not MusFlow. Some tables hide their losses. This one shows its own, which makes the rest easier to trust.
Here is what the evidence supports. MusFlow produces audio that is close to real music in embedding space, matches its input at least as well as the baselines, and does so from images and stories, where most baselines have no path at all. That is a real result, from a small model on one consumer GPU.
Here is what it does not show, in our reading. First, the test set is the authors’ own split. MusFlow trained on that data family; the paper does not say the baselines did. A model trained on the exam’s style has an edge. Second, there are no error bars, so the 3% FAD gain over MusicLDM on captions cannot be told from noise. Third, the story and image inputs in ArtMusic came from the same agents that built the data (Chapter 6). Fourth, the paper reports FAD at one sampling setting and does not state its solver or steps, so speed claims (“fast generation”) are an argument, not a measurement.
Chapter 8
Test the alignment adapters against raw features and against a cheat, check the fine-tuned composer, and list what the paper admits it cannot do
A recipe with six ingredients invites one question: which of them matters? The way to find out is an ablation: remove or swap one part, keep everything else, and measure. If the score barely moves, the part was decoration. The MusFlow paper runs two such tests, and they ask different questions.
The adapters are the paper’s main idea, so the first test checks them. The authors train extra copies of the generator, changing only what it is conditioned on, and score the music every 50 epochs of generation training. Three conditioning choices compete.
CLAPmusic: the cheat. Feed the generator the real target clip’s own CLAP vector, eM. This is not usable at test time, because you do not have the clip. It shows the ceiling: how good conditioning could be if the pointer were perfect.
Raw features. Skip the adapters. Use CLAP of the caption, CLIP of the story, CLIP of the image, or (for multimodal) a plain average of those raw vectors, called “Avg”. This is the floor: what you get with no alignment.
Aligned: the paper’s method. Use ef from the adapters.
The prediction is clear: cheat above aligned above raw. Figure 4 has four panels, one per task. The y-axis is the CLAP score for text tasks and the IB score for image and multimodal tasks. Explore the curves below. The values are read off the plot, so they are accurate to about a hundredth.
Pick a panel from Figure 4. Blue is the cheat (the target music’s CLAP vector). Purple is the paper’s aligned condition. Grey is the raw feature. Drag the epoch and read the gap.
Curve values are our readings of the paper’s Figure 4 (about 0.01 accuracy). The score is CLAP score for caption and story, ImageBind score for image and multimodal. The gap-closed share is our arithmetic: (aligned minus raw) divided by (cheat minus raw).
At epoch 250 on caption-to-music, the cheat reaches about 0.35, the raw caption 0.27 and the aligned condition 0.31. The adapters close 50% of the gap between floor and ceiling. On story: 0.24 raw, 0.30 aligned, 0.35 cheat, so 55%. On image: 0.67, 0.77 and 0.88, so 48%. On multimodal the raw average stalls at 0.53 while aligned reaches 0.78 against a ceiling of 0.86: 76%.
Two observations. The adapters help on every task, which supports the central claim. And the gap to the cheat stays large, around half. Alignment is useful but far from perfect: predicting a clip’s sound from a photo is hard, and no adapter fully solves it. The multimodal panel shows the strongest effect, because a plain average of CLIP and CLAP vectors mixes two different spaces, while aligned vectors share one.
A small honest point: the aligned curves in Figure 4 end near 0.31 CLAP on caption, while Table 1 reports 0.32. The paper does not explain the small difference. The ablation models were retrained for this test, and the figure is a training-time check, not the final table.
The second test is about the data crew, not the generator. Does fine-tuning Qwen2-VL on the 10k samples produce better music captions? The authors fine-tune on MusicCaps, MelBench and MUImage, then test on Music2Image. They measure two things: the CLAP score between the generated caption and the target music (does it sound right?), and the BART score between the generated caption and the human caption (does it read the same?).
Choose a metric. Each bar is one version of the composer agent: the base model, or QLoRA fine-tunes of rank 4 and rank 8. Taller is better.
Values are the paper’s Table 4. BART score is computed with MiniLM-V2, a pretrained language model, as the paper states. The percentage change is our arithmetic.
Fine-tuning at rank 8 lifts the CLAP score from 0.15 to 0.24 (60% more) and the BART score from 0.50 to 0.63 (26% more). Rank 4 sits in between, so a bigger rank helped. Because GPU memory stopped the authors at rank 8, we do not know if rank 16 would help further. This test supports the data crew, but only on a small validation set, and it measures the caption, not the final music.
The Limitations section lists three things. Sampling rate. The model trains on 16 kHz audio, but most music is made at 44.1 kHz. The cause is the pretrained HiFi-GAN vocoder, which fixes the rate (Chapter 1). No video. Film music is a main use case, but compute limits kept the authors from adding video input. Rank. They could not fine-tune Qwen2-VL above rank 8 for lack of GPU memory.
We add four of our own, flagged as our reading. The averaging step treats all inputs as equally trustworthy, so a bad story can pull the average off. The training pairs in ArtMusic are retrieved, not composed for the picture (Chapter 6). There are no error bars or listening-test details such as the rating scale. And the paper does not report generation time or the solver, so the “fast” claim is untested here.
Chapter 9
Keep the numbers, the checklist and the core code, and see where the paper sits among the others in this course
People who want music for a scene often cannot describe music. MusFlow lets them give an image, a story or a caption instead. Pretrained CLIP and CLAP turn each input into 512 numbers. A small MLP adapter per input moves that vector into the CLAP music space, and the vectors present are averaged into one condition ef. A conditional flow matching network, with the FM-OT straight path, learns a velocity field that carries Gaussian noise to the VAE latent of a Mel-spectrogram. A VAE decoder and a HiFi-GAN vocoder turn that latent into sound. Training goes in three stages (align, generate, joint) with a random mask over the inputs. A four-agent workflow of BLIP, CLIP, a fine-tuned Qwen2-VL and CLAP built the 33.3k-clip dataset MMusSet that made all this possible.
| What | Number | Why it matters |
|---|---|---|
| Embedding size | 512, for eI, eS, eC, eM | All inputs share a size, so adapters and averaging fit |
| Adapter | 4 layers of Linear, ReLU, LayerNorm | Small, cheap, and no LLM needed |
| Input sets under the mask | 7 (any non-empty subset of 3) | Every input mix a user can give is practised |
| Training stages | 50, 250 and 100 epochs | Align first, generate with adapters frozen, polish jointly |
| Optimiser and hardware | AdamW, lr 1e-4, batch 24, one RTX 4090 | Reproducible on one consumer GPU |
| MMusSet | 33.31k clips, 92.49 h, 10 s each | The first music set with both images and stories |
| Agent thresholds | 0.3 (CLIP score and CLAP score) | The precision and quantity dial of the data crew |
| Composer fine-tune | QLoRA rank 8, 20 epochs; CLAP 0.15 to 0.24 | Fine-tuning improves captions; memory capped the rank |
| FAD by task (lower is better) | 3.41 caption, 3.56 story, 3.66 image, 3.36 multimodal | One model, best or near-best on every input |
| Best baseline on image and multimodal | M2UGen: FAD 6.24 and 6.36; IB 0.71 and 0.68 | MusFlow cuts FAD by 41% and 47% |
| Human scores | OVL 78.25, REL 74.12 (20 raters, 50 samples each) | Top in both, by small margins |
| Alignment ablation, epoch 250 (our reading) | adapters close about 50% of the gap on caption, 76% on multimodal | Adapters help, and a perfect pointer would help more |
| Audio rate | 16 kHz | Set by the pretrained vocoder; below usual 44.1 kHz |
| Term | Plain meaning |
|---|---|
| ef | The fused condition: the mean of the adapter outputs for the inputs present |
| CFM, FM-OT | Train on single straight walks from noise to one data point; the target velocity is z1 minus (1 minus σmin) z0 |
| ℒA, ℒG, ℒJ | Alignment loss, generation loss, and joint loss LG + λLA |
| Latent Z1 | The VAE’s compressed Mel-spectrogram, of shape C by H by W |
| FAD, KL | Distance of generated audio from real audio; lower is better |
| CLAP score, IB score | Match between the output audio and the input text or image; higher is better |
Tick each item you could explain from memory, with the shapes. This is a self-check; nothing is saved.
Press each skill you could explain without looking back. The sentence below counts them and names the next chapter to revisit.
A self-test, not a measurement. Each item points to the chapter that teaches it.
pythonclass Adapter(nn.Module): # one per input: CLIP image, CLIP story, CLAP caption def __init__(self, d=512, layers=4): super().__init__() self.net = nn.Sequential(*[b for _ in range(layers) for b in (nn.Linear(d, d), nn.ReLU(), nn.LayerNorm(d))]) def forward(self, e): return self.net(e) # (B, 512) -> (B, 512) def fuse(adapters, embs, present): # embs: dict of (B, 512); present: e.g. ["I", "C"] return torch.stack([adapters[k](embs[k]) for k in present]).mean(0) # e_f: (B, 512) def alignment_loss(e_f, e_M): # Equation 3: the average sits inside the norm return ((e_M - e_f) ** 2).sum(-1).mean() def cfm_loss(flow_net, z1, e_f, s_min): # Equation 8 z0 = torch.randn_like(z1); t = torch.rand(z1.size(0), 1, 1, 1) z_t = t * z1 + (1 - (1 - s_min) * t) * z0 target = z1 - (1 - s_min) * z0 return ((flow_net(z_t, t.flatten(), e_f) - target) ** 2).mean() @torch.no_grad() def sample(flow_net, e_f, shape, steps): # Euler stand-in; the paper does not name its solver z = torch.randn(e_f.size(0), *shape) for k in range(steps): z = z + flow_net(z, torch.full((z.size(0),), k / steps), e_f) / steps return hifigan(vae.decode(z)) # waveform, 16 kHz
MusFlow is a small, practical paper. It does not invent flow matching or the latent music pipeline. It borrows them from MusicLDM and the flow-matching work, and puts an alignment-by-averaging front end on them. Its large idea is not the generator but the plumbing: you can swap the generator’s input from musical words to anything, if you can map that input into the music space. Its second idea, the agent crew that builds data, is a pattern you can reuse in any field short of paired data.
It also shows a weakness shared by every system built on frozen encoders. Quality is capped by what CLIP and CLAP already know. The adapters can only move vectors; they cannot add musical knowledge that the encoders lack.
This lesson re-teaches “MusFlow: Multimodal Music Generation via Conditional Flow Matching” by Jiahao Song and Yuzhao Wang of the School of Mathematics and Statistics, Shanxi University, from the ACM Multimedia 2025 paper, arXiv:2504.13535. The authors’ samples, code and dataset are listed on their project page. Figures and numbers are theirs; the toys, analogies and our flagged readings are ours. It is an assigned reading for MIT MMAI, Multimodal AI (Spring 2026).
Now press Present or Teach and explain MusFlow out loud, from memory: why a story needs an adapter, how a straight walk becomes a training target, why training runs in three stages, and what the data crew did. Then go back to the instrument at the top, switch off two inputs, set the flow steps to 1, and explain why the particles collapse to one spot.