• Keine Ergebnisse gefunden

Conclusion and Limitations

Im Dokument Metric Learning for Structured Data (Seite 62-74)

0 2 4 6

·102 type

scope parent codePosition name className returnType externalDependencies numberOfEdges

normalized weight

Figure 3.3:The weights~λ after metric learning on the affineedit distance. The weights were normalized by their frequency in the dataset.

reduced to zero, whereas the scope and the type feature are strongly emphasized. This makes intuitive sense as the type feature is invariant against many stylistic choices and captures the local function of the current syntactic element, whereas the scope feature indicates the rough position in the tree of the current syntactic element. Less frequent elements such as name, className, and returnType, can fulfill auxiliary function and disambiguate special types of nodes, namely class declarations, method declarations, and variable declarations.

and corrected distances may differ significantly (refer e.g. to Nebel, Kaden, et al.2017).

Third, our proposed method is relatively slow because each gradient step requires us to compute the gradients of all pairwise distances in the data set, which is only feasible for small datasets and a small number of gradient steps. Fourth, there is no guarantee regarding the approximation quality of the softmin-approximatededit distance. While we have shown that a single softmin application approximates the actual minimum, approximation errors may accumulate over the computation, leading to higher errors for longer inputsequences. Fifth, we are currently limited tosequence edit distances, which can not directly process tree or graph data. In the next section, we will address all of these limitations with an extended metric learning scheme that works ontrees.

4

T R E E E D I T D I S TA N C E L E A R N I N G

Summary: Trees are versatile data structures, which can be used to model syntax of natural and formal languages as well as biological data such as RNA secondary structures or glycan molecules. In all these cases, the tree edit distance offers an interpretable and actionable metric, which is useful for various downstream applications. However, the tree edit distance may be misleading if its parameters do not fit the task at hand. In this chapter, we present embedding edit distance learning (BEDL), an effective and scalable tree edit distance learning approach. In our evaluation on datasets from natural language processing, biology, and intelligent tutoring systems we demonstrate that our method can not only improve the default tree edit distance, but can also outperform the state-of-the-art.

Publications: This chapter is based on the following publications.

• Paaßen, Benjamin (2018).Revisiting the tree edit distance and its backtracing: A tutorial.

arXiv:1805.06869 [cs.DS].

• Paaßen, Benjamin, Claudio Gallicchio, et al. (2018). “Tree Edit Distance Learning via Adaptive Symbol Embeddings”. In:Proceedings of the 35th International Conference on Machine Learning (ICML 2018). (Stockholm, Sweden). Ed. by Jennifer Dy and Andreas Krause. Vol. 80. Proceedings of Machine Learning Research, pp. 3973–3982.

u r l:http://proceedings.mlr.press/v80/paassen18a.html.

Source Code: The Java(R) source code for the tree edit distance andcooptimalfrequency matrix computation is available athttps://openresearch.cit-ec.de/projects/tcs.

The Java(R) source code for median generalized vector quantization is available at https://gitlab.ub.uni-bielefeld.de/bpaassen/median_relational_glvq

The MATLAB(R) source code for tree edit distance learning is available at http:

//doi.org/10.4119/unibi/2919994.

Trees occur in many shapes across various application domains, such as syntax trees of natural language (Socher, Perelygin, et al.2013), syntax trees of programming languages (Rivers and Koedinger2015), or descriptors of RNA secondary structures and glycan molecules in biology (Akutsu2010). In all these areas, thetree edit distance(Zhang and Shasha 1989) is a useful measure of distance, as it can support information retrieval and other downstream tasks (Akutsu 2010). For example, the tree edit distance has achieved increasing popularity in recent years in the field of intelligent tutoring systems for computer programming (Mokbel, Gross, et al. 2013; Gross, Mokbel, et al.2014; Price, Dong, and Lipovac 2017; Rivers and Koedinger 2015). In such systems, the tree edit distance can pinpoint exactly which nodes in an abstract syntax tree of a student’s current program have to be changed in order to arrive at a correct solution, and we can use these editsto guide a student through a programming task (Mokbel, Gross, et al.

2013; Gross, Mokbel, et al.2014; Price, Dong, and Lipovac2017; Rivers and Koedinger 2015).

As withsequence edit distances, thetree edit distanceis only useful if itscost function fits the task at hand. Per default, thetree edit distanceregards all possibletreenodes as equidistant, which may be misleading for all the domains above. In particular, natural language words may have overlapping semantics (Pennington, Socher, and Manning2014;

Socher, Perelygin, et al.2013), glycan molecule descriptors may be referring to biologically similar elements (Gallicchio and Micheli2013), and syntactic nodes in computer programs may fulfill the same or similar functions (Paaßen, Jensen, and Hammer2016), in which case the pairwise replacement costs should be lowered. This begs the question how the tree edit distancecan beadaptedto be better suited for the domain and task at hand.

In this chapter, we propose a novel method to learn thetree edit distancethat goes beyond the state of the art ofgood edit similarity learning(GESL, Bellet, Habrard, and Sebban2012, also refer to Section2.4.1) in several respects.

• We consider allcooptimalpairwisetree mappingsinstead of just onetree mapping by means of a novel forward-backward algorithm.

• We select reference pairs for metric learning in a principled fashion based on learning vector quantizationprototypes for each class instead of ad-hoc selection schemes.

• Most importantly, we learn an embedding of the syntactic elements oftreesinstead of direct cost parameters, thus guaranteeing metric properties and higher efficiency for large alphabets.

We call our resulting metric learning approachembeddingeditdistancelearning(BEDL).

In our evaluation, we show thatBEDLoutperformsGESLin terms of classification accuracy across several classifiers and several real-world datasets from natural language processing, biology, and intelligent tutoring systems. We also demonstrate that BEDL can be scaled up to a large natural language processing dataset. In the next section, we describeBEDLin detail, before we continue to our experimental evaluation.

4.1 m e t h o d

Our aim is to adapt thecost functionof thetree edit distanceof Zhang and Shasha (1989) to improve the accuracy of a classifier based on thisedit distance. More specifically, we intend to improve the accuracy of a median generalized learning vector quantization (MGLVQ) model. For our purposes, MGLVQ has two key advantages compared to RGLVQ, which we used in the previous chapter. First, MGLVQ does not require an Euclidean distance as input such that we can avoid eigenvalue correction. Second, MGLVQrepresentsprototypessparsely by setting eachprototypeto a single datapoint.

As such, we only need to consider linearly manydistancevalues to optimize theGLVQ cost functionin Equation2.28, namely the data-to-prototype distances.

More precisely, assume that we wish to optimize the parameters~λof thecost function c~λ via gradient-based techniques on theGLVQ cost functionEGLVQ with the gradient3.2.

To compute this gradient, we require thetree edit distancegradients∇~

λd+i and∇~

λdi . Computing these gradients is our next step. To do so, we decompose thetree edit distance into a scalar product oftree mappingmatrices and pairwise costs.

Co-Optimal Frequency Matrices

Our decomposition is similar to theGESLapproach of Bellet, Habrard, and Sebban (2012, also refer to Section2.4.1). However, in contrast to their approach, we consider not only a single tree mappingmatrix, but an average of all cooptimal tree mappingmatrices.

Recall that we denote thetree edit distance with respect to acost function cas dc (refer to Definition 2.12), thetree mapping edit distanceas Dc (refer to Definition2.14), and the tree mappingmatrix with respect to atree mappingMbetween twotreesx˜ and ˜yas P(M, ˜x, ˜y)(refer to Definition2.16). We define thecooptimalfrequency matrix as follows.

Definition 4.1 (Co-optimal Frequency Matrix). Let ˜x and ˜ybetreesover somealphabet A, let Mbe atree mappingbetween ˜x and ˜y, and letcbe acost functionoverA.

Further, letM(c, ˜x, ˜y)be the set of allcooptimal tree mappingsbetween ˜xand ˜y, i.e.

alltree mappingsM such thatc(M, ˜x, ˜y) =Dc(x, ˜˜ y).

We define thecooptimalfrequency matrixPc(x, ˜˜ y)as the|x˜| × |y˜|matrix Pc(x, ˜˜ y):= M∈M(c, ˜x, ˜y)P(M, ˜x, ˜y)

|M(c, ˜x, ˜y)| (4.1)

In other words, thecooptimalfrequency matrixPc(x, ˜˜ y)is defined as the averagetree mapping matrixP(M, ˜x, ˜y)for allcooptimal tree mappings M. As an example, consider the trees x˜ = a(b(c,d),e)and ˜y = f(g). Allcooptimal tree mappings between ˜x and

˜

y according to default costs, along with the respective tree mapping matrix and the resultingcooptimalfrequency matrix are listed in Figure4.1.

Using the concepts oftree mappingmatrices andcooptimalfrequency matrices, we obtain the following decomposition for thetree edit distance.

Theorem 4.1. Letx and˜ y be˜ treesover somealphabetAand let c be acost functionoverA. Then, if c is non-negative, self-equal, and conforms to the triangular inequality, it holds:

dc(x, ˜˜ y) =

|x˜| i

=1

|y˜| j

=1

Pc(x, ˜˜ y)i,j·c(xi,yj) (4.2)

+

|x˜| i

=1

1−

|y˜| j

=1

Pc(x, ˜˜ y)i,j·c(xi,−) +

|y˜| j

=1

1−

|x˜| i

=1

Pc(x, ˜˜ y)i,j·c(−,yj)

Proof. First, Theorem2.5implies that dc(x, ˜˜ y) =Dc(x, ˜˜ y).

Further, note that for anyM ∈ M(c, ˜x, ˜y)it holds:c(M, ˜x, ˜y) =Dc(x, ˜˜ y). Accordingly, we obtain:

dc(x, ˜˜ y) = M∈M(c, ˜x, ˜y)c(M, ˜x, ˜y)

|M(c, ˜x, ˜y)|

By virtue of Equation2.26we obtain:

dc(x, ˜˜ y) = 1

|M(c, ˜x, ˜y)|·

M∈M(c, ˜x, ˜y)

|x˜| i

=1

|y˜|

j=1

P(M, ˜x, ˜y)i,j·c(xi,yj)

+

|x˜| i

=1

1−

|y˜| j

=1

P(M, ˜x, ˜y)i,j·c(xi,−) +

|y˜| j

=1

1−

|x˜| i

=1

P(M, ˜x, ˜y)i,j·c(−,yj)

a e b

d c

f g

M={(1, 1),(2, 2)}

i\j 1 2

1 1 0

2 0 1

3 0 0

4 0 0

5 0 0

P(M, ˜x, ˜y)

a e b

d c

f g

M= {(1, 1),(3, 2)}

i\j 1 2

1 1 0

2 0 0

3 0 1

4 0 0

5 0 0

P(M, ˜x, ˜y)

a e b

d c

f g

M= {(1, 1),(4, 2)}

i\j 1 2

1 1 0

2 0 0

3 0 0

4 0 1

5 0 0

P(M, ˜x, ˜y)

a e b

d c

f g

M={(1, 1),(5, 2)}

i\j 1 2

1 1 0

2 0 0

3 0 0

4 0 0

5 0 1

P(M, ˜x, ˜y)

a e b

d c

f g

M= {(2, 1),(3, 2)}

i\j 1 2

1 0 0

2 1 0

3 0 1

4 0 0

5 0 0

P(M, ˜x, ˜y)

a e b

d c

f g

M= {(2, 1),(4, 2)}

i\j 1 2

1 0 0

2 1 0

3 0 0

4 0 1

5 0 0

P(M, ˜x, ˜y)

i\j 1 2 1 2/3 0 2 1/3 1/6

3 0 1/3

4 0 1/3

5 0 1/6

Pc(x, ˜˜ y)

Figure 4.1:Allcooptimal tree mappingsbetween thetreesx˜=a(b(c,d),e)and ˜y=f(g) accord-ing to default costs (top and middle), the correspondaccord-ingtree mappingmatricesP(M, ˜x, ˜y)(below thetree mappingdiagrams), and the resultingcooptimalfrequency matrixPc(x, ˜˜ y)(bottom).

which can be re-written into Equation4.2, which completes the proof.

Note that it is not trivial to compute thecooptimal frequency matrix because the set M(c, ˜x, ˜y) may have exponential size. To address this issue, we introduce a novel forward-backward algorithm.

Theorem 4.2. Let x and˜ y be˜ trees over somealphabet Aand let c be acost function overA that conforms to the triangular inequality. Then, Algorithm4.1computesPc(x, ˜˜ y)· |M(c, ˜x, ˜y)|

as first output and|M(c, ˜x, ˜y)|as second output. Further, Algorithm4.1runs inO(|x˜|6· |y˜|6) time complexity andO(|x˜|2· |y˜|2)space complexity in the worst case.

Proof. Refer to AppendixA.13.

Algorithm 4.1An algorithm that computes the matrixPc(x, ˜˜ y)for two giventreesx˜and ˜y and acost functionc. More specifically, the first output argument isPc(x, ˜˜ y)· |M(c, ˜x, ˜y)|, and the second output argument is|M(c, ˜x, ˜y)|. For the forward and backward algorithm, refer to AppendixA.13.

1: function c o o p t i m a l s(Two trees x˜ and ˜y, the matrices d and D after executing algorithm2.1, and acost functionc)

2: (C,A)← f o r wa r d( ˜x, ˜y,d,D,c). .Refer to AlgorithmA.1.

3: B← b a c k wa r d( ˜x, ˜y,d,D,c,C). .Refer to AlgorithmA.2.

4: InitializeΓas a |x˜| × |y˜|matrix of zeros.

5: for(i,j)∈Cdo

6: ifi=|x˜|+1∨j=|y˜|+1then

7: continue

8: end if

9: if rlx˜(i) =|x˜| ∧rly˜(j) =|y˜|∨c(xi,yj) =c(xi,−) +c(−,yj)then

10: ifDi,j =Di+1,j+1+c(xi,yj)then

11: Γi,jΓi,j+Ai,j·Bi+1,j+1.

12: end if

13: else

14: ifDi,j =Drlx˜(i)+1,rly˜(j)+1+di,j then

15: γAi,j·Brlx˜(i)+1,rly˜(j)+1.

16: Compute D0 andd0 via Algorithm2.1for the subtrees ˜xi and ˜yj.

17: D01,2∞. D2,10∞.

18: (Γ0,|M(c, ˜xi, ˜yj)|)← c o o p t i m a l s( ˜xi, ˜yj,D0,d0,c).

19: fori0 ←1, . . . ,|x˜i|do

20: forj0 ←1, . . . ,|y˜j|do

21: Γi+i01,j+j01Γi+i01,j+j01+Γ0i0,j0·γ.

22: end for

23: end for

24: end if

25: end if

26: end for

27: return(Γ,A|x˜|+1,|y˜|+1).

28: end function

In rough terms, Algorithm4.1works as follows. We first compute the matrixA, where Ai,j essentially contains the number ofcooptimal tree mappings between ˜x and ˜y up

to nodesxi and yj respectively. Then, we compute the matrixB, where Bi,j essentially contains the number ofcooptimal tree mappingsbetween ˜x and ˜y, starting from nodesxi andyj respectively. Accordingly, the number ofcooptimal tree mappingswhich contain the pairing (i,j) can be computed as Γi,j = Ai,j ·Bi+1,j+1, as is visible in line 11 of Algorithm4.1. What complicates this process, however, is that we also need to compute cooptimal tree mappingsbetween subtrees, which are recursively computed in lines 15-23 of Algorithm4.1. After executing the algorithm, the desired frequency matrix Pc(x, ˜˜ y) can easily be computed asΓ/A|x˜|+1,|y˜|+1, where / denotes the element-wise division.

Note that the version of the algorithm presented here is dedicated to minimize space complexity. By additionally tabulatingΓfor all subtrees, space complexity rises toO(|x˜|4· |y˜|4)in the worst case, but runtime complexity is reduced to O(|x˜|3· |y˜|3). Another point to note is that the worst case for this algorithm is quite unlikely. First, both inputtreeswould have to be left-heavy, such as in the worst case for the originaltree edit distance(Zhang and Shasha1989). Second, in every step of the computation, multiple options have to becooptimal, which only occurs in degenerate cases where, for example, the deletion or insertion cost for all symbols is zero.

After obtaining the cooptimalfrequency matrixPc(x, ˜˜ y), we can utilize the decom-position above to compute the gradient of the tree edit distance dc~λ with respect to the parameters~λ. Similar to Bellet, Habrard, and Sebban (2012), we assume that the cooptimalfrequency matricesPc~

λ(x, ˜˜ y)stay constant under changes of~λ. Thus, we obtain the gradient:

~

λdc~λ(x, ˜˜ y)

const.Pc~λ

=

|x˜| i

=1

|y˜| j

=1

Pc~

λ(x, ˜˜ y)i,j· ∇~

λc~λ(xi,yj) (4.3)

+

|x˜| i

=1

1−

|y˜| j

=1

Pc~

λ(x, ˜˜ y)i,j· ∇~

λc~

λ(xi,−) +

|y˜|

j=1

1−

|x˜| i

=1

Pc~

λ(x, ˜˜ y)i,j· ∇~

λc~

λ(−,yj) This gradient expression is efficiently computable and permits optimization via gradient-based techniques, such as stochastic gradient descent or L-BFGS (Liu and Nocedal1989).

Note that optimizing the parameters~λwith respect to theGLVQ cost function 2.28 may yield atree edit distanceunder which a betterMGLVQmodel is possible. Therefore, we recommend an alternating optimization scheme with two steps, namelyMGLVQand metric learning, which are iterated until convergence. This yields Algorithm4.2.

Algorithm 4.2Thetree edit distancelearning algorithm for arbitrary parameters~λ.

1: function t e d_l e a r n(A dataset of trees x˜1, . . . , ˜xM over some alphabet A, class labelsy1, . . . ,yM, no. ofprototypes K, acost functionc~λ, and initial parameters~λ)

2: whileEhas changeddo

3: Compute pairwisetree edit distancesDi,j =dc~

λ(x˜i, ˜yj)via Algorithm2.1.

4: (w1, . . . ,wK,E)←MGLVQforD.

5: ComputePc~λ(x˜i,wk)for alli,kvia Algorithm4.1.

6: Optimize~λwith respect to theGLVQ cost function Eusing Equation4.3.

7: end while

8: return(~λ,E).

9: end function

Regarding runtime complexity, computing all pairwise tree edit distance requires O(M2· |x˜|2· |y˜|2)steps, trainingMGLVQrequiresO(M2)steps, computing thecooptimal frequency matrices for all datapoint-prototype pairs requires O(M· |x˜|6· |y˜|6) in the worst case, after which each gradient computation according to Equations3.2and4.3 requires only O(M· |x˜| · |y˜|) steps. In terms of space, we requireO(M2) to represent the pairwisedistancematrix andO(|x˜|2· |y˜|2)for computing thecooptimalfrequency matrices. Therefore, assuming a constant number of iterations τ, we obtain an overall runtime complexity in the order of O(τ·M· |x˜|2· |y˜|2·(M+|x˜|4· |y˜|4))and an overall space complexity ofO(M2+|x˜|2· |y˜|2).

Note that the decomposition in Equation4.2only holds under the assumption thatc~λ

