Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-264

Textual Inversion Loss

Problem

Compute the textual inversion objective for one step: the mean squared diffusion loss plus lambda_reg times the squared L2 distance between the learned embedding and its reference embedding.

The signature is textual_inversion_loss(predicted_eps, target_eps, embedding, ref_embedding, lambda_reg).

Hint

The regularizer prevents the new token embedding from straying too far from a real word.

Test cases

case 1
in: [[1,2],[0,0],[1],[0],1]
expected: 3.5
case 2
in: [[0],[0],[1],[0],0.5]
expected: 0.5
case 3
in: [[1],[0],[0],[1],0.25]
expected: 1.25
case 4
in: [[1,1],[1,1],[1,1],[1,1],2]
expected: 0
Starter codePython
def textual_inversion_loss(predicted_eps, target_eps, embedding, ref_embedding, lambda_reg):
    # Your code here
    pass

4 test cases · run your code against them in the editor