PhD

The LaTeX sources of my Ph.D. thesis
git clone https://esimon.eu/repos/PhD.git
Log | Files | Refs | README | LICENSE

transe.tex (1341B)


      1 \begin{algorithmic}
      2 	\Function{TransE}{}
      3 		\FunctionInputs{}   \(\kbSet\) knowledge base
      4 		\FunctionInputs*{}  \(\gamma\) margin
      5 		\FunctionInputs*{}  \(d\) embedding dimension
      6 		\FunctionInputs*{}  \(b\) batch size
      7 		\FunctionOutputs{}  \(\mtrx{U}\) entity embeddings
      8 		\FunctionOutputs*{} \(\mtrx{V}\) relation embeddings
      9 		\State
     10 		\LComment{Initialization}
     11 		\State \(\mtrx{U} \gets \uniformDistribution_{|\entitySet|\times d}\left(-\frac{6}{\sqrt{d}}, \frac{6}{\sqrt{d}}\right)\)
     12 		\State \(\mtrx{V} \gets \uniformDistribution_{|\relationSet|\times d}\left(-\frac{6}{\sqrt{d}}, \frac{6}{\sqrt{d}}\right)\)
     13 		\State \(\forall r\in\relationSet: \vctr{v}_r \gets \vctr{v}_r / \|\vctr{v}_r\|_2\)
     14 		\LComment{Training}
     15 		\Loop
     16 			\State \(\forall e\in\entitySet: \vctr{u}_e \gets \vctr{u}_e / \|\vctr{u}_e\|_2\)
     17 			\State \(B \gets \emptyset\)
     18 			\For{\(i=1,\dotsc,b\)}
     19 				\State Sample \((e_1, r, e_2) \sim \uniformDistribution(\kbSet)\)
     20 				\State Sample \((e_1', e_2') \sim N(e_1, e_2)\)
     21 				\State \(B \gets B \cup \{(e_1, r, e_2, e_1', e_2')\}\)
     22 			\EndFor
     23 			\State Update \(\mtrx{U}\) and \(\mtrx{V}\) w.r.t.
     24 			\State \hspace{7mm}\(\displaystyle\nabla\sum_{\mathrlap{\hspace{-2mm}(e_1, r, e_2, e_1', e_2')\in B}}\loss{te}(e_1, r, e_2, e_1', e_2')\)
     25 		\EndLoop
     26 		\State \Output \(\mtrx{U}, \mtrx{V}\)
     27 	\EndFunction
     28 \end{algorithmic}