\section*{Program Summary}

\section{Introduction}
With the recent discovery of a bosonic resonance
\cite{Atlas:2012gk,CMS:2012gu} showing all the characteristics of the
SM Higgs boson a long search might soon come to a successful end.  In
contrast there are no hints for a signal of supersymmetric (SUSY)
particles or particles predicted by any other extension of the
standard model (SM)
\cite{:2012rz,Chatrchyan:2012jx,CMS-PAS-SUS-11-022,CMS-PAS-SUS-12-005,:2012mfa}.
Therefore, large areas of the parameter space of the simplest SUSY
models are excluded. The allowed mass spectra as well as the best fit
mass values to the data are pushed to higher and higher values
\cite{pMSSM}.  This has lead to an increasing interest in the study of
SUSY models which provide new features. For instance, models with
broken $R$-parity \cite{rpv,rpvsearches} or compressed spectra
\cite{compressed} might be able to hide much better at the LHC, while
for other models high mass spectra are a much more natural feature
than this is the case in the minimal-supersymmetric standard model
(MSSM) \cite{finetuning}.

However, bounds on the masses and couplings of beyond the SM
(BSM) models follow not only from direct searches at colliders. New
particles also have an impact on SM processes
via virtual quantum corrections, leading in many
instances to sizable deviations from the SM expectations. This holds
in particular for the anomalous magnetic moment of the muon
\cite{Stockinger:2006zn} and
processes which are highly suppressed in the SM.
The latter are mainly lepton flavor violating (LFV) or decays involving
quark flavor changing neutral currents (qFCNC). While the prediction
of LFV decays in the SM is many orders of magnitude below the
experimental sensitivity \cite{Cheng:1985bj}, qFCNC is
experimentally well established. For instance, the observed rate of $b
\to s\gamma$ is in good agreement with the SM expectation and this
observable has put for several years strong
constraints on qFCNCs beyond the SM \cite{bsgamma}.

The experiments at the LHC have reached now a sensitivity to test also
the SM prediction for BR($B^0_s\to\mu\bar\mu$) as well as BR($B^0_d\to
\mu \bar{\mu}$) \cite{Buras:2012ru}
\begin{eqnarray}
  \BRx{B^0_s \to \mu \bar{\mu}}_{\text{SM}} &=& \scn{(3.23\pm 0.27)}{-9} \label{eq:Bsintro1}, \\
  \BRx{B^0_d \to \mu \bar{\mu}}_{\text{SM}} &=& \scn{(1.07\pm 0.10)}{-10}. \label{eq:Bsintro2}
\end{eqnarray}
Using the measured finite width difference of the $B$ mesons the time integrated branching ratio
which should be compared to experiment is \cite{Buras:2013uqa}
\begin{eqnarray}
  \BRx{B^0_s \to \mu \bar{\mu}}_{\text{theo}} &=& \scn{(3.56\pm 0.18)}{-9} \, .
\end{eqnarray}
Recently, LHCb reported the first evidence for $B^0_s \to \mu
\bar{\mu}$. The observed rate  \cite{LHCb:2012ct}
\begin{equation}
\BRx{B^0_s \to \mu \bar{\mu}} = (3.2^{+1.5}_{-1.2})\times 10^{-9}  \\
\end{equation}
fits nicely to the SM prediction. For $\BRx{B^0_d \to \mu \bar{\mu}}$
the current upper
bound: $9.4 \cdot 10^{-10}$
is already of the same order as the SM expectation.

This leads to new constraints for BSM models and each model has to be
confronted with these measurements. So far, there exist several public
tools which can calculate
$\BRx{B^0_{s,d}\to \ell\bar{\ell}}$ as well as other observables in the context of the MSSM
or partially also for the next-to-minimal supersymmetric standard
model (NMSSM) \cite{NMSSM}: {\tt superiso} \cite{superiso}, {\tt
SUSY\_Flavor} \cite{susyflavor}, {\tt NMSSM-Tools} \cite{NMSSMTools},
{\tt MicrOmegas} \cite{MicrOmegas} or {\tt SPheno} \cite{spheno}.
However, for more complicated SUSY models none of the available tools
provides the possibility to calculate
these decays easily. This gap is now closed by the interplay of the {\tt
Mathematica} package {\tt SARAH}\xspace \cite{sarah} and the spectrum generator
{\tt SPheno}\xspace. {\tt SARAH}\xspace
already has many SUSY models incorporated but allows also an easy and
efficient implementation of new models. For all of these models {\tt SARAH}\xspace
can generate new modules for {\tt SPheno}\xspace for a comprehensive numerical
evaluation. This functionality is extended, as described in this paper, by a
full 1-loop calculation of $B^0_{s,d}\to\ell\bar{\ell}$.

The rest of the paper is organized as follows: in
sec.~\ref{sec:analytical} we recall briefly the analytical calculation
for BR($B^0_{s,d}\to\ell\bar{\ell}$).  In
sec.~\ref{sec:implementation} we discuss the implementation of this
calculation in {\tt SARAH}\xspace and {\tt SPheno}\xspace before we conclude in
sec.~\ref{sec:conclusion}. The appendix contains more information
about the calculation and generic results for the amplitudes.

\section{Calculation of BR($B^0_{s,d}\to\ell\bar{\ell}$)}
\label{sec:analytical}
In the SM this decay was first calculated in ref~\cite{Inami:1980fz},
in the analogous context of kaons. The higher order corrections were
first presented in \cite{Buchalla:1993bv}; see also
\cite{Misiak:1999yg}. In the context of supersymmetry this was
considered in \cite{bsmumu-susy}. See also the interesting correlation
between BR$(B_s^0\to\mu\bar\mu)$ and $(g-2)_\mu$ \cite{Dedes:2001fv}.

We present briefly the main steps of the calculation of BR($B^0_{q}\to
\ell_k\bar{\ell}_l$) with $q=s,d$. We follow
closely the notation of ref.~\cite{Dedes:2008iw}. The effective
Hamiltonian can be parametrized by
\begin{eqnarray}
  \label{eq:effectiveH} \mathcal{H}&=&\frac{1}{16\pi^2}
  \sum_{X,Y=L,R}\kl{C_{SXY}\mathcal{O}_{SXY}+C_{VXY}\mathcal{O}_{VXY}+C_{TX}\mathcal{O}_{TX}}
  \, ,
\end{eqnarray}
with the Wilson coefficients $C_{SXY},C_{VXY},C_{TX}$ corresponding to
the scalar, vector and tensor operators
\begin{equation}
  \mathcal{O}_{SXY} = (\bar q_j P_X q_i)(\bar \ell_l P_Y \ell_k) \,, \hspace{0.5cm}
  \mathcal{O}_{VXY} = (\bar q_j \gamma^\mu P_X q_i)(\bar \ell_l \gamma_\mu P_Y
\ell_k) \,, \hspace{0.5cm}
  \mathcal{O}_{TX} = (\bar q_j \sigma^{\mu\nu} P_X q_i)(\bar \ell_l \sigma_{\mu\nu} \ell_k) \, .
\end{equation}
$P_L$ and $P_R$ are the projection operators on left respectively
right handed states.  The expectation value of the axial vector matrix
element is defined as
\begin{eqnarray}
  \label{eq:fBs}
  \langle 0\left| \bar b \gamma^\mu \gamma^5 q \right| B^0_q(p)\rangle
&\equiv&  ip^\mu f_{B^0_q} \, .
\end{eqnarray}
Here, we introduced the meson decay constants $f_{B^0_q}$ which can be
obtained from lattice QCD simulations \cite{Laiho:2009eu}. The current
values for $B^0_s$ and $B^0_d$ are given by \cite{Davies:2012qf}
\begin{equation}
  \label{eq:fBsValue}
  f_{B^0_s} = (227\pm 8)~{\text{Me}\hspace{-0.05cm}\text{V}} \,,\hspace{1cm} f_{B^0_d} = (190\pm 8)~{\text{Me}\hspace{-0.05cm}\text{V}} \, .
\end{equation}
Since the momentum $p$ of the meson is the only four-vector available,
the matrix element in \qref{eq:fBs} can only depend on
$p^\mu$. The incoming momenta of the $b$ antiquark and the $s$ (or $d$) quark are $p_1,p_2$  respectively, where $p=p_1+p_2$. Contracting \qref{eq:fBs} with $p_\mu$ and using the
equations of motion $\bar b \slashed p_1=-\bar b m_b$ and $\slashed
p_2 q=m_q q$ leads to an
expression for the pseudoscalar current
\begin{eqnarray}
  \label{eq:fBspseudo}
   \langle 0 \left| \bar b \gamma^5 q\right| B^0_q(p) \rangle &=& - i \frac{M_{B_q^0}^2 f_{B^0_q}}{m_b+m_q} \, .
\end{eqnarray}
The vector and scalar currents vanish
\begin{equation}
  \label{eq:vanish}
  \langle 0\left| \bar b \gamma^\mu  q \right| B^0_q(p)\rangle=
\langle 0 \left| \bar b q\right| B^0_q(p)
\rangle =0 \, .
\end{equation}
From eqs.~(\ref{eq:fBs}) and (\ref{eq:fBspseudo}) we obtain
\begin{equation}
\langle 0 \left| \bar b \gamma^\muP_{L/R} q \right| B^0_q(p)\rangle =
\mp \frac i2 p^\mu f_{B^0_q} \label{eq:fBsPLR1} \, , \hspace{1cm}
\langle 0 \left| \bar b P_{L/R} q
\right| B^0_q(p)\rangle = \pm \frac i2 \frac {M_{B^0_q}^2
f_{B^0_q}}{m_b+m_q} \, .
\end{equation}
In general, the matrix element $\mathcal M$ is a function of the form
factors $F_S,F_P,F_V,F_A$ of the scalar, pseudoscalar, vector and
axial-vector current and can be expressed by
\begin{equation}
  \label{eq:matrixelementBs}
    (4\pi)^2\mathcal M = F_S \bar \ell \ell + F_P \bar \ell \gamma^5 \ell
+ F_V p_\mu \bar \ell
  \gamma^\mu \ell + F_A p_\mu \bar \ell \gamma^\mu \gamma^5 \ell \, .
\end{equation}
Note that there is no way of building an antisymmetric 2-tensor out of
just one vector $p^\mu$. The matrix element of the tensor operator
$\mathcal{O}_{TX}$ must therefore vanish. The form factors can be
expressed by linear combinations of the Wilson coefficients of
eq.~(\ref{eq:effectiveH})
\begin{eqnarray}
    F_S &=& \frac i4 \frac{M_{B^0_q}^2 f_{B^0_q}}{m_b+m_q}  \kl{ C_{SLL} +
    C_{SLR} - C_{SRR}-C_{SRL}},\label{eq:formfactorsBs1}\\
   F_P &=& \frac i4 \frac{M_{B^0_q}^2 f_{B^0_q}}{m_b+m_q}  \kl{ -C_{SLL} +
    C_{SLR} - C_{SRR}+C_{SRL}}, \label{eq:formfactorsBs2}\\
  F_V &=& -\frac i4 f_{B^0_q} \kl{ C_{VLL} + C_{VLR} - C_{VRR}-C_{VRL}}, \label{eq:formfactorsBs3}\\
  F_A &=& -\frac i4 f_{B^0_q} \kl{ -C_{VLL} + C_{VLR} - C_{VRR}+C_{VRL}}.\label{eq:formfactorsBs4}
  \end{eqnarray}

The main task is to calculate the different Wilson coefficients for a
given model.  These Wilson coefficients receive at the 1-loop level
contributions from
various wave, penguin
and box diagrams, see Figures~\ref{fig:wave}-\ref{fig:box2} in
\ref{app:amplitudes}. Furthermore, in some models these decays could
also happen already at tree-level \cite{Dreiner:2006gu}.  The
amplitudes for all possible, generic diagrams which can contribute to
the Wilson coefficients have been calculated with {\tt FeynArts}\xspace/{\tt FormCalc}\xspace
\cite{feynarts} and the results are listed in
\ref{app:amplitudes}. This calculation has been performed in the
$\overline{\text{DR}}$ scheme and 't Hooft gauge. How these results
are used together with {\tt SARAH}\xspace and {\tt SPheno}\xspace to get numerical results
will be discussed in the next section.

After the calculation of the form factors, the squared amplitude is
\begin{align}
  \label{eq:squaredMBsllp}
  (4\pi)^4 \abs{\ampM}^2&=2\abs{F_S}^2\kl{M_{B^0_q}^2-(m_\ell+m_k)^2}
+2\abs{F_P}^2\kl{M_{B^0_q}^2-(m_\ell-m_k)^2}
  \\
\nonumber &+ 2\abs{F_V}^2\kl{M_{B^0_q}^2(m_k-m_\ell)^2-(m_k^2-m_\ell^2)^2} \\
\nonumber &+ 2\abs{F_A}^2\kl{M_{B^0_q}^2(m_k+m_\ell)^2-(m_k^2-m_\ell^2)^2} \\
\nonumber &+ 4\Re (F_s F_V^*) (m_\ell-m_k)\kl{M_{B^0_q}^2+(m_k+m_\ell)^2} \\
\nonumber &+ 4\Re (F_P F_A^*) (m_\ell+m_k)\kl{M_{B^0_q}^2-(m_k-m_\ell)^2} \, .
\end{align}
Here, $m_\ell$ and $m_k$ are the lepton masses. In the case $k=\ell$,
this expression simplifies to
\begin{eqnarray}
\label{eq:ampSquaredsimp}
\abs{\ampM}^2&=&\frac{2}{(16\pi^2)^2} \kl{(M_{B^0_q}^2-4 m_\ell^2)\abs{F_S}^2+
M_{B^0_q}^2 \abs{F_P+2m_\ell F_A}^2}.
\end{eqnarray}
Note, the result is independent of the form factor $F_V$ in this
limit. In the SM the leading 1-loop contributions proceed via
the exchange of virtual gauge bosons. They are thus helicity
suppressed. Furthermore, since these are flavor changing neutral
currents, they are GIM suppressed. The diagrams involving virtual
Higgs bosons are suppressed due to small Yukawa couplings. In BSM
scenarios these suppressions can be absent.

The branching ratio is then given by
\begin{equation}
  \label{eq:Bsllpbranching}
  \ensuremath{\text{BR}\,}(B_q^0\to \ell_k\bar{\ell}_l)=\frac{\tau_{B^0_q}}{16\pi}
  \frac{\abs{\mathcal{M}}^2}{M_{B_q^0}}\sqrt{1-\kl{\frac{m_k+m_l}{M_{B_q^0}}}^2}\sqrt{1-\kl{\frac{m_k-m_l}{M_{B_q^0}}}^2}
\end{equation}
with $\tau_{B^0_q}$ as the life time of the mesons.

\section{Automatized calculation of $\ensuremath{B^0_{s,d}\to \ell \bar{\ell} \xspace}$}
\label{sec:implementation}
\subsection{Implementation in {\tt SARAH}\xspace and {\tt SPheno}\xspace}
{\tt SARAH}\xspace is the first 'spectrum-generator-generator' on the market which
means that it can generate Fortran source for {\tt SPheno}\xspace to obtain a
full-fledged spectrum generator for models beyond the MSSM. The main
features of a {\tt SPheno}\xspace module written by {\tt SARAH}\xspace are a precise mass
spectrum calculation based on 2-loop renormalization group equations
(RGEs) and a full 1-loop calculation of the mass spectrum. Two-loop
results known for the MSSM can be included. Furthermore, also the
decays of SUSY and Higgs particles are calculated as well as
observables like $\ell_i \to \ell_j \gamma$, $\ell_i \to 3 \ell_j$, $b\to
s\gamma$, $\delta\rho$, $(g-2)$, or electric dipole moments. For more
information about the interplay between {\tt SARAH}\xspace and {\tt SPheno}\xspace we refer
the interested reader to Ref.~\cite{Staub:2011dp}.

Here we extend the list of observables  by BR($B^0_s\to\ell\bar
{\ell}$) and BR($B^0_d\to \ell\bar{\ell}$). For this purpose, the
generic tree--level and 1--loop amplitudes calculated with
{\tt FeynArts}\xspace/{\tt FormCalc}\xspace given in \ref{app:amplitudes} have been implemented
in {\tt SARAH}\xspace. When {\tt SARAH}\xspace generates the output for {\tt SPheno}\xspace it checks for
all possible field combinations which can populate the generic
diagrams in the given model. This information is then used to generate
Fortran code for a numerical evaluation of all of these diagrams. The
amplitudes are then combined to the Wilson coefficients which again
are used to calculate the form factors
eqs.~(\ref{eq:formfactorsBs1})-(\ref{eq:formfactorsBs4}).  The
branching ratio is finally calculated by using
eq.~(\ref{eq:Bsllpbranching}). Note, the known 2--loop QCD corrections
of Refs.~\cite{Buchalla:1993bv,Misiak:1999yg,Bobeth:2001jm} are
not included in this calculation.

The Wilson coefficients for $\ensuremath{B^0_{s,d}\to \ell \bar{\ell} \xspace}$ are
calculated at a scale $Q=160$~GeV by all modules generated by {\tt SARAH}\xspace,
as this is done by default by {\tt SPheno}\xspace in the MSSM. Hence, as input
parameters for the calculation the running SUSY masses and couplings at
this scale obtained by a 2-loop RGE evaluation down from the SUSY scale are used.
In the standard model gauge sector we use the running value of $\alpha_{em}$, the on-shell
Weinberg angle $\sin \Theta_W^2 = 1 -\frac{m_W^2}{m_Z^2}$ with $m_W$ calculated
from $\alpha_{em}(M_Z)$, $G_F$ and the $Z$ mass. In addition, the CKM matrix calculated
from the Wolfenstein parameters ($\lambda$, $A$,$\rho$,$\eta$) as well as
the running quark masses enter the calculation. To obtain the running SM parameters at $Q=160$~GeV
 we use 2-loop standard model RGEs of Ref.~\cite{Arason:1991ic}.
The default SM values as well as the derived parameters are given in Tab.~\ref{tab:sm}.
Note, even if CP violation is not switched on the calculation of the SUSY spectrum, always the phase
of the CKM matrix is taken into account in these calculations. This is especially important for $B_d^0$
decays.
\begin{table}[bt]
\centering
\small
\begin{tabular}{|l|l|l|l|l|}
\hline \hline
\multicolumn{5}{|c|}{default SM input parameters} \\
\hline
$\alpha^{-1}_{em}(M_Z) = 127.93  $ & $\alpha_s(M_Z) = 0.1190  $ & $G_F = 1.16639\cdot 10^{-5}~\text{GeV}^{-2}$
 & $\rho = 0.135$ & $\eta = 0.349$  \\
$m_t^{pole} = 172.90~\text{GeV}$ & $M_Z^{pole} = 91.1876~\text{GeV}  $ & $m_b(m_b) = 4.2~\text{GeV} $ & $\lambda = 0.2257 $ & $A = 0.814$ \\
\hline \hline
\multicolumn{5}{|c|}{derived parameters} \\
\hline
 $m_t^{\overline{DR}} = 166.4~\text{GeV}$ &
$| V_{tb}^* V_{ts}| = 4.06*10^{-2}  $ & $| V_{tb}^* V_{td}| = 8.12*10^{-3} $ & $m_W = 80.3893 $ & $\sin^2 \Theta_W = 0.2228 $ \\
\hline
\end{tabular}
\caption{SM input values and derived parameters by default used for the numerical evaluation of $B^0_{s,d} \to l\bar{l}$ in {\tt SPheno}\xspace.}
  \label{tab:sm}
\end{table}
All standard model parameters can be adjusted by using the
corresponding standard blocks
of the SUSY LesHouches Accord 2 (SLHA2) \cite{SLHA}.
Furthermore, the default input values for the
hadronic parameters given in Table~\ref{tab:input} are used. These
can be changed in the Les Houches input accordingly to the Flavor Les Houches
Accord (FLHA) \cite{Mahmoudi:2010iz} using the following blocks:
\begin{verbatim}
      Block FLIFE          #
      511   1.525E-12      # tau_Bd
      531   1.472E-12      # tau_Bs
      Block FMASS          #
      511   5.27950   0    0    # M_Bd
      531   5.3663    0    0    # M_Bs
      Block FCONST    #
      511   1   0.190    0    0   # f_Bd
      531   1   0.227    0    0   # f_Bs
\end{verbatim}
While {\tt SPheno}\xspace includes the
chiral resummation for the MSSM, this is not taken into account in the
routines generated by {\tt SARAH}\xspace because of its large model dependence.
\begin{table}
\centering
\begin{tabular}{|l|l|l|}
\hline
\multicolumn{3}{|c|}{Default hadronic parameters} \\
\hline
$m_{B^0_s} = 5.36677$ GeV & $f_{B^0_s} = 227(8)$ MeV & $\tau_{B^0_s} = 1.466(31)$ ps \\
$m_{B^0_d} = 5.27958$ GeV  & $f_{B^0_d} = 190(8)$ MeV & $\tau_{B^0_d} = 1.519(7)$ ps  \\
\hline
 \end{tabular}
 \caption{Hadronic input values by default used for the numerical evaluation of $B^0_{s,d} \to l\bar{l}$ in {\tt SPheno}\xspace.}
  \label{tab:input}
\end{table}
\subsection{Generating and running the source code}
We describe briefly the main steps necessary to generate and run the
{\tt SPheno}\xspace code for a given model: after starting {\tt Mathematica} and
loading {\tt SARAH}\xspace it is just necessary to evaluate the demanded model and
call the function to generate the {\tt SPheno}\xspace source code. For instance,
to get a {\tt SPheno}\xspace module for the B-L-SSM \cite{Khalil:2007dr,FileviezPerez:2010ek,O'Leary:2011yq}, use
\begin{verbatim}
<<[$SARAH-Directory]/SARAH.m;
Start["BLSSM"];
MakeSPheno[];
\end{verbatim}
{\tt MakeSPheno[]} calculates first all necessary information
(\textit{i.e.} vertices, mass matrices, tadpole equations, RGEs,
self-energies) and then exports this
information to Fortran code and writes all necessary auxiliary
functions needed to compile the code together with {\tt SPheno}\xspace. The entire
output is saved in the directory
\begin{verbatim}
[$SARAH-Directory]/Output/BLSSM/EWSB/SPheno/
\end{verbatim}
The content of this directory has to be copied into a new
subdirectory of {\tt SPheno}\xspace called {\tt BLSSM} and afterwards the code can
be compiled:
\begin{verbatim}
cp [$SARAH-Directory]/Output/BLSSM/EWSB/SPheno/*  [$SPheno-Directory]/BLSSM/
cd [$SPheno-Directory]
make Model=BLSSM
\end{verbatim}
This creates a new binary {\tt SPhenoBLSSM} in the directory {\tt bin}
of {\tt SPheno}\xspace. To run the spectrum calculation a file called {\tt
LesHouches\!.in.BLSSM} containing all input parameters in the Les
Houches format has to be provided.  {\tt SARAH}\xspace writes also a template for
such a file which has been copied with the other files to {\tt
/BLSSM}. This example can be evaluated via
\begin{verbatim}
./bin/SPhenoBLSSM BLSSM/LesHouches.in.BLSSM
\end{verbatim}
and the output is written to {\tt SPheno.spc.BLSSM}. This file
contains all information like the masses, mass matrices, decay widths
and branching ratios, and observables. For the $B^0_{s,d}\to \ell \bar{\ell}$
decays
the results are given twice for easier comparison: once for the full
calculation and once including only the SM contributions. All results
are written to the block  {\tt SPhenoLowEnergy} in the spectrum file
using the following numbers:
\begin{center}
\begin{tabular}{|cl|cl|}
\hline
{\tt 4110}   & $\text{BR}^{SM}(B^0_d\to e^+e^-)$ & {\tt 4111}  & $\text{BR}^{full}(B^0_d\to e^+e^-)$ \\
 {\tt 4220}   & $\text{BR}^{SM}(B^0_d\to \mu^+\mu^-)$ & {\tt 4221}  & $\text{BR}^{full}(B^0_d\to \mu^+\mu^-)$ \\
 {\tt 4330}   & $\text{BR}^{SM}(B^0_d\to \tau^+\tau^-)$ & {\tt 4331}  & $\text{BR}^{full}(B^0_d\to \tau^+\tau^-)$ \\
 {\tt 5110}   & $\text{BR}^{SM}(B^0_s\to e^+e^-)$ & {\tt 5111}  & $\text{BR}^{full}(B^0_s\to e^+e^-)$ \\
 {\tt 5210}   & $\text{BR}^{SM}(B^0_s\to \mu^+e^-)$ & {\tt 5211}  & $\text{BR}^{full}(B^0_s\to \mu^+e^-)$ \\
 {\tt 5220}   & $\text{BR}^{SM}(B^0_s\to \mu^+\mu^-)$ & {\tt 5221}  & $\text{BR}^{full}(B^0_s\to \mu^+\mu^-)$ \\
 {\tt 5330}   & $\text{BR}^{SM}(B^0_s\to \tau^+\tau^-)$ & {\tt 5331}  & $\text{BR}^{full}(B^0_s\to \tau^+\tau^-)$ \\
\hline
\end{tabular}
\end{center}
Note, we kept for completeness and as cross-check $\text{BR}^{SM}(B^0_s\to \mu^+e^-)$ which has to vanish.
The same steps can be repeated for any other model implemented in
{\tt SARAH}\xspace, or the {\tt SUSY-Toolbox} scripts \cite{Staub:2011dp} can be
used for an automatic implementation of new models in {\tt SPheno}\xspace as well
as in other tools based on the {\tt SARAH}\xspace output.

\subsection{Checks}
We have performed several cross checks of the code generated by
{\tt SARAH}\xspace: the first, trivial check has been that we reproduce the known
SM results and that those agree with the full calculation in the limit of
heavy SUSY spectra. For the input parameters
of Tab.~\ref{tab:sm} we obtain $\text{BR}(B^0_s\to \mu^+ \mu^-)^{SM} = 3.28\cdot 10^{-9}$
and $\text{BR}(B^0_d\to \mu^+ \mu^-)^{SM} = 1.08\cdot 10^{-10}$ which are in good agreement
with eqs.~(\ref{eq:Bsintro1})-(\ref{eq:Bsintro2}).
Secondly, as mentioned in
the introduction there are several codes which calculate these decays
for the MSSM or NMSSM. A detailed comparison of all of these codes is
beyond the scope of the presentation here and will
be presented elsewhere \cite{comparison}.
However, a few comments are in order:
the code generated by {\tt SARAH}\xspace as well as most other codes usually show
the same behavior. There are differences in the numerical
values calculated by the programs because of different values
for the SM inputs. For instance, there is an especially strong
dependence on the value of the
electroweak mixing angle and, of course, of the hadronic parameters used in the
calculation \cite{Buras:2012ru}.  In addition, these processes are
implemented with different accuracy in different tools: the treatment
of NLO QCD corrections \cite{Bobeth:2001jm}, chiral resummation
\cite{Crivellin:2011jt}, or SUSY box diagrams is not the
same. Therefore, we depict in Fig.~\ref{fig:comparison} a comparison
between {\tt SPheno 3.2.1}, {\tt Superiso 3.3} and {\tt SPheno by
SARAH} using the results normalized to the SM limit of each program.

\begin{figure}[hbtp]
 \centering
 \includegraphics[width=0.5\linewidth]{FeynAmps/m0_R.pdf}  \\
 \includegraphics[width=0.5\linewidth]{FeynAmps/m0M12_R.pdf}  \\
 \includegraphics[width=0.5\linewidth]{FeynAmps/tb_R.pdf}
 \caption{The top figure: $R=\text{BR}(B_s^0\to \mu^+
   \mu^-)/\text{BR}(B_s^0\to \mu^+\mu^-)_{SM}$ for the constrained
   MSSM and as function of $m_0$. The other parameters were set to
   $M_{1/2}=140$~GeV, $\tan\beta=10$, $\mu>0$. In the middle $m_0$
   and $M_{1/2}$ were varied simultaneously, while $\tan\beta=30$
   was fixed. In the bottom figure we show $\log(R)$ as a function
   of $\tan\beta$, while $m_0=M_{1/2} = 150$~GeV were kept fix. In
   all figures $A_0=0$ and $\mu>0$ was used. The color code is as
   follows: {\tt superiso 3.3} (dotted black), {\tt SPheno 3.2.1}
   (dashed red) and {\tt SPheno}\xspace by {\tt SARAH}\xspace (solid blue).}
 \label{fig:comparison}
\end{figure}

It is also possible to perform a check of self-consistency: the
leading-order contribution has to be finite which leads to non-trivial
relations among the amplitudes for all
wave and penguin diagrams are given in \ref{sec:waveBapp} and \ref{sec:penguinB}.
Therefore, we can check these relations numerically by
varying the renormalization scale used in all loop integrals. The
dependence on this scale should cancel and the branching ratios should
stay constant. This is shown in Figure~\ref{fig:scaledependence}:
while single contributions can change by several orders the sum of all
is numerically very stable.

\begin{figure}[hbt]
 \centering
 \includegraphics[width=0.6\linewidth]{FeynAmps/renorm-plot-FA}
 \caption{The figure shows $|\sum F_A|_{\text{penguin}}$ and $|\sum F_A|_{\text{wave}}$ as well as the sum of both $|\sum F_A|$. Penguin and wave contributions have opposite signs that interchange between $Q=10^2{\text{Ge}\hspace{-0.05cm}\text{V}}$ to $Q=10^3{\text{Ge}\hspace{-0.05cm}\text{V}}$.}
 \label{fig:scaledependence}
\end{figure}

\subsection{Non-supersymmetric models}
We have focused our discussion so far on SUSY models. However, even if
{\tt SARAH}\xspace is optimized for the study of SUSY models it is also able to
handle non-SUSY models to some extent. The main drawback at the moment
for non-SUSY models is that the RGEs can not be calculated
because the results of Refs.~\cite{Martin:1993zk,Fonseca:2011vn} which
are used by {\tt SARAH}\xspace are not valid in this case. However, all other
calculations like the ones for the vertices, mass matrices and
self-energies don't use SUSY properties and therefore apply to
any model. Hence, it is also possible to generate {\tt SPheno}\xspace code for
these models which calculates $B^0_{s,d}\to\ell\bar{\ell}$. The main
difference in the calculation comes from the missing possibility to
calculate the RGEs: the user has to provide numerical values for all
parameters at the considered scale which then enter the
calculation. We note that in order to fully support non-supersymmetric
models with {\tt SARAH}\xspace the calculation of the corresponding RGEs at 2-loop
level will be included in {\tt SARAH}\xspace in the future \cite{nonsusyrges}.

\section{Conclusion}
\label{sec:conclusion}
We have presented a model independent implementation of the flavor
violating decays $B^0_{s,d} \to \ell\bar{\ell}$ in {\tt SARAH}\xspace and {\tt SPheno}\xspace. Our
approach provides the possibility to generate source code which
performs a full 1-loop calculation of these observables for any
model which can be implemented in {\tt SARAH}\xspace.  Therefore, it takes care of
the necessity to confront many BSM models in the future with the
increasing constraints coming from the measurements of $B^0_{s,d} \to
\ell\bar{\ell}$ at the LHC.

\section*{Acknowledgements}
W.P.\ thanks L.~Hofer for discussions.  This work has been supported
by the Helmholtz alliance `Physics at the Terascale' and W.P.\ in part
by the DFG, project No. PO-1337/2-1. HKD acknowledges support from
BMBF grant 00160200.

\input{appendix.tex}
\input{lit.tex}

\end{document}

\section{Conventions}
\label{conventions}
\subsection{Passarino-Veltman integrals}

We use in the following the conventions of \cite{Pierce:1996zz}
for the Passarino-Veltman integrals. All Wilson coefficients appearing
in the following can be expressed by the integrals
\begin{eqnarray}
  \label{eq:B0withPsq0}
  B_0(0,x,y)&=& \Delta + 1 + \ln \kl{\frac{Q^2}{y}} +
  \frac{x}{x-y}\ln \kl{\frac{y}{x}} \\
\Delta &=& \frac 2{4-D} - \gamma_E + \log 4\pi \\
  B_1(x,y,z) &=& \frac 12 (z-y)\frac{B_0(x,y,z)-B_0(0,y,z)}{x}-\frac 12  B_0(x,y,z)  \\
  C_0(x,y,z) &=& \frac{1}{y-z} \left[ \frac{y}{x-y} \log \frac yx - \frac{z}{x-z} \log \frac zx \right] \label{eq:C0} \\
 \nonumber C_{00}(x,y,z)
  &=& \frac 14 \kl{1-\frac 1{y-z}\kl{ \frac {x^2\log x - y^2\log y}{x-y}-\frac{x^2\log x-z^2\log z}{x-z}}} \\
  D_0(x,y,z,t) &=& \frac{C_0(x,y,z)-C_0(x,y,t)}{z-t} \label{eq:D0reduce} \\
\nonumber &=& -\left[ \frac{y\log \frac yx}{(y-x)(y-z)(y-t)} +
    \frac{z\log \frac zx}{(z-x)(z-y)(z-t)}+\frac{t\log \frac
      tx}{(t-x)(t-y)(t-z)} \right] \\
  D_{00}(x,y,z,t)  & = &  -\frac 14\left[ \frac{y^2\log \frac yx}{(y-x)(y-z)(y-t)} +
    \frac{z^2log \frac zx}{(z-x)(z-y)(z-t)}+\frac{t^2\log \frac
      tx}{(t-x)(t-y)(t-z)} \right].
\end{eqnarray}
Note, the conventions of ref.~\cite{Pierce:1996zz} (Pierce, Bagger
[PB]) are different than those presented in ref.~\cite{Dedes:2008iw}
(Dedes, Rosiek, Tanedo [DRT]). The box integrals are related by
\begin{eqnsub}
  \label{eq:Dloopsall}
D_{0} &=& D_0^{(\text{PB})}=- D_0^{(DRT)}, \\
\label{eq:Dloopsall2}
D_{00}&=& D_{27}^{(\text{PB})}=- \frac 14 D_{2}^{(DRT)} \,.
\end{eqnsub}

\subsection{Massless limit of loop integrals}
In some amplitudes (i.e. penguin diagrams $(a-b)$, box diagram $(v)$) the
following combinations of loop integrals appear:
\begin{align}
  I_1 &= B_0(s,M_{F1}^2,M_{F2}^2)+M_S^2 C_0(s,0,0,M_{F2}^2,M_{F1}^2,M_S^2), \\
  I_2 &= C_0(0,0,0,M_{F2}^2,M_{F1}^2,M_{V2}^2) + M_{V1}^2 D_0(M_{F2}^2,M_{F1}^2,M_{V1}^2,M_{V2}^2).
\end{align}
The loop functions $B_0,C_0,D_0$ diverge for massless fermions (e.g. neutrinos in the MSSM) but
 the expressions $I_1,I_2$ are finite. However, this limit must be taken analytically in order to avoid
numerical instabilities.
In a generalized  form and in the limit of zero external momenta, $I_i$ can be expressed by
\begin{align}
  I_1(a,b,c) &= B_0(0,a,b)+c C_0(0,0,0,a,b,c) \equiv B_0(0,a,b)+c C_0(a,b,c), \\
  I_2(a,b,c,d) &= C_0(0,0,0,a,b,d) + c D_0(a,b,c,d) \equiv C_0(a,b,d)+c D_0(a,b,c,d).
\end{align}
Using eqs.~{\ref{eq:B0withPsq0},\ref{eq:C0},\ref{eq:D0reduce}} we obtain in the limit $a\to 0$
\begin{align}
  I_1(0,b,c) &= B_0(0,0,b) + c C_0(0,b,c) \\
 &= \Delta + 1 - \log \frac b{Q^2} + c \frac 1{b-c}\log \frac cb \\
 &= \Delta + 1 + \log Q^2  + \frac {c}{b-c} \log c + \kl{-1-\frac c{b-c}}\log
 b
\end{align}
The term proportional to $\log b$ vanishes in the limit $b\to 0$
\begin{equation}
 I_1(0,0,c) = \Delta + 1 - \log \frac c{Q^2}
\end{equation}
The same strategy works for $I_2$:
\begin{align}
  I_2(0,b,c,d) &= C_0(0,b,d)+c D_0(0,b,c,d) \\
&= \frac 1{b-d} \log \frac{d}{b} + c  \frac{C_0(0,b,c)-C_0(0,b,d)}{c-d} \\
&= \frac 1{b-d} \log \frac{d}{b} +  \frac c{c-d} \frac 1{b-c} \log \frac{c}{b} -
\frac{c}{c-d}\frac 1{b-d}\log \frac {d}{b} \\
&= \frac{(c-d)(b-c)\log \frac db + c (b-d)\log \frac cb - c(b-c) \log \frac
  db}{(b-d)(c-d)(b-c)} \label{eq:I2last}
\end{align}
The denominator of \qref{eq:I2last} is finite for $b\to 0$ and in the
numerator, the $\log b$ terms cancel each other:
\begin{equation}
  ( (c-d)c + cd -c^2 ) \log b =0.
\end{equation}
Hence, we end up with
\begin{align}
I_2(0,0,c,d) &= \frac{-c(c-d)\log d - cd \log c + c^2 \log
  d}{cd(c-d)} = \frac{\log \frac dc}{c-d}.
\end{align}
\subsection{Parametrization of vertices}
We are going to express the amplitude in the following in terms of
generic vertices. For this purpose, we parametrize a vertex between
two fermions and one vector or scalar respectively as
\begin{eqnarray}
\label{eq:chiralvertices1}
 & G_A \gamma_\mu P_L + G_B  \gamma_\mu P_R\, , &  \\
\label{eq:chiralvertices2}
 & G_A P_L + G_B   P_R \, . &
\end{eqnarray}
$P_{L,R}=\frac 12 (1\mp \gamma^5)$ are the polarization operators. In
addition, for the vertex between three vector bosons and the one between one
vector boson and two scalars the conventions are as follows
\begin{eqnarray}
& G_{VVV} \cdot \kl{g_{\mu\nu}(k_2-k_1)_\rho+g_{\nu\rho}(k_3-k_2)_\mu
+g_{\rho\mu}(k_1-k_3)_\nu}  \, , \\
& G_{SSV}\cdot (k_1-k_2)_\mu\, . &
\end{eqnarray}
Here, $k_i$ are the (ingoing) momenta of the external particles.

\section{Generic amplitudes}
\label{app:amplitudes}
We present in the following the expressions for the generic amplitudes obtained with {\tt FeynArts}\xspace and {\tt FormCalc}\xspace. All coefficients that are not explicitly listed are zero. Furthermore, the Wilson coefficients are left--right symmetric, i.e.
\begin{equation}
 C_{XRR} = C_{XLL} (L \leftrightarrow R) \,, \hspace{1cm} C_{XRL}
   = C_{XLR}  (L \leftrightarrow R),
\end{equation}
with $X=S,V$ and where $(L \leftrightarrow R)$ means that
the coefficients of the left and right polarization part of each vertex have to be interchanged.

\allowdisplaybreaks
\subsection{Tree Level Contributions}
\label{sec:treelevel}
\begin{figure}[htbp]
  \centering
  \begin{tabular}{cc}
  \includegraphics[width=4cm]{FeynAmps/STree1x} & \includegraphics[width=4cm]{FeynAmps/STree2x} \\
   (a) & (b) \\
  \includegraphics[width=4cm]{FeynAmps/TTree1x} & \includegraphics[width=4cm]{FeynAmps/TTree2x} \\
  (c) & (d) \\
    \includegraphics[width=4cm]{FeynAmps/UTree1x} &    \includegraphics[width=4cm]{FeynAmps/UTree2x} \\
   (e) & (f)
   \end{tabular}
  \caption{Tree level diagrams with vertex numbering}
  \label{fig:treeleveldiagrams}
\end{figure}
Since in models beyond the MSSM it might be possible that $\ensuremath{B^0_s\to \ell\bar{\ell}}\xspace$ is already possible at tree--level. This is for instance the case for trilinear $R$-parity violation \cite{Dreiner:2006gu}. The generic diagrams are given in Figure~\ref{fig:treeleveldiagrams}. The chiral vertices are parametrized as in eqs.~(\ref{eq:chiralvertices1})-(\ref{eq:chiralvertices2}) with $A=1,B=2$ for vertex 1 and $A=3,B=4$ for vertex 2. Using these conventions, the corresponding contributions to the Wilson coefficients read
\begin{eqnarray}
  \label{eq:treeSchannel}
  C^{(a)}_{SLL}&=&16\pi^2 \frac{G_1G_3}{M_S^2-s} \,, \hspace{1cm}  C^{(a)}_{SLR} = 16\pi^2 \frac{G_1G_4}{M_S^2-s}\\
  C^{(b)}_{VLL}&=&16\pi^2 \frac{-G_1G_3}{M_V^2-s}\,, \hspace{1cm}  C^{(b)}_{VLR} = 16\pi^2 \frac{-G_1G_4}{M_V^2-s}\\
  C^{(c)}_{SLL}&=& 16\pi^2\frac{-G_1G_3}{2(M_S^2-t)}\,, \hspace{1cm} C^{(c)}_{VLR} =  16\pi^2\frac{-G_2G_3}{2(M_S^2-t)} \\
  C^{(d)}_{SLR}&=&16\pi^2\frac{2G_2G_3}{M_V^2-t} \,, \hspace{1cm} C^{(d)}_{VLL} = 16\pi^2\frac{-G_1G_3}{M_V^2-t} \\
  C^{(e)}_{SLL} &=& 16\pi^2\frac{-G_1G_3}{2(M_S^2-u)} \,, \hspace{1cm} C^{(e)}_{VLL} = 16\pi^2\frac{G_2G_3}{2(M_S^2-u)} \\
  C^{(f)}_{SLR} &=& 16\pi^2\frac{-2G_2G_4}{M_V^2-u}  \,, \hspace{1cm} C^{(f)}_{VLR} =  16\pi^2\frac{-G_1G_4}{M_V^2-u}
 \end{eqnarray}
Here, $s$, $t$ and $u$ are the usual Mandelstam variables.

\subsection{Wave Contributions}
\label{sec:waveBapp}
\begin{figure}[htpb]
\centering
\begin{tabular}{cc}
\includegraphics[width=3cm]{FeynAmps/BsLLwaveS1SS}
& \includegraphics[width=3cm]{FeynAmps/BsLLwaveS1VS}  \\
(a) & (b) \\
\includegraphics[width=3cm]{FeynAmps/BsLLwaveS1SV} &    \includegraphics[width=3cm]{FeynAmps/BsLLwaveS1VV}\\
(c) & (d) \\
\includegraphics[width=3cm]{FeynAmps/BsLLwaveT1SS}
 & \includegraphics[width=3cm]{FeynAmps/BsLLwaveT1VS}
\\
(e) & (f) \\
\includegraphics[width=3cm]{FeynAmps/BsLLwaveT1SV}
 &   \includegraphics[width=3cm]{FeynAmps/BsLLwaveT1VV}
 \\
(g) & (h) \\
\includegraphics[width=3cm]{FeynAmps/BsLLwaveU1SS}
 & \includegraphics[width=3cm]{FeynAmps/BsLLwaveU1VS}
\\
(i) & (j) \\
\includegraphics[width=3cm]{FeynAmps/BsLLwaveU1SV}
& \includegraphics[width=3cm]{FeynAmps/BsLLwaveU1VV}
\\
(k) & (l) \\
\end{tabular}
\caption[Generic wave diagrams]{Generic wave diagrams. For every diagram there is a crossed version, where the loop attaches to the other external quark.}
\label{fig:wave}
\end{figure}
\begin{figure}[htpb]
  \centering
  \includegraphics[width=4cm]{FeynAmps/BsLLwaveS1numbers}
  \includegraphics[width=4cm]{FeynAmps/BsLLwaveS2numbers} \\
  \includegraphics[width=4cm]{FeynAmps/BsLLwaveT1numbers}
  \includegraphics[width=4cm]{FeynAmps/BsLLwaveT2numbers} \\
  \includegraphics[width=4cm]{FeynAmps/BsLLwaveU1numbers}
  \includegraphics[width=4cm]{FeynAmps/BsLLwaveU2numbers}
  \caption{Generic wave diagram vertex numbering}
  \label{fig:wavenumbering}
\end{figure}
The generic wave diagrams are given in Figure~\ref{fig:wave}. The internal
quark which attaches to the vector or scalar propagator has generation index
$n$. Couplings that depend on $n$ carry it as an additional index. The chiral
vertices are parametrized as in
eqs.~(\ref{eq:chiralvertices1})-(\ref{eq:chiralvertices2}) with $A=1,B=2$ for
vertex 1, $A=3,B=4$ for vertex 2, $A=5,B=6$ for vertex 3 and $A=7,B=8$ for
vertex 4, see also Figure~\ref{fig:wavenumbering} for the numbering of the
vertices. If a vertex is labelled $3^\prime$ for instance, the corresponding couplings
are $G_5^\prime, G_6^\prime$. Furthermore, we define the following abbreviations:
\begin{align}
  \label{eq:wavebubbleSapp}
  f_{S1} &= \frac{1}{m_n^2-m_{i}^2} \kl{-M_F(G_1G_{3n}m_n+G_2G_{4n}m_{i})B_0^{(i)}+(G_2G_{3n}m_nm_{i}+G_1G_{4n}m_{i}^2)B_1^{(i)}},
  \\
  f_{S2} &= \frac{1}{m_{j}^2-m_n^2}\kl{M_F(G_{2n}G_4m_{j}+G_{1n}G_3m_n)B_0^{(j)}-(G_{2n}G_3m_{j}^2+G_{1n}G_4m_{j}
    m_n)B_1^{(j)}}, \\
  \tilde f_{S2} &= \frac{1}{m_{j}^2-m_n^2}\kl{M_F(G_{1n}G_3m_{j}+G_{2n}G_4 m_n)B_0^{(j)}-(G_{1n}G_4m_{j}^2+G_{2n}G_3m_{j}
    m_n)B_1^{(j)}}, \\
\label{eq:wavebubbleVapp}
  f_{V1} &= \frac{1}{m_n^2-m_{i}^2}\kl{2M_F(G_1G_{4n} m_n+G_2G_{3n}m_{i})B_0^{(i)}+(G_2G_{4n}m_nm_{i}+G_1G_{3n}m_{i}^2)B_1^{(i)}}, \\
  f_{V2} &= \frac{1}{m_{j}^2-m_n^2}\kl{2M_F(G_{2n}G_3m_j+G_{1n}G_4 m_n)B_0^{(j)}+(G_{2n}G_4m_{j}^2+G_{1n}G_3m_{j} m_n)B_1^{(j)}},  \\
\tilde f_{V2} &= \frac{1}{m_{j}^2-m_n^2}\kl{2M_F(G_{1n}G_4m_j+G_{2n}G_3 m_n)B_0^{(j)}+(G_{1n}G_3m_{j}^2+G_{2n}G_4m_{j} m_n)B_1^{(j)}}.
\end{align}
The $m_i,m_j$ are the quark masses and $B_{0,1}^{(i)} = B_{0,1}(m_i^2,M_F^2,M_S^2)$ (or $M_V^2$ instead of $M_S^2$). $m_n$ is the mass of the internal quark with generation index $n$. Couplings that involve the internal quark are also labelled with $n$ (e.g. $G_{3n}$). Using these conventions, the contributions to the Wilson coefficients are
\begin{eqnarray}
C^{(a)}_{SLL}&=& \frac{G_7}{M_{S0}^2-s} \kl{ G_{5n} f_{S1}+ G_{5n}^\prime f_{S2} } \\
C^{(c)}_{VLL}&=& \frac{G_7}{M_{V0}^2-s} \kl{ -G_{5n} f_{S1} - G_{5n}^\prime \tilde f_{S2} }  \to \frac{G_7}{M_{V0}^2-s} G_5 G_1G_4B_1(0,M_F,M_S)  \\
C^{(b)}_{SLL}&=&\frac{2G_7}{M_{S0}^2-s} \kl{ G_{5n} f_{V1} - G_{5n}^\prime f_{V2} } \\
C^{(d)}_{VLL}&=&\frac{2G_7}{M_{V0}^2-s} \kl{-G_{5n} f_{V1} + G_{5n}^\prime \tilde f_{V2}} \to \frac{2G_7}{M_{V0}^2-s} G_5 G_1G_3B_1(0,M_F,M_V)  \\
 C^{(e)}_{SLL} &=& \frac{-1}{2(M_{S0}^2-t)} \kl{ G_{5n} G_7 f_{S1} + G_{5n}^\prime G_7^\prime f_{S2} } \\
 C^{(e)}_{VLR} &=& \frac{ -1}{2(M_{S0}^2-t)} \kl{ G_{5n} G_8 f_{S1} + G_{6n}^\prime G_7^\prime \tilde f_{S2} } \\
C^{(g)}_{SLR}&=& \frac{+2}{M_{V0}^2-t} \kl{ G_{5n} G_8 f_{S1} + G_{6n}^\prime  G_7^\prime f_{S2} } \\
C^{(g)}_{VLL}&=&\frac{-1}{M_{V0}^2-t} \kl{ G_{5n}G_7 f_{S1} + G_{5n}^\prime  G_7^\prime \tilde f_{S2} } \\
    C^{(f)}_{SLL}&=& \frac{-1}{M_{S0}^2-t} \kl{ G_{5n}G_7 f_{V1} - G_{5n}^\prime G_7^\prime f_{V2} }  \\
    C^{(f)}_{VLR} &=& \frac{-1}{M_{S0}^2-t} \kl{ G_{5n}G_8 f_{V1} - G_{6n}^\prime   G_7^\prime \tilde f_{V2} } \\
    C^{(h)}_{SLR} &=& \frac{+4}{M_{V0}^2-t} \kl{ G_{5n}G_8 f_{V1} - G_{6n}^\prime G_7^\prime f_{V2} } \\
    C^{(h)}_{VLL} &=& \frac{+2}{M_{V0}^2-t} \kl{ - G_{5n}G_7 f_{V1} + G_{5n}^\prime     G_7^\prime \tilde f_{V2} }\\
    C^{(i)}_{SLL} &=& \frac{-1}{2(M_{S0}^2-u)} \kl{ G_{5n}G_7 f_{S1} + G_{5n}^\prime  G_7^\prime f_{S2} } \\
C^{(i)}_{VLL} &=& \frac{+1}{2(M_{S0}^2-u)} \kl{ G_{5n}G_8 f_{S1} + G_{6n}^\prime  G_{7}^\prime \tilde f_{S2} }\\
C^{(k)}_{SLR}&=& \frac{-2}{M_{V0}^2-u}\kl{G_{6n}G_8 f_{S1}+G_{6n}^\prime G_8^\prime f_{S2}} \\
C^{(k)}_{VLR} &=& \frac{-1}{M_{V0}^2-u} \kl{G_{6n}G_7 f_{S1}+G_{5n}^\prime  G_8^\prime \tilde f_{S2}} \\
    C^{(j)}_{SLL}&=& \frac{-1}{M_{S0}^2-u} \kl{ G_{5n} G_7 \tilde f_{V1} -   G_{5n}^\prime G_7^\prime f_{V2}  } \\
    C^{(j)}_{VLL} &=& \frac{-1}{M_{S0}^2-u} \kl{ - G_{5n}G_8 \tilde f_{V1} +   G_{6n}^\prime G_7^\prime \tilde f_{V2}   } \\
    C^{(l)}_{SLR} &=& \frac{-4}{M_{V0}^2-u} \kl{ G_{6n}G_8 \tilde f_{V1} -    G_{6n}^\prime G_8^\prime f_{V2} }\\
    C^{(l)}_{VLR} &=& \frac{-2}{M_{V0}^2-u} \kl{ G_{6n}G_7 \tilde f_{V1} -    G_{5n}^\prime G_8^\prime \tilde f_{V2} }
\end{eqnarray}

\subsection{Penguin Contributions}
\label{sec:penguinB}
\begin{figure}[htpb]
  \centering
  \includegraphics[width=4cm]{FeynAmps/PenV}
  \caption{Vertex number conventions for a representative penguin diagram}
  \label{fig:penguinvertex}
\end{figure}
\begin{figure}[hbt]
 \centering
 \begin{tabular}{cccc}
  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinScalarFFS} &  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinVectorFFS} & \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinScalarSSF} &  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinVectorSSF} \\
  (a) & (b) &  (c) & (d) \\
  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinScalarFFV} &  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinVectorFFV} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinScalarFVV} &  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinVectorFVV} \\
  (e) & (f) &  (g) & (h) \\
  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinScalarFSV1} & \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinVectorFSV1} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinScalarFSV2} &  \includegraphics[width=3cm]{FeynAmps/BtoLLpPenguinVectorFSV2} \\
    (i) & (j) &  (k) & (l)
 \end{tabular}
\caption{Generic penguin diagrams}
\label{fig:penguin}
\end{figure}
Diagrams with scalar propagators have $C_{VXY}=0$ and those with vector propagators have \mbox{$C_{SXY}=0$}. The vertex number conventions are given in fig.~\ref{fig:penguinvertex} and all possible diagrams are depicted in Figure~\ref{fig:penguin}. The chiral vertices are parametrized as in eqs.~(\ref{eq:chiralvertices1})-(\ref{eq:chiralvertices2}) with $A=1,B=2$ for vertex 1, $A=3,B=4$ for vertex 2 and $A=7,B=8$ for vertex 4. Vertex 3 can be a chiral vertex, in this case $A=5,B=6$ is used. Otherwise, we will denote it with a index $5$ and give as additional subscript the kind of vertex. The contributions to the Wilson coefficients from these diagrams read
\begin{align}
  C^{(a)}_{SLL}&= \frac 1{M_{S0}^2-s}G_1G_3G_7\kl{G_6 B^{(a,b)}_0+(G_5M_{F1}M_{F2}+G_6M_S^2)C^{(a,b)}_0 } \\
  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2-s} G_1G_3G_{5,SVV}G_8 M_F C^{(i-l)}_0
\end{align}
Here, the arguments of the Passarino-Veltman integrals are as follows, with $s=M_{B^0_q}^2$:
\begin{align}
C_X^{(a,b)} &=C_X (s,0,0,M_{F2}^2,M_{F1}^2,M_{S}^2) \,\hspace{1cm}
B_X^{(a,b)}  = B_X(s,M_{F1}^2,M_{F2}^2)  \\
C_X^{(c,d)} & = C_X(0,s,0,M_{F}^2,M_{S1}^2,M_{S2}^2) \\
C_X^{(e,f)} &=C_X(s,0,0,M_{F2}^2,M_{F1}^2,M_{V}^2) \,\hspace{1cm}
B_X^{(e,f)} = B_X(s,M_{F1}^2,M_{F2}^2)\\
C_X^{(g,h)}&=C_X(0,s,0,M_{F}^2,M_{V1}^2,M_{V2}^2) \,\hspace{1cm}
B_X^{(g,h)}=B_X(s,M_{V1}^2,M_{V2}^2) \\
C_X^{(i-l)} &= C_X(0,s,0,M_{F}^2,M_{S}^2,M_{V}^2) \,\hspace{1cm}
B_X^{(i-l)} = B_X(s,M_{S}^2,M_{V}^2)
\end{align}

\subsection{Box Contributions}
\begin{figure}[htpb]
  \centering
  \begin{tabular}{ccc}
  \includegraphics[width=4cm]{FeynAmps/BoxIns1} & \includegraphics[width=4cm]{FeynAmps/BoxIns2} & \includegraphics[width=4cm]{FeynAmps/BoxIns4} \\
  \end{tabular}
  \caption{Vertex number conventions for a set of representative box diagrams}
  \label{fig:boxvertex}
\end{figure}
\begin{figure}[hbt]
 \centering
 \begin{tabular}{ccc}
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxS1} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxS1ins2} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxS2ins4} \\
  (a) & (b) & (c) \\
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxS2} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxS2ins2} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxS1ins4} \\
  (d) & (e) & (f) \\
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxSV1} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxSV1ins2} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxSV2ins4} \\
  (g) & (h) & (i) \\
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxVS1} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxVS1ins2} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxVS2ins4} \\
  (j) & (k) & (l)
 \end{tabular}
  \caption{Generic box diagrams I}
 \label{fig:box1}
\end{figure}
\begin{figure}[hbt]
 \centering
 \begin{tabular}{ccc}
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxSV2} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxSV2ins2} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxSV1ins4} \\
  (m) & (n) & (o) \\
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxVS2} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxVS2ins2} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxVS1ins4} \\
 (p) & (q) & (r)  \\
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxV1} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxV1ins2} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxV1ins4} \\
  (s) & (t) & (u) \\
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxV2} &   \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxV2ins2} &
  \includegraphics[width=3cm]{FeynAmps/BtoLLpBoxV2ins4} \\
  (v) & (w) & (x)
 \end{tabular}
 \caption{Generic box diagrams II}
 \label{fig:box2}
\end{figure}
The vertex number conventions for boxes are shown in figs.~\ref{fig:boxvertex}, while all possible generic diagrams are given in Figures~\ref{fig:box1} and \ref{fig:box2}. All vertices are chiral and they are parametrized as in eqs.~(\ref{eq:chiralvertices1})-(\ref{eq:chiralvertices2}) with $A=1,B=2$ for vertex 1, $A=3,B=4$ for vertex 2, $A=5,B=6$ for vertex 3 and $A=7,B=8$ for vertex 4. If there are two particles of equal type in a loop (say, two fermions), the one between vertices 1 and 2 (2 or 3) will be labelled $F1$ and the other one will be $F2$. The contributions to the different Wilson coefficients read
\begin{align}
  C^{(a)}_{SLL} &= -G_1G_3G_5G_7M_{F1}M_{F2} \cdot D^{(a-c)}_0 \\
  C^{(a)}_{SLR} &= -G_1G_3G_ 6G_8M_{F1}M_{F2}\cdot D^{(a-c)}_0 \\
  C^{(a)}_{VLL}&=-G_2G_3G_6G_7 \cdot D^{(a-c)}_{00} \\
  C^{(a)}_{VLR}&=-G_2G_3G_5G_8 \cdot D^{(a-c)}_{00} \\
C^{(b)}_{SLL} &= -G_1G_3G_5 G_7 M_{F1}M_{F2} \cdot D^{(a-c)}_0 \\
C^{(b)}_{SLR} &= -G_1G_3G_ 6 G_8M_{F1}M_{F2}\cdot D^{(a-c)}_0 \\
C^{(b)}_{VLL}&=G_2G_3G_5 G_8  \cdot D^{(a-c)}_{00} \\
C^{(b)}_{VLR}&=G_2G_3G_6 G_7  \cdot D^{(a-c)}_{00} \\
C^{(c)}_{SLL} &= \frac 12 G_1G_3G_5G_7 M_{F1}M_{F2}D^{(a-c)}_0 \\
C^{(c)}_{SLR} &= -2 G_1G_4G_5G_8 D^{(a-c)}_{00} \\
C^{(c)}_{VLL} &= -\frac 12 G_2G_4G_5G_7 M_{F1}M_{F2} D^{(a-c)}_0 \\
C^{(c)}_{VLR} &= -G_2G_3G_5G_8 D^{(a-c)}_{00} \\
  C^{(d)}_{SLL} &= \frac 12 G_1G_3G_5G_7M_1M_2 \cdot D^{(d-f)}_0 \\
  C^{(d)}_{SLR} &= 2G_1G_3G_6G_8 \cdot D^{(d-f)}_{00} \\
  C^{(d)}_{VLL}&= -G_2G_3G_6G_7 \cdot D^{(d-f)}_{00} \\
  C^{(d)}_{VLR}&=\frac 12 G_2G_3G_5G_8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s-u)}_{0}\\
  C^{(u)}_{SLR}&= -8 G_2G_3G_5 G_8  D^{(s-u)}_{00}  \\
  C^{(u)}_{VLL}&= 16 G_1G_3G_5 G_7  D^{(s-u)}_{00}\\
  C^{(u)}_{VLR}&= 2 G_1G_4G_5 G_8  M_{F1}M_{F2} D^{(s-u)}_{0}\\
  C^{(v)}_{SLL}&= 8 G_2G_3G_6G_7 M_{F1}M_{F2} D^{(v-x)}_{0}\\
  C^{(v)}_{SLR}&= 8 G_2G_3G_5G_8 \kl{C^{(v-x)}_0+M_{V1}^2D^{(v-x)}_0}  \\
  C^{(v)}_{VLL}&= -4 G_1G_3G_5G_7 \kl{C^{(v-x)}_0+M_{V1}^2D^{(v-x)}_0-3D^{(v-x)}_{00}}\\
  C^{(v)}_{VLR}&= 2 G_1G_3G_6G_8 M_{F1}M_{F2} D^{(v-x)}_{0}\\
  C^{(w)}_{SLL}&= 8 G_1G_3G_6 G_8  M_{F1}M_{F2} D^{(v-x)}_{0}\\
  C^{(w)}_{SLR}&= 32 G_1G_3G_5 G_7  D^{(v-x)}_{00}  \\
  C^{(w)}_{VLL}&= -2 G_2G_3G_6 G_7  M_{F1}M_{F2} D^{(v-x)}_0\\
  C^{(w)}_{VLR}&= 4 G_2G_3G_5 G_8  D^{(v-x)}_{00}\\
  C^{(x)}_{SLL}&= -4 G_1G_4G_5 G_8  M_{F1}M_{F2} D^{(v-x)}_{0}\\
  C^{(x)}_{SLR}&= -8 G_1G_3G_5 G_7 (C^{(v-x)}_0+M_{V1}^2D^{(v-x)}_0-3 D^{(v-x)}_{00})  \\
  C^{(x)}_{VLL}&= -2 G_2G_3G_5 G_8  M_{F1}M_{F2} D^{(v-x)}_0\\
  C^{(x)}_{VLR}&= -4 G_2G_4G_5 G_7(C^{(v-x)}_0+M_{V1}^2D^{(v-x)}_0)
  \end{align}
The arguments of the loop functions for the different amplitudes are
\begin{align}
D_X^{(a-c)}&= D_X(M_{F1}^2,M_{F2}^2,M_{S1}^2,M_{S2}^2) \\
D_X^{(d-f)}&= D_X(M_{F1}^2,M_{F2}^2,M_{S1}^2,M_{S2}^2) \\
C_X^{(g-i)}&= C_X(\vec 0_3, M_{F2}^2,M_V^2,M_{S}^2) \,\hspace{1cm}
D_X^{(g-i)}= D_X(M_{F1}^2,M_{F2}^2,M_{V}^2,M_{S}^2)\\
C_X^{(j-l)}&= C_X(\vec 0_3,M_{F2}^2,M_S^2,M_{V}^2) \,\hspace{1cm}
D_X^{(j-l)}= D_X(M_{F1}^2,M_{F2}^2,M_{S}^2,M_{V}^2)\\
C_X^{(m-o)}&= C_X(\vec 0_3, M_{F2}^2,M_{F1}^2,M_V^2) \,\hspace{1cm}
D_X^{(m-o)}= D_X(M_{F2}^2,M_{F1}^2,M_S^2,M_V^2)\\
C_X^{(p-r)}&= C_X(\vec 0_3, M_{F2}^2,M_{F1}^2,M_S^2) \,\hspace{1cm}
D_X^{(p-r)}= D_X(M_{F2}^2,M_{F1}^2,M_V^2,M_S^2) \\
C_X^{(s-u)}&= C_X(\vec 0_3, M_{F2}^2,M_{V1}^2,M_{V2}^2)\,\hspace{1cm}
D_X^{(s-u)}= D_X(M_{F1}^2,M_{F2}^2,M_{V1}^2,M_{V2}^2)  \\
C_X^{(v-x)}&= C_X(\vec 0_3, M_{F2}^2,M_{F1}^2,M_{V2}^2) \,\hspace{1cm}
D_X^{(v-x)}= D_X(M_{F2}^2,M_{F1}^2,M_{V1}^2,M_{V2}^2)
\end{align}

\end{appendix}


\section{Introduction}

Transformer-based models continue to achieve state-of-the-art performance on a number of NLU and NLG tasks.
A rich body of literature, termed BERTology \cite{Rogers2020API}, has evolved to analyze and optimize these models.
One set of studies comment on the functional role and importance of attention heads in these models \cite{clark2019does,michel2019sixteen, voita2019analyzing, voita2019bottom,liu2019attentive,belinkov2017neural}.
Another set of studies have identified ways to make these models more efficient by methods such as pruning \cite{mccarley2019pruning, gordon2020compressing, sajjad2020poor, budhraja2020weak}.
A third set of studies show that multilingual extensions of these models, such as Multilingual BERT \cite{devlin-etal-2019-bert}, have surprisingly high crosslingual transfer \cite{pires2019multilingual,wu-dredze-2019-beto}.%

Our work lies in the intersection of these three sets of methods:
We analyze the importance of attention heads in multilingual models based on the effect of pruning on performance for both in-language and cross-language tasks.
We base our analysis on BERT and mBERT \cite{devlin-etal-2019-bert} and evaluate (i) in-language performance in English on four tasks from the GLUE benchmark - MNLI, QQP, QNLI, SST-2, and (ii) cross-language performance on the XNLI task on 10 languages - Spanish, German, Vietnamese, Chinese, Hindi, Greek, Urdu, Arabic, Turkish, and Swahili. With these, we derive two broad sets of findings.
Notice that we prune only the attention heads and not other parts of the network, such as the fully connected layers or the embedding layers.
Thus all our results are restricted to comments on role of attention capacity in multilingual models.

First, we compare and contrast the effect of pruning on in-language performance of BERT and mBERT.
Intuitively, the reduced dedicated attention capacity in mBERT for English may suggest a more adverse effect of pruning on the GLUE tasks.
However, we find that mBERT is just as robust to pruning as is BERT.
At 50\% random pruning, average accuracy drop with mBERT on the GLUE tasks is 2\% relative to the base performance, similar to results for BERT reported in \citeauthor{budhraja2020weak}\shortcite{budhraja2020weak}.
Further, mBERT has identical preferences amongst layers to BERT, where (i) heads in the middle layers are more important than the ones in top and bottom layers, and (ii) consecutive layers cannot be simultaneously pruned.

Second, we study the effect of pruning on cross-language performance across languages that are categorised by language family (SVO/SOV/VSO/Agglutinative) and corpus size used for pre-training (high/medium/low-resource).
We find that mBERT is significantly less robust to pruning on the XNLI task: At 50\% random pruning, performance averaged across languages drops by 5\%.
However, this drop is not uniform across languages: The drop in SVO and high-resource languages is lower confirming that more pre-training data and similar language family %
make crosslingual transfer more robust.

Next, layer-wise pruning results reveal several insights into the functional roles of different layers in multilingual models.
Pruning bottom layers sensitively affects cross-language performance where the drop across languages shows a trend based on the language family: Agglutinative $>$ VSO $>$ SOV $>$ SVO.
On the other hand, pruning top layers has a lower impact on accuracy, but the order across language families is the exact reverse of the order for the bottom layers: SVO $>$ SOV $>$ VSO $>$ Agglutinative.
These results suggest that the bottom layers of the network are storing crosslingual information which is particularly crucial for performance on low-resource languages and languages quite different from the fine-tuned language (En-SVO).
Further, the top layers of the network are specialising for the fine-tuned task and relatively more important for languages that are related to the fine-tuned language.
We confirm this intuition by showing that the impact of fine-tuning on attention heads (captured by the difference in entropy of attention distributions across tokens) is much higher on the top layers than the middle or bottom layers.
We also observe that fine-tuning for a single epoch recovers about 93\% of cross-language performance consistently across all languages.

\begin{figure*}
    \includegraphics[width=6in]{plots/resource_layers2.png}
    \caption{Layerwise pruning - Comparison across four GLUE tasks[(a)-(d)], and XNLI task: language family[(e)-(h)], and pre-training corpus size[(i)-(k)]}

    \label{label_combined_layers}
\end{figure*}

\section{In-language performance}

\citeauthor{DBLP:conf/acl/ConneauKGCWGGOZ20}\shortcite{DBLP:conf/acl/ConneauKGCWGGOZ20} argue that in multilingual models such as mBERT there is always a trade-off between \textit{transfer} and \textit{capacity dilution}. Specific to our focus on attention heads, the finite capacity of a fixed number of attention heads is shared by many languages. We refer to this as the \textit{attention capacity} of the network. As a result of this shared capacity, the in-language performance of multilingual models is typically poor when compared to monolingual models. Thus, the first question to ask is \textit{"Does pruning attention capacity affect the in-language performance of mBERT more adversely than BERT?"} Intuitively, if the attention capacity of mBERT is limited to begin with, then pruning it further should lead to large drops in performance. To check this intuition, we take the publicly available mBERT$_{BASE}$ model
which is pretrained on 104 languages.
We then fine-tune and evaluate it on four GLUE tasks: MNLI-M, QQP, QNLI, SST-2 \cite{wang2018glue}; and compare it with BERT$_{BASE}$. Following the evaluation setup as in \citeauthor{budhraja2020weak}\shortcite{budhraja2020weak}, we either (i) randomly prune k\% of attention heads in mBERT, or (ii) prune all heads in specific layers (top, middle, or bottom). In each case, after pruning we finetune the model for 10 epochs. Since the pruned attention heads are randomly sampled, we report the average across three different experiment runs. The standard deviation across three runs of experiments averaged across all languages is 0.51\% of the reported mean values. Our main observations are:%

\noindent \textbf{mBERT is as robust as BERT.} From Figure \ref{fig:random_pruning} we observe that at 0\% pruning, the performance of mBERT is comparable to BERT on 2 out of the 4 tasks (except MNLI-M and SST-2). Further, on pruning, the performance of mBERT does not drop drastically when compared to BERT. At all levels of pruning (0 to 90\% heads pruned) the gap between mBERT and BERT is more or less the same as that at the starting point (0\% pruning). This trend is more clear from Figure \ref{fig:random_pruning} (e) which shows the average drop in the performance at different levels of pruning relative to the base performance (no pruning). Even at 50\% pruning the average performance of mBERT drops by only 2\% relative to the base performance. Thus, contrary to expectation, mBERT is not adversely affected by pruning despite its seemingly limited attention capacity for each language.\\
\noindent \textbf{mBERT has same layer preferences as BERT.} From their pruning experiments, \citeauthor{budhraja2020weak}\shortcite{budhraja2020weak} show that the middle layers in BERT are more important than the top or bottom layers: The performance of BERT does not drop much when pruning top or bottom layers as compared to middle layers. We perform similar experiments with mBERT and find that the results are consistent. As shown in Figure \ref{label_combined_layers}) (a) to (d) across the 4 tasks mBERT does not have any preference amongst top and bottom layers, but middle layers are more important. This is especially true when we prune more layers ($>$4 out of the 12 layers in mBERT). \\
\noindent \textbf{mBERT doesn't prefer pruning consecutive layers (same as BERT).} Some works on BERTology \cite{lan2019albert} have identified that consecutive layers of BERT have similar functionality. We find supporting evidence for this in our experiments. In particular, pruning consecutive layers of mBERT as opposed to odd or even layers leads to a higher drop in the performance (see Table \ref{tab:mbert_glue}). %
Similar results are reported by \citeauthor{budhraja2020weak}\shortcite{budhraja2020weak} for BERT.
Thus, despite being multilingual, mBERT's layers have the same ordering of importance as BERT.

\begin{table}[tp]
\small
\begin{center}
\begin{tabular}{ c c c c c }
 \hline
 \rule{0pt}{1.5ex} Layers Pruned & MNLI-M & QQP & QNLI & SST-2 \\
 \hline
 \rule{0pt}{1.5ex} Top six & 78.45 & 90.53 & 87.46 & 89.33 \\
 \rule{0pt}{1.5ex} Bottom six & 78.71 & 89.77 & 87.22 & 87.84 \\
 \rule{0pt}{1.5ex} Middle six & 76.72 & 89.07 & 85.28 & 87.5 \\
 \rule{0pt}{1.5ex} Odd six & 78.94 & 90.24 & 88.72 & 88.64 \\
 \rule{0pt}{1.5ex} Even six & 79.82 & 90.17 & 89.09 & 90.02 \\
 \hline

\end{tabular}
\caption{Effect of pruning self-attention heads of consecutive v/s non-consecutive layers of mBERT}
\label{tab:mbert_glue}
\end{center}
\end{table}

\section{Cross-language performance}

We now study the impact of pruning on the crosslingual performance of mBERT. Again, intuitively, one would expect that if we prune some heads then the crosslingual signals learned implicitly during training may get affected resulting in poor performance on downstream tasks. To check this intuition, we perform experiments with 11 languages on the XNLI dataset \cite{conneau2018xnli}.
We categorize these languages according to their structural similarity as SVO (English, Spanish, German, Vietnamese, Chinese),
SOV (Hindi, Greek, Urdu),
VSO (Arabic),
and Agglutinative (Turkish, Swahili). Further, we follow \citeauthor{wu2020all}\shortcite{wu2020all} and classify these languages as High Resource (English, Spanish, German), Medium Resource (Arabic, Vietnamese, Chinese, Turkish), and Low Resource (Hindi, Greek, Urdu, Swahili) based on the size of the pretraining corpus. %
Similar to our in-language experiments reported above, we either (i) randomly prune k\% of attention  heads in mBERT, or (ii) prune all heads in specific layers (top, middle, or bottom). In each case, after pruning we finetune the model for 10 epochs on the task specific training data.  Our mains observations are: \\
\begin{figure}[tp]
    \includegraphics[width=2.7in]{plots/xnli_pp.png}
    \caption{XNLI task - Performance of various language families at different percentages of pruning.}
    \label{label_xnli_pp}
\end{figure}
\noindent\textbf{mBERT is less robust in a cross language setup.} In Figure \ref{label_xnli_pp}, we plot the relative drop in performance from the baseline (0\% pruning) at different levels of pruning (10-90\%).
We observe that at 50\% pruning the relative drop in performance is around 5\% and at 90\% pruning the drop is around 10-15\%. We contrast this with the results in \ref{fig:random_pruning} (e) where the relative drop in performance for in-language tasks was more modest (around 2\% drop at 50\% pruning and 7.5\% drop at 90\% pruning). Thus, in a cross language setup mBERT is affected more adversely at higher levels of pruning (beyond 25\%). However, pruning upto 25\% of the heads does not affect the performance much ($\approx$ 2.5\% relative drop).

\noindent\textbf{mBERT is more robust for SVO and high resource languages.} Referring to Figure \ref{label_xnli_pp}, we observe that high resource languages (more pretraining data) and SVO languages (similar to English) are relatively less adversely affected by pruning. Among the non-SVO languages,  agglutinative languages like Turkish are most affected by pruning\footnote{Note that, there is a high overlap between our SVO languages and high resource languages (since in the XNLI dataset most SVO languages are European languages which are high/mid resource languages)}.

\noindent\textbf{mBERT is sensitive to pruning bottom layers for crosslingual transfer.}
Many recent works have shown that middle layers are important in BERT \cite{Pande2021TheHH, Rogers2020API, jawahar-etal-2019-bert, liu2019linguistic}. In this section, we analyse the relative importance of layers for different languages in a crosslingual task. Referring to Figure \ref{label_combined_layers} (e) to (k), we observe that for all languages, the bottom layers are more important than the top layers for crosslingual transfer. Specifically, we compare the difference $d(\cdot)$ between the relative performance drop when pruning the same number of top and bottom layers. We observe that $d(\mbox{SVO})$ $<$ $d(\mbox{SOV})$ $<$ $d(\mbox{VSO})$ $<$ $d(\mbox{Agglutinative})$ [(e) to (h) of Figure \ref{label_combined_layers}] and $d(\mbox{High~resource})$ $<$ $d(\mbox{Medium~resource})$  $<$ $d(\mbox{Low~resource})$ [(i) to (k) of Figure \ref{label_combined_layers}]. %
This suggests that most of the crosslingual information is stored in the bottom layers. While pruning top layers has a lower impact on accuracy, the order across language families is the exact reverse of the order for the bottom layers:  $d(\mbox{SVO})$ $>$ $d(\mbox{SOV})$ $>$ $d(\mbox{VSO})$ $>$ $d(\mbox{Agglutinative})$. Lastly, we observe that unlike BERT, mBERT is less sensitive to pruning middle layers for most languages.

\noindent\textbf{mBERT is more sensitive to pruning consecutive layers.}
We observe that mBERT is more sensitive to pruning consecutive layers. On average, pruning \textit{even} layers works better than pruning \textit{odd} or consecutive layers. This suggests that retaining the first layer (in even case) is beneficial.

\noindent\textbf{mBERT does not benefit from extensive fine-tuning after pruning.} We observe that on average (over all pruning experiments and languages on the XNLI task), mBERT achieves 93\% of the final accuracy after just one epoch of fine-tuning. Further fine-tuning causes only marginal gains in the accuracy.
We then analyse the changes across layers to identify any preference for specific layers during fine tuning.
We then compute the entropy of each attention head in each layer for a given input token and average this entropy across all tokens in 500 sentences from the dev set. We plot the difference between the entropy of the unpruned heads before and after fine-tuning (see Figure \ref{label_entropy_change}). We notice that just like BERT \cite{kovaleva2019revealing}, the change in entropy is maximum for attention heads in the top layers (0.176) as compared to bottom (0.047) or middle layers (0.042). This  suggests that mBERT adjusts the top layers more during fine-tuning.

\begin{figure}[tp]
\centering
  \begin{tabular}{@{\hskip 0in}c}
    \includegraphics[height=1.2in]{plots/90pp_ftuning_layer_cropped.png}
  \end{tabular}
    \caption{Change in entropy of alive heads before and after 1 epoch fine-tuning for 90\% rand. pruned model.}
    \label{label_entropy_change}
\end{figure}

\section{Conclusion}
We studied the effect of pruning on mBERT and found that for in-language tasks, it is equally robust and has the same layer preferences as BERT.
For cross language tasks, mBERT is less robust with significant drops especially for low resource and non-SVO languages. Bottom layers are more important and pruning consecutive layers is not preferred.
The importance of top and bottom layers have the reverse order across language families.