Skip to content

Instantly share code, notes, and snippets.

@tetsuok
Last active December 14, 2015 10:59
Show Gist options
  • Select an option

  • Save tetsuok/5075700 to your computer and use it in GitHub Desktop.

Select an option

Save tetsuok/5075700 to your computer and use it in GitHub Desktop.
Eisner First-order rules of the Eisner algorithm for projective dependency parsing, and its sample run.
*.aux
*.log
*.pdf
*.dvi
*.snm
*.nav
*.synctex*
*.toc
*.out
auto
\ProvidesPackage{eisner-deprule}[2013/03/03 v0.1 Macros to draw eisner rectangles]
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\RequirePackage{tikz,environ}
\usetikzlibrary{calc}
\tikzset{
deparc/.style={very thick,draw=black},
tri/.style={fill=blue},
incomplete/.style={fill=yellow},
next/.style={fill=green!80},
complete/.style={fill=green!80},
transition/.style={->,line width=3},
}
\def\eisnerxoffset{0.1}
\def\eisneryoffset{0.5}
\def\eisnertriwidth{0.7}
\def\eisnercompleteheight{2.5}
\def\eisnerincompleteheight{1.3}
\def\righttri#1#2#3{
\draw [very thick] (#1,\eisneryoffset) -- (#1,#2) -- (#3,\eisneryoffset) -- cycle;
}
\def\fillrighttri#1#2#3{
\filldraw [very thick,fill=green!80] (#1,\eisneryoffset) -- (#1,#2) -- (#3,\eisneryoffset) -- cycle;
}
% x coord, height, step
\def\leftcorner#1{ \fillrighttri{#1+\eisnerxoffset}{\eisnercompleteheight}{#1+\eisnertriwidth}; }
\def\rightcorner#1{ \fillrighttri{#1-\eisnerxoffset}{\eisnercompleteheight}{#1-\eisnertriwidth}; }
% x origin
\def\splittri#1{
\fillrighttri{#1 - \eisnerxoffset}{\eisnercompleteheight}{#1 - \eisnertriwidth}; % left
\fillrighttri{#1 + \eisnerxoffset}{\eisnercompleteheight}{#1 + \eisnertriwidth}; % right
}
% x1, y1, x2, y2, step size for x1 and x2
\def\incomplete#1#2#3#4#5{
\filldraw [very thick,fill=yellow] (#1+#5,\eisneryoffset) -- (#1+#5, #2) -- (#3-#5,#4) -- (#3-#5,\eisneryoffset) -- cycle;
}
\def\downincomplete#1#2{
\incomplete{#1}{\eisnercompleteheight}{#2}{\eisnerincompleteheight}{\eisnerxoffset};
\draw [->,deparc] ($(#1+.1,\eisneryoffset) + (.1,.1)$) .. controls +(1,1) and +(-1,1) .. ($(#2-.1,\eisneryoffset) + (-.1,.1)$);
}
% x1, x2
\def\upincomplete#1#2{
\incomplete{#1}{\eisnerincompleteheight}{#2}{\eisnercompleteheight}{\eisnerxoffset};
\draw [<-,deparc] ($(#1+.1,\eisneryoffset) + (.1,.1)$) .. controls +(.5,.5) and +(-.5,.5) .. ($(#2-.1,\eisneryoffset) + (-.1,.1)$);
}
% #3: color
\def\upcomplete#1#2#3{
\filldraw[very thick, fill=#3] (#1- \eisnertriwidth,\eisneryoffset) -- (#2-\eisnerxoffset,\eisnercompleteheight) -- (#2-\eisnerxoffset,\eisneryoffset) -- cycle;
}
\def\downcomplete#1#2#3{
\filldraw[very thick, fill=#3] (#1+\eisnerxoffset,\eisneryoffset) -- (#1+\eisnerxoffset,\eisnercompleteheight) -- (#2+\eisnertriwidth,\eisneryoffset) -- cycle;
}
\documentclass{standalone}
\usepackage{eisner-deprule}
\begin{document}
%
\begin{tikzpicture}[
deparc/.style={very thick},
tri/.style={fill=blue},
incomplete/.style={fill=yellow},
next/.style={fill=green!80},
complete/.style={fill=red!80},
transition/.style={->,line width=3},
]
\def\setupone{
\coordinate (c) at (3,-1);
\coordinate [label=below:$s$] (s) at (-2,0);
\coordinate [label=below:$h_1$] (h1l) at (0,0);
\coordinate [label=above:$h_1$] (h1lu) at (0,2);
\coordinate [label=below:$h_1$] (h1r) at (.5,0);
\coordinate [label=above:$h_1$] (h1ru) at (.5,2);
\coordinate [label=below:$r$] (r) at (2.5,0);
\coordinate [label=below:$r+1$] (r1) at (3.5,0);
\coordinate [label=below:$h_2$] (h2l) at (5.5,0);
\coordinate [label=above:$h_2$] (h2lu) at (5.5,2);
\coordinate [label=below:$h_2$] (h2r) at (6,0);
\coordinate [label=above:$h_2$] (h2ru) at (6,2);
\coordinate [label=below:$t$] (t) at (8,0);
}
\def\setuptwo{
\coordinate (c) at (3,-1);
\coordinate [label=below:$s$] (s) at (-2,0);
\coordinate [label=below:$h_1$] (h1l) at (0,0);
\coordinate [label=above:$h_1$] (h1lu) at (0,2);
\coordinate [label=below:$h_1$] (h1r) at (.5,0);
\coordinate [label=above:$h_1$] (h1ru) at (.5,2);
\coordinate [label=below:$h_2$] (h2l) at (5.5,0);
\coordinate [label=above:$h_2$] (h2lu) at (5.5,1);
\coordinate [label=below:$h_2$] (h2r) at (6,0);
\coordinate [label=above:$h_2$] (h2ru) at (6,2);
\coordinate [label=below:$t$] (t) at (8,0);
}
\def\setupthree{
\coordinate (c) at (3,-1);
\coordinate [label=below:$s$] (s) at (-2,0);
\coordinate [label=below:$h_1$] (h1l) at (0,0);
\coordinate [label=above:$h_1$] (h1lu) at (0,2);
\coordinate [label=below:$h_1$] (h1r) at (.5,0);
\coordinate [label=above:$h_1$] (h1ru) at (.5,2);
\coordinate [label=below:$t$] (t) at (8,0);
}
\begin{scope}[very thick]
\setupone
%
\draw (s) -- (h1l) -- (h1lu) -- cycle;
\filldraw [tri] (r) -- (h1r) -- (h1ru) -- cycle;
\filldraw [tri] (r1) -- (h2l) -- (h2lu) -- cycle;
\draw (t) -- (h2r) -- (h2ru) -- cycle;
%
% dependency arc
\draw [dotted, ->,deparc] ($(h1ru)+(0,.5)$) .. controls +(1,1.5) and +(-1,1.5) .. ($(h2lu) + (0,.5)$);
\draw [transition] (c) -- ($(c)+(0, -1)$);
\end{scope}
%
\begin{scope}[very thick,yshift=-5cm]
\setuptwo
\draw (s) -- (h1l) -- (h1lu) -- cycle;
\filldraw [incomplete] (h1r) -- (h1ru) -- (h2lu) -- (h2l) -- cycle;
\filldraw [next] (t) -- (h2r) -- (h2ru) -- cycle;
\draw [->,deparc] (h1r) .. controls +(1,1.5) and +(-1,1.5) .. ($(h2l) + (-.1,.1)$);
\draw [transition] (c) -- ($(c)+(0, -1)$);
\end{scope}
%
\begin{scope}[very thick,yshift=-10cm]
\setupthree
\draw (s) -- (h1l) -- (h1lu) -- cycle;
\filldraw [complete] (h1r) -- (h1ru) -- (t) -- cycle;
% \filldraw [next] (t) -- (h2r) -- (h2ru) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
\documentclass{standalone}
\usepackage{eisner-deprule}
\begin{document}
%
\begin{tikzpicture}
\def\setup{
\coordinate [label=below:\$] (root) at (0,0);
\coordinate [label=below:John] (john) at (2,0);
\coordinate [label=below:hit] (hit) at (4,0);
\coordinate [label=below:the] (the) at (6,0);
\coordinate [label=below:ball] (ball) at (8,0);
\coordinate [label=below:with] (with) at (10,0);
\coordinate [label=below:the] (the) at (12,0);
\coordinate [label=below:bat] (bat) at (14,0);
}
\begin{scope}
\setup
\leftcorner{0};
\foreach \x in {2, 4, 6, 8, 10, 12, 14 }{
\splittri{\x};
}
\end{scope}
%
\begin{scope}[yshift=-5cm]
\setup;
\leftcorner{0};
\rightcorner{2};
\upincomplete{2}{4};
\leftcorner{4};
\rightcorner{6};
\upincomplete{6}{8};
\leftcorner{8};
\splittri{10};
\rightcorner{12};
\upincomplete{12}{14};
\leftcorner{14};
\end{scope}
%
\begin{scope}[yshift=-10cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{red!80};
\leftcorner{4};
\upcomplete{6}{8}{red!80};
\leftcorner{8};
\splittri{10};
\upcomplete{12}{14}{red!80};
\leftcorner{14};
\end{scope}
%
\begin{scope}[yshift=-15cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downincomplete{4}{8};
\leftcorner{8};
\rightcorner{10};
\downincomplete{10}{14};
\leftcorner{14};
\end{scope}
%
\begin{scope}[yshift=-20cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downcomplete{4}{8}{red!80};
\rightcorner{10};
\downcomplete{10}{14}{red!80};
\end{scope}
%
\begin{scope}[yshift=-25cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downincomplete{4}{10};
\downcomplete{10}{14}{green!80};
\end{scope}
%
\begin{scope}[yshift=-30cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downcomplete{4}{14}{red!80};
\end{scope}
%
\begin{scope}[yshift=-35cm]
\setup;
\downincomplete{0}{4};
\downcomplete{4}{14}{green!80};
\end{scope}
%
\begin{scope}[yshift=-40cm]
\setup;
\downcomplete{0}{14}{red!80};
\end{scope}
\end{tikzpicture}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{eisner-deprule}
\def\setup{
\coordinate [label=below:\$] (root) at (0,0);
\coordinate [label=below:John] (john) at (2,0);
\coordinate [label=below:hit] (hit) at (4,0);
\coordinate [label=below:the] (the) at (6,0);
\coordinate [label=below:ball] (ball) at (8,0);
\coordinate [label=below:with] (with) at (10,0);
\coordinate [label=below:the] (the) at (12,0);
\coordinate [label=below:bat] (bat) at (14,0);
}
%
\newcommand{\scalesize}{0.74}
\begin{document}
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup
\leftcorner{0};
\foreach \x in {2, 4, 6, 8, 10, 12, 14 }{
\splittri{\x};
}
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup;
\leftcorner{0};
\rightcorner{2};
\upincomplete{2}{4};
\leftcorner{4};
\rightcorner{6};
\upincomplete{6}{8};
\leftcorner{8};
\splittri{10};
\rightcorner{12};
\upincomplete{12}{14};
\leftcorner{14};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{red!80};
\leftcorner{4};
\upcomplete{6}{8}{red!80};
\leftcorner{8};
\splittri{10};
\upcomplete{12}{14}{red!80};
\leftcorner{14};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downincomplete{4}{8};
\leftcorner{8};
\rightcorner{10};
\downincomplete{10}{14};
\leftcorner{14};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downcomplete{4}{8}{red!80};
\rightcorner{10};
\downcomplete{10}{14}{red!80};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downincomplete{4}{10};
\downcomplete{10}{14}{green!80};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downcomplete{4}{14}{red!80};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup;
\downincomplete{0}{4};
\downcomplete{4}{14}{green!80};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}[scale=\scalesize]
\setup;
\downcomplete{0}{14}{red!80};
\end{tikzpicture}
\end{frame}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
TEX = pdflatex
TARGET = slide.pdf eisner-firstorder.pdf sheheardnoise.pdf
all: $(TARGET)
clean:
-rm -f *.aux *.pdf *.log *.snm *.nav *.synctex* *.toc *.out
-rm -fr auto
%.pdf: %.tex
$(TEX) $<
\documentclass{standalone}
\usepackage{eisner-deprule}
\begin{document}
%
\begin{tikzpicture}
\def\setup{
\coordinate [label=below:\$] (root) at (0,0);
\coordinate [label=below:she] (she) at (2,0);
\coordinate [label=below:heard] (heard) at (4,0);
\coordinate [label=below:the] (the) at (6,0);
\coordinate [label=below:noise] (noise) at (8,0);
\coordinate [label=below:.] (period) at (10,-.2);
}
\begin{scope}
\setup;
\leftcorner{0};
\foreach \x in {2, 4, 6, 8, 10}{
\splittri{\x};
}
\end{scope}
%
\begin{scope}[yshift=-5cm]
\setup;
\leftcorner{0};
\upincomplete{2}{4};
\upincomplete{6}{8};
\rightcorner{2};
\leftcorner{4};
\rightcorner{6};
\leftcorner{8};
\splittri{10};
\end{scope}
%
\begin{scope}[yshift=-10cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{red!80};
\upcomplete{6}{8}{red!80};
\leftcorner{4};
\leftcorner{8};
\splittri{10};
\end{scope}
%
\begin{scope}[yshift=-15cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downincomplete{4}{8};
\leftcorner{8};
\splittri{10};
\end{scope}
%
\begin{scope}[yshift=-20cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downcomplete{4}{8}{red!80};
\splittri{10};
\end{scope}
%
\begin{scope}[yshift=-25cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downincomplete{4}{10};
\leftcorner{10};
\end{scope}
%
\begin{scope}[yshift=-30cm]
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downcomplete{4}{10}{red!80};
\end{scope}
%
\begin{scope}[yshift=-35cm]
\setup;
\downincomplete{0}{4};
\downcomplete{4}{10}{green!80};
\end{scope}
%
\begin{scope}[yshift=-40cm]
\setup;
\downcomplete{0}{10}{red!80};
\end{scope}
\end{tikzpicture}
\end{document}
%
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{eisner-deprule}
%
\def\setup{
\coordinate [label=below:\$] (root) at (0,0);
\coordinate [label=below:she] (she) at (2,0);
\coordinate [label=below:heard] (heard) at (4,0);
\coordinate [label=below:the] (the) at (6,0);
\coordinate [label=below:noise] (noise) at (8,0);
\coordinate [label=below:.] (period) at (10,-.2);
}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{scope}
\setup;
\leftcorner{0};
\foreach \x in {2, 4, 6, 8, 10}{
\splittri{\x};
}
\end{scope}
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}
\setup;
\leftcorner{0};
\upincomplete{2}{4};
\upincomplete{6}{8};
\rightcorner{2};
\leftcorner{4};
\rightcorner{6};
\leftcorner{8};
\splittri{10};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}
\setup;
\leftcorner{0};
\upcomplete{2}{4}{red!80};
\upcomplete{6}{8}{red!80};
\leftcorner{4};
\leftcorner{8};
\splittri{10};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downincomplete{4}{8};
\leftcorner{8};
\splittri{10};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downcomplete{4}{8}{red!80};
\splittri{10};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downincomplete{4}{10};
\leftcorner{10};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}
\setup;
\leftcorner{0};
\upcomplete{2}{4}{green!80};
\downcomplete{4}{10}{red!80};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}
\setup;
\downincomplete{0}{4};
\downcomplete{4}{10}{green!80};
\end{tikzpicture}
\end{frame}
%
\begin{frame}
\begin{tikzpicture}
\setup;
\downcomplete{0}{10}{red!80};
\end{tikzpicture}
\end{frame}
%
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment