Alejandro Alcalde

Graduado en Ingeniería Informática en la ETSIIT, Granada.

More Alejandro Alcalde's posts

My computer science final project was about building a dependency parser for Spanish. Writing the documentation I had to draw some trees representing a dependency graph and a visual explanation of what an SVM (Support Vector Machine ) is.

To draw all this pictures I’ve used Tikz, a LaTeX package. Here is the code:

Drawing a dependency tree with Tikz

Example 1

Here is the code:



\begin{dependency}[edge slant=15pt,label theme = simple, edge theme = iron]
  \begin{deptext}[column sep=1em]
    This \& time \& around \& , \& they \& 're \& moving \& even \& faster \&
    . \\
  \depedge[edge height=1.9cm]{7}{2}{TMOD}
  \depedge[edge start x offset=-4pt]{9}{8}{ADVMOD}


And the result:

Dependenty tree in tikz

Example 2



\begin{tikzpicture}[every node/.style={align=center},scale=.9]
    edge from parent/.style={
      draw,edge from parent
      path={(\tikzparentnode.south)-- +(0,-8pt)-| (\tikzchildnode)}
    frontier/.style={distance from root=208pt}, % Align leaf nodes
    level 1+/.style={level distance=18pt} % Distance between levels

   \Tree [.S
             [.NP Rolls-Royce\\NNP Motor\\NNP Cars\\NNPS Inc\\NNP ]
             [.VP said\\VBD
                [.SBAR [.none ]
                      [.NP it\\PRP ]
                      [. VP expects\\VBZ
                            [.NP its\\PRP\$ U.S\\NNP sales\\NNS ]
                            [.VP to\\TO
                               [.VP remain\\VB
                                  [.ADJP steady\\JJ ]
                                  [.PP at\\IN
                                        [.QP about\\IN 1200\\CD ]


Other Dependency Tree in tikz

Example 3

Finally, one last example:


  \begin{tikzpicture}[every node/.style={align=center},level distance=30pt]
    \tikzset{edge from parent/.append style={<-, >=latex,thick}}
   \Tree [.said\\VBD
             [.Inc.\\NNP Rolls-Royce\\NNP Motor\\NNP Cars\\NNPS ]
             [.expects\\VBZ it\\PRP
                   [.sales\\NNS its\\PRP\$ U.S\\NNP ]
                   [.at\\IN [.cars\\NNS [.about\\IN 1200\\CD ] ] ]
Yet another example of a Dependency tree in tikz

Drawing a Support Vector Machine In tikz

I’ve also had to draw a visual explanation of what a SVM is:



    leftNode/.style={circle,minimum width=.5ex, fill=none,draw},
    rightNode/.style={circle,minimum width=.5ex, fill=black,thick,draw},
    rightNodeInLine/.style={solid,circle,minimum width=.7ex, fill=black,thick,draw=white},
    leftNodeInLine/.style={solid,circle,minimum width=.7ex, fill=none,thick,draw},
        important line/.style={thick}, dashed line/.style={dashed, thin},
        every node/.style={color=black},
    \draw[dashed line, yshift=.7cm]
       (.2,.2) coordinate (sls) -- (2.5,2.5) coordinate (sle)
       node[solid,circle,minimum width=2.8ex,fill=none,thick,draw] (name) at (2,2){}
       node[leftNodeInLine] (name) at (2,2){}
       node[solid,circle,minimum width=2.8ex,fill=none,thick,draw] (name) at (1.5,1.5){}
       node[leftNodeInLine] (name) at (1.5,1.5){}
       node [above right] {$w\cdot x + b > 1$};

    \draw[important line]
       (.7,.7) coordinate (lines) -- (3,3) coordinate (linee)
       node [above right] {$w\cdot x + b = 0$};

    \draw[dashed line, xshift=.7cm]
       (.2,.2) coordinate (ils) -- (2.5,2.5) coordinate (ile)
       node[solid,circle,minimum width=2.8ex,fill=none,thick,draw] (name) at (1.8,1.8){}
       node[rightNodeInLine] (name) at (1.8,1.8){}
       node [above right] {$w\cdot x + b < -1$};

    \draw[very thick,<->] ($(sls)+(.2,.2)$) -- ($(ils)+(.2,.2)$)
       node[sloped,above, near end] {Margen};

    \foreach \Point in {(.9,2.4), (1.3,2.5), (1.3,2.1), (2,3), (1,2.9)}{
      \draw \Point node[leftNode]{};

    \foreach \Point in {(2.9,1.4), (2.3,.5), (3.3,.1), (2,0.9), (2.5,1)}{
      \draw \Point node[rightNode]{};
Support Vector Machine in Latex with Tikz


While writing this snippets, I had to ask some questions on, those questions can be found in the following links:


Maybe this posts are also worth reading