2

Is there a sample code that draws something similar to the figure below ? The black images are pictures that Id like to insert. enter image description here

I have a sample code.

1) How do I change the rectangles into another shape ? Eg trapezoid / a rectangle without splitting.

2) How do I insert images where the text is

% System Combination
% Harish K Krishnamurthy <www.ece.neu.edu/~hkashyap/>
\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows}
\usepackage{amsmath,bm,times}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{comment}
:Title: System Combination
:Author: Harish K Krishnamurthy

A block diagram of system combination technique of combining several Automatic Speech Recognition Systems (ASRs) to determine best word sequence outputs is shown here. The training and validation phase are the important phases.

\end{comment}

\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command

\begin{document}
% Define the layers to draw the diagram
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

% Define block styles used later

\tikzstyle{sensor}=[draw, fill=blue!20, text width=5em, 
    text centered, minimum height=2.5em,drop shadow]
\tikzstyle{ann} = [above, text width=5em, text centered]
\tikzstyle{wa} = [sensor, text width=10em, fill=red!20, 
    minimum height=6em, rounded corners, drop shadow]
\tikzstyle{sc} = [sensor, text width=13em, fill=red!20, 
    minimum height=10em, rounded corners, drop shadow]

% Define distances for bordering
\def\blockdist{2.3}
\def\edgedist{2.5}

\begin{tikzpicture}[
  hid/.style 2 args={
    rectangle split,
    rectangle split horizontal,
    draw=#2,
    rectangle split parts=#1,
    fill=#2!20,
    outer sep=1mm}]
  % draw input nodes
  \foreach \i [count=\step from 1] in {the,blue,house,{{$<$eos$>$}}}
    \node (i\step) at (2*\step, -2) {\i};
  % draw output nodes
  \foreach \t [count=\step from 4] in {la,casa,azul,{{$<$eos$>$}}} {
    \node[align=center] (o\step) at (2*\step, +2.75) {\t};
  }
  % draw embedding and hidden layers for text input
  \foreach \step in {1,...,3} {
    \node[hid={3}{red}] (h\step) at (2*\step, 0) {};
    \node[hid={3}{red}] (e\step) at (2*\step, -1) {};    
    \draw[->] (i\step.north) -> (e\step.south);
    \draw[->] (e\step.north) -> (h\step.south);
  }
  % draw embedding and hidden layers for label input
  \foreach \step in {4,...,7} {
    \node[hid={3}{yellow}] (s\step) at (2*\step, 1.25) {};
    \node[hid={3}{blue}] (h\step) at (2*\step, 0) {};
    \node[hid={3}{blue}] (e\step) at (2*\step, -1) {};    
    \draw[->] (e\step.north) -> (h\step.south);
    \draw[->] (h\step.north) -> (s\step.south);
    \draw[->] (s\step.north) -> (o\step.south);
  }  
  % edge case: draw edge for special input token
  \draw[->] (i4.north) -> (e4.south);
  % draw recurrent links
  \foreach \step in {1,...,6} {
    \pgfmathtruncatemacro{\next}{add(\step,1)}
    \draw[->] (h\step.east) -> (h\next.west);
  }
  % draw predicted-labels-as-inputs links
  \foreach \step in {4,...,6} {
    \pgfmathtruncatemacro{\next}{add(\step,1)}
    \path (o\step.north) edge[->,out=45,in=225] (e\next.south);
  }
\end{tikzpicture}
\end{document}

enter image description here

  • 2
    Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE). This isn't a "Please do my work for me" site! What do you have so far? Try to create ... Do you know this site? Maybe a starting point. – Bobyandbob Oct 20 '17 at 11:45
  • good god. I would be dead if my life depended on latex. – Kong Oct 20 '17 at 12:15
  • 1
    1. Replace hid/.style 2 args={ rectangle split, rectangle split horizontal, draw=#2, rectangle split parts=#1, fill=#2!20, outer sep=1mm}] with hid/.style 2 args={ trapezium, trapezium angle=67.5, draw=#2, fill=#2!20, outer sep=1mm}] (see: tikz - trapezium node) 2.) Insert \includegraphics[width=0.1\textwidth]{example-image} instead of the text like house. (see: Drawing on an image with TikZ) – Bobyandbob Oct 20 '17 at 13:03
  • Sorry I should have been clearer. How do I select the type of shape I want for each shape ? The middle row needs to be a square and the lower rows a trapezoid. How do I change the option without changing every freaking object in the drawing ? – Kong Oct 20 '17 at 13:39
  • 1
    What about a new/second style? Add \tikzset{ trapez/.style 2 args={ trapezium, trapezium angle=#1, draw=#2, fill=#2!20, outer sep=1mm} } to your preamble and use \node[trapez={67.5}{red}] (e\step) at (2*\step, -1) {}; instead of \node[hid={3}{red}] (e\step) at (2*\step, -1) {}; – Bobyandbob Oct 20 '17 at 13:59
6

A step in the right direction...

\documentclass[tikz, margin=5]{standalone}
\usepackage[prefix=]{xcolor-material}
\usetikzlibrary{shapes.geometric,positioning,arrows.meta}
\renewcommand\familydefault\sfdefault
\tikzset{%
  coder/.style={
    shape=trapezium,
    fill=LightGreen,
    text=White
  },
  lstm/.style={
    shape=rectangle,
    fill=LightBlue,
    text=white,
    minimum width=2cm
  },
  image/.style={
    shape=rectangle,
    minimum size=1.5cm,
    draw=White,
    fill=Black
  },
  link/.style={
    ultra thick,
    ->
  },
  >=Triangle
}

\begin{document}
\begin{tikzpicture}
\foreach \i [count=\j from 0] in {1,...,4}{
  \tikzset{shift=(0:\j*3)}
  \node [lstm] (lstm-\i) {LSTM};
  \node [above=0.5cm of lstm-\i, coder] (decoder-\i) {DECODER};
  \node [below=0.5cm of lstm-\i, coder] (encoder-\i) {ENCODER};
  \node [image, above=0.25 of decoder-\i, shift=(45:0.5), 
    label={100:$x[\i]$}] {};
  \node [image, above=0.25 of decoder-\i, label={150:$\bar{x}[\i]$}] {};
  \node [image, below=0.25 of encoder-\i, label={270:$x[\j]$}] {};
  \draw [link] (encoder-\i) -- (lstm-\i);
  \draw [link] (lstm-\i) -- (decoder-\i);
  \ifnum\j>0
    \draw [link] (lstm-\j) -- (lstm-\i);
  \fi
}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.