is non-negative, self-equal, and fulfills the triangular inequality. Unfortunately, ensuring metric axioms on c~λ imposes additional constraints on the optimization in line 6 of Algorithm4.2, which prevent us from directly applying gradient-based solvers. To avoid such explicit constraints, we introduce an additional innovation, namely a representation of thealphabetAvia symbol embeddings.

Adaptive Symbol Embeddings

In this section, we introducesymbol embeddings, that is, we represent the elements of an alphabet Aby vectors in anEuclideanspace. The main motivation for this alternative representation is that theEuclidean distanceguarantees pseudo-metric properties, which in turn ensure that the assumptions of the tree edit distancealgorithm as well as the decomposition in Equation4.2are fulfilled without having to constrain the optimization process. Another advantage is that we can potentially interpret the positions of the vectorial representations and thus gain additional insight regarding the role different symbols play.

We define a symbol embedding as follows.

Definition 4.2 (Symbol Embedding). LetAbe analphabetwith−∈ A/ . Then, asymbol embeddingofAis defined as a mappingφ:A →Rm for some m∈ {1, . . . ,|A|}. For any symbol embedding, we defineφ(−):=~0, where~0 is them-dimensional zero-vector.

Further, we define thecost functioncφ with respect to the symbol embeddingφas follows.

cφ(x,y):= kφ(x)−φ(y)k

In other words,cφis anEuclidean distanceonA ∪ {−} with the spatial mappingφ.

Note that the gradient ofcφ(x,y)with respect to φ(x)is given as:

φ(x)cφ(x,y) =∇φ(x) q

φ(x)−φ(y)>· φ(x)−φ(y)

= ∇φ(x) φ(x)−φ(y)>· φ(x)−φ(y)

q

φ(x)−φ(y)>· φ(x)−φ(y)

= φ(x)−φ(y)

kφ(x)−φ(y)k (4.4)

Plugging this result into Equation4.3, we obtain a gradient of thetree edit distance with respect to the embedding vectors for every symbol, under the assumption that the

cooptimalfrequency matrices stay constant.

φ(x)d˜cφ(x, ˜˜ y)const.=Pcφ (4.5)

|x˜| i

=1

δ(x,xi|y˜|

j

=1

Pcφ(x, ˜˜ y)i,j· φ(x)−φ(yj)

kφ(x)−φ(yj)k+1

|y˜|

j=1

Pcφ(x, ˜˜ y)i,j· φ(x) kφ(x)k

+

|y˜|

j=1

δ(x,yj|x˜|

i

=1

Pcφ(x, ˜˜ y)i,j· φ(x)−φ(xi)

kφ(x)−φ(xi)k+1−

|x˜| i

=1

Pcφ(x, ˜˜ y)i,j· φ(x) kφ(x)k

whereδ is the Kronecker-Delta, i.e.:δ(x,y) =1 ifx=y and 0 otherwise.

Finally, we can plug this gradient into Equation3.2and thus obtain a gradient of the GLVQ cost functionwith respect to the rows of our symbol embedding matrix. Using this gradient, we can learn a symbol embedding via any gradient-based technique.

Two challenges remain in this setup. First, we have to obtain a viable initialization for the embeddingφ. In this regard, we suggest to use an initialization, which yields the default edit costs of thetreeandsequence edit distance, that is, c(x,y)should be 1 in all cases, except ifx=y, where it is zero. Indeed, such an initialization exists.

Theorem 4.3. LetA={x1, . . . ,xn}be analphabet. Then, the following functionφ:A →Rn with

φ(xi)j :=





0 if j>i ρj if j<i ρi·(i+1) if j=i

where (4.6)

ρi =1/

q

2·i·(i+1) (4.7)

is a symbol embedding ofAsuch that:

cφ(x,y) =

(0 if x =y 1 otherwise Proof. Refer to AppendixA.14.

As an example, consider the two-dimensional embedding generated for the alphabet A={a,b}in Figure4.2.

The second challenge concerns the handling of the following degenerate cases for the embeddingφ. First,cφ is non-differentiable with respect toφ(x)at the point φ(x) =~0.

However, this may not pose a problem as such. In particular,φ(x) =~0 implies thatx is unimportant to distinguish betweentrees, which is an interesting observation to make.

Therefore, we simply extend the definition of the gradient ofcφ to be zero atφ(x) =~0.

Second, φ may “flatten” the data too much, in the sense that the matrix Φ = φ(x1), . . . ,φ(xn) for the alphabetA= {x1, . . . ,xn}becomes low rank. Such oversim-plification effects have previously been observed ingeneralized matrix learning vector quantization(GMLVQ) as well (Schneider, Bunte, et al.2010). Indeed, we can make the

1 1

φ(−) = 0

0

φ(a) = 1

0 φ(b) =

1

2 3 2

!

Figure 4.2: The initial 2-dimensional embedding of the alphabetA ={a,b}. This embedding ensures that the pairwise costs of all symbols, including the-symbol, is 1.

similarity between GMLVQand our metric learning scheme more obvious by re-writing cφ(xi,xj)as follows.

cφ(xi,xj) = q

φ(xi)−φ(xj)>· φ(xi)−φ(xj)

=

q Φ·eiΦ·ej>

· Φ·eiΦ·ej

= q

ei−ej>

·Φ>·Φ· ei−ej whereei is theith unit vector andej is the jth unit vector.

In this representation it is obvious thatΦplays the role of theprojection matrixin GMLVQ(compare to Equation2.29). As Biehl et al. (2015) have shown,tends to very low-rank solutions, which may be overly simplistic in practical cases. To prevent such a low-rank solution, we follow the recommendation of Schneider, Bunte, et al. (2010) and add the regularization term −λ·log(det(Φ·Φ>))for some constant λ>0 to theGLVQ cost function 2.28, which becomes large if any eigenvalue of Φ·Φ>gets close to zero.

The gradient of the regularization with respect toΦis theMoore-Penrose Pseudo-Inverse

λ·Φ (Schneider, Bunte, et al.2010; Petersen and Pedersen2012).

Finally, the GLVQ cost function 2.28 is inherently scale-invariant in terms of the distances, that is, if we multiply all pairwise distances with some constant, the loss will stay the same. Given this degree of freedom, we may converge to an an embedding with needlessly large scaling. To prevent such a case, we additionally add the regularization term λ· kΦkF, wherekΦkFis the Frobenius norm ofΦ.

This concludes our basic setup fortree edit distancelearning via adaptive symbol embeddings. We call our approachembeddingeditdistancelearning(BEDL).

Before we evaluateBEDLexperimentally, we wish to highlight one additional desir-able property of BEDL, namely that we can utilize alternative initializations and metrics if suitable for the domain at hand. For example, in the domain of natural language processing, we do not need to learn an embedding of words from scratch but can rely on existing word embeddings, such as GloVe (Pennington, Socher, and Manning2014).

We can then learn toadaptthe word embedding instead of learning it from scratch by only learning a linear transformation that maps the pre-existing word embedding into another space in which classification is simpler. Furthermore, for word embeddings, the cosine similarity is typically favored over theEuclideandistance (Pennington, Socher,

and Manning2014). We can include the cosine distance inBEDLeasily by re-defining thecost functioncφ,Ω as follows.

cφ,(x,y):= 1

1−s(φ(x),φ(y)) where (4.8) s(φ(x),φ(y)) = (·φ(x))>··φ(y)

k·φ(x)k · k·φ(y)k For the gradient, we obtain:

cφ,Ω(x,y) =−1

2∇s(φ(x),φ(y))

=−1

2 ··φ(x)·φ(y)>+φ(y)·φ(x)>

k·φ(x)k · k·φ(y)k +1

2 ··s(φ(x),φ(y))·hφ(x)·φ(x)>

k·φ(x)k2 +φ(y)·φ(y)>

k·φ(y)k2 i

We will utilize both the basic Euclidean version ofBEDL and the cosine distance variation in our next section, in which we evaluateBEDLexperimentally.

Im Dokument Metric Learning for Structured Data (Seite 62-74)