Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Tree distance algorithm
1. Workshop on tree distance By Hector Franco francoph at tcd dot ie Trinity College of Dublin
2.
3.
4.
5.
6. Computing Levenshtein distance D(i,j) = score of best alignment from s1..si to t1..tj = min D(i-1,j-1) + d(si,tj) //subst/copy D(i-1,j)+1 //insert D(i,j-1)+1 //delete (simplify by letting d(c,d)=0 if c=d, 1 else) also let D(i,0)=i (for i inserts) and D(0,j)=j
7. Computing Levenshtein distance - 3 D(i,j)= min D(i-1,j-1) + d(si,tj) //subst/copy D(i-1,j)+1 //insert D(i,j-1)+1 //delete The yellow row and column, correspond to the row 0 and column 0 of the table, and they are initiated in increasing order. For (int x = 0; x<size(target), x++) D(0,x) = x; For (int x = 0; x<size(source), x++) D(x,0) = x; d(si,tj) represents the cost of change the letter si into the letter tj, where if the letter is the same the cost will be 0 and if is a different letter the cost will be 1. = D( s,t ) C O H E N 0 1 2 3 4 5 M 1 1 2 3 4 5 C 2 1 2 3 4 5 C 3 2 2 3 4 5 O 4 3 2 3 4 5 H 5 4 3 2 3 4 N 6 5 4 3 3 3
8. Computing Levenshtein distance - 3 D(i,j)= min D(i-1,j-1) + d(si,tj) //subst/copy D(i-1,j)+1 //insert D(i,j-1)+1 //delete C O H E N 0 1 2 3 4 5 M 1 1 2 3 4 5 C 2 1 2 3 4 5 C 3 2 2 3 4 5 O 4 3 2 3 4 5 H 5 4 3 2 3 4 N 6 5 4 3 3 3 T1 T2 Cost M - 1 C - 1 C C 0 O O 0 H H 0 - E 1 N N 0 T1 T2 Cost M - 1 C C 0 C - 1 O O 0 H H 0 - E 1 N N 0
9. Practice G O O D G O D G O D TRY TRY G O O D 0 1 2 3 4 G 1 0 1 2 3 O 2 1 0 1 2 D 3 2 1 1 1
20. Mappings M H S I I S S B Domain: Range: Deleted: in the domain: Changed Exact match Inserted: in the range
21. Mappings M H S I I S S B Domain: Range: Transformation = { 1,2 } , { 2, } , { 3,1 } , { 4,4 } , { ,3 } Note: this is NOT a tai map. 1 1 2 2 3 3 4 4
22. The sets TR: Transformations M: Map C: change Cost =1 EX: exact match Cost = 0 I: Insertion Cost = 1 D: deletion Cost= 1 TR = EX + C + I + D M = EX + C M H S I I S S B Domain: Range: 1 1 2 2 3 3 4 4
31. Practice All possible combinations of the set m1 and m2 in m3 gives same or less cost combined, than alone. SET1 COST SET2 COST SET3 COST DIFF EX 0 EX 0 EX 0 0 EX 0 C 1 C 1 0 EX 0 D 1 D 1 0 C 1 EX 0 C 1 0 C 1 C 1 C/EX 1/0 -1/-2 C 1 D 1 D 1 -1 I 1 EX 0 I 1 0 I 1 C 1 I 1 -1 I 1 D 1 None 0 -2 D 1 None 0 D 1 0 D 1 I 1 C/EX 1/0 -1/-2 None 0 I 1 I 1 0