# Error-Mitigated Quantum Random Access Memory

Wenbo Shi1, Neel Kanth Kundu23, Matthew R. McKay3, and Robert Malaney1
1School of Electrical Engineering and Telecommunications, University of New
South Wales, Sydney, NSW, Australia.  2Centre for Applied Research in
Electronics, Indian Institute of Technology Delhi, New Delhi, India.
3Department of Electrical and Electronic Engineering, University of Melbourne,
Melbourne, Victoria, Australia.

###### Abstract

As an alternative to quantum error correction, quantum error mitigation
methods, including Zero-Noise Extrapolation (ZNE), have been proposed to
alleviate run-time errors in current noisy quantum devices. In this work, we
propose a modified version of ZNE that provides for a significant performance
enhancement on current noisy devices. Our modified ZNE method extrapolates to
zero-noise data by evaluating groups of noisy data obtained from noise-scaled
circuits and selecting extrapolation functions for each group with the
assistance of estimated noisy simulation results. To quantify enhancement in a
real-world quantum application, we embed our modified ZNE in Quantum Random
Access Memory (QRAM) - a memory system important for future quantum networks
and computers. Our new ZNE-enhanced QRAM designs are experimentally
implemented on a 27-qubit noisy superconducting quantum device, the results of
which demonstrate that with reasonable estimated simulation results, QRAM
fidelity is improved significantly relative to traditional ZNE usage. Our
results demonstrate the critical role the extrapolation function plays in ZNE
- judicious choice of that function on a per-measurement basis can make the
difference between a quantum application being functional or non-functional.

##  I Introduction

Current quantum devices are widely regarded as Noisy Intermediate-Scale
Quantum (NISQ) devices - quantum-enabled systems that do not have low enough
intrinsic errors to implement quantum error correction [1]. To reach a quantum
advantage using current NISQ devices, growing attention is being focused on
quantum error mitigation methods, schemes that attempt to reduce the presence
of intrinsic device errors [2, 3]. In general, quantum error mitigation
generates a number of ancillary quantum circuits and applies classical post-
processing to the measurement outcomes of the circuits in an attempt to deduce
zero-noise results. Such mitigation is known to be partially effective in
reducing intrinsic errors within many current NISQ devices, especially when
the intrinsic errors mainly consist of quantum gate errors, measurement
errors, decoherence errors, and/or cross-talk errors [4, 5].

The most common methods discussed for quantum error mitigation include Zero-
Noise Extrapolation (ZNE), Probabilistic Error Cancellation (PEC), Clifford
Data Regression (CDR), and Measurement Error Mitigation (MEM) [6, 7, 8, 9]. In
ZNE, the zero-noise expectation value of an operator is extrapolated from
artificially noise-scaled circuits [6, 10, 11]. In PEC, a target (ideal)
circuit is approximated by averaging over distinct noisy circuits which
consist of noisy, but implementable, quantum gates. The expectation values of
the operator for the noisy circuits are combined to approximate the zero-noise
expectation value for the target circuit [12, 7]. CDR executes a group of
near-Clifford circuits on a simulator and a quantum device, where the near-
Clifford circuits are quantum circuits (collectively similar to the target
circuit) composed largely of Clifford gates (gates that map Pauli operators to
Pauli operators). It then utilizes linear regression or machine-learning
methods to infer the zero-noise expectation value for the target circuit via
the expectation values obtained from the near-Clifford circuits [2, 13]. MEM
aims to reduce measurement errors by generating a calibration matrix, whose
inverse is utilized to compensate for the measurement errors [14].

In this work, we introduce a variant of ZNE, namely selected-ZNE (sZNE). We
will consider the implementation of ZNE and sZNE on a current NISQ device - a
superconducting quantum device manufactured by IBM [15]. This device is
manipulated via IBM’s open-source software development kit—the Quantum
Information Science toolKit (Qiskit) [16]. Via Qiskit, we operate a simulator,
ibmq_qasm_simulator, and a 27-qubit quantum device, ibm_cairo.

In order to investigate the performance of sZNE, we will apply ZNE and sZNE to
a specific application, namely, Quantum Random Access Memory (QRAM) - a system
for storing both classical _and_ quantum information in an array of memory
cells [17, 18, 19, 20]. QRAM can be considered a quantum version of classical
RAM, with the added ability to query multiple addresses simultaneously. QRAM
can also provide the fundamental architecture for realizing quantum oracles
[21, 22].

(a)

(b)

(c)

Figure 1:  (a), (b) Schematic of ZNE shows how it calculates the zero-noise
probabilities. The square dots between subfigures represent the intervening
probabilities $P_{2}$ to $P_{2^{n}-1}$. (c) Schematic of ZNE that calculates
the zero-noise expectation value. Note that in traditional ZNE, only one
extrapolation function is selected to extrapolate the zero-noise probabilities
or the zero-noise expectation value.

Currently, the performance of ZNE is restricted due to the ambiguity of which
extrapolation function to be used and to what precise data each extrapolation
function should be applied. As we shall see, by providing flexibility to both
these issues much improved performance on current ZNE algorithms can be
delivered. To provide focus, we couple our modified ZNE algorithm, sZNE, to a
tomography application, and investigate the fidelity of a state “pulled” from
QRAM on the device with the ideal QRAM state. Noting that numerous
extrapolation functions can be used in deployments of ZNE, we will see how
sZNE allows the selection of the optimal extrapolation function (for a given
measurement) with the assistance of estimated noisy simulation results. We
will show under what accuracy of the estimated noisy simulation results the
sZNE algorithm can produce gain relative to ZNE. As such an estimate becomes
more accurate, we will see how we can view our results as providing for the
optimal performance of QRAM under ZNE using current NISQ devices. In the limit
of noiseless simulation outcomes, our experimental results expose the critical
importance of the choice of extrapolation function within ZNE algorithms - the
main purpose of our work. More specifically, in the context of our application
we shall see that if the most accurate extrapolation function (out of a choice
of four) is chosen for each measurement, then an eight-memory-cell QRAM moves
from a low-fidelity (non-functional) outcome to a high-fidelity (functional)
outcome.

The main contributions of this work are summarized as follows. (i) We propose
a modified version of ZNE, namely, sZNE, and then, we embed ZNE and sZNE into
a quantum device and experimentally deploy both algorithms in the context of
QRAM with quantum state tomography in order to show their relative real-world
performance (as applied to an important application). Based on our
experimental results, (ii) we indicate under what statistical constraints on
the accuracy of noiseless simulations would sZNE provide improved outcomes,
relative to ZNE, in practice. (iii) Finally, we discuss some open questions
and consider the future implementation of sZNE in the context of QRAM.

In the following, we introduce ZNE in detail in Section II before outlining
the specific QRAM architecture we use. Section III presents the procedure of
sZNE and describes our results in experimental deployment. Section V concludes
our work.

##  II Background

Before proceeding let us clarify some of the metrics and variables we will use
in our analysis. Suppose that $O$ is an operator with expectation value
$\left<O\right>$ and discrete eigenvalues $\\{a_{x},\,x=1,2,\cdots,2^{n}\\}$.
Here, $n$ is the number of some qubits (represented by a state $|\psi\rangle$)
to be measured by the operator $O$. In the operational perspective, $C_{tot}$
copies of $|\psi\rangle$ are prepared, and each copy is measured by $O$. The
number of times that $a_{x}$ is obtained as the result of the measurement is
denoted as $C_{x}\in[0,C_{tot}]$. The frequency of obtaining $a_{x}$ from a
limited number of trials is defined as $F_{x}=C_{x}/C_{tot}$. The probability
of obtaining $a_{x}$ with zero finite sampling error is obviously
$P_{x}=\lim_{C_{tot}\to\infty}\left(C_{x}/C_{tot}\right)$. Therefore, the
expectation value of $O$ with respect to the state $|\psi\rangle$ can be
expressed as

$\left<O\right>=\lim_{C_{tot}\to\infty}\sum_{x=1}^{2^{n}}\dfrac{C_{x}}{C_{tot}}a_{x}=\sum_{x=1}^{2^{n}}P_{x}a_{x}\text{.}$
(1)

Henceforth, we assume $P_{x}=F_{x}$.

###  II-A ZNE

ZNE is a quantum error mitigation method that involves running additional
quantum circuits and classical post-processing of experimental data. The main
idea of ZNE is to extrapolate the zero-noise expectation value of an operator
from noise-scaled circuits at different noise levels [23]. ZNE can be divided
into analog and digital ZNE based on the noise-scaling method adopted. Analog
ZNE scales the noise by extending the microwave pulse duration (used to
execute a gate), while digital ZNE scales the noise via the insertion of
additional quantum gates. In this work, we consider only digital ZNE.

In digital ZNE, global and local folding are the two main methods utilized for
generating noise-scaled circuits. Global folding replaces a unitary circuit
$U$ with $U\rightarrow U\left(U^{\dagger}U\right)^{k}$, where $k$ is a
positive integer. As $U^{\dagger}U=I$, this folding operation amplifies the
noise of noisy quantum devices without adding any logical effects. Local
folding folds a _subset_ of gates in $U$, and each gate in the subset is
folded with the same logic as global folding. With a chosen noise-scaling
method, we select the noise-scaling factors
$\boldsymbol{\lambda}=\left[\lambda_{1},\lambda_{2},\cdots,\lambda_{j},\cdots,\lambda_{J}\right]$
to represent the amplification of the noise, where the $\lambda_{j}$ are real
numbers in ascending sequence with (typically) $\lambda_{1}=1$. In total, $J$
noise-scaled circuits will be generated based on $\boldsymbol{\lambda}$, where
the number of gates in the $j^{\text{th}}$ noise-scaled circuit is
$N_{g}^{\lambda_{j}}=\lambda_{j}N_{g}$, where $N_{g}$ is the number of gates
in $U$. Note that the value of $k$ determines the number of gates in the
noise-scaled circuits.

Suppose that the measurement of $O$ is applied to $n$ qubits of the generated
noise-scaled circuits. Following the execution of the noise-scaled circuits on
the quantum device, we collect their measurement results, namely, the
probabilities
$\boldsymbol{P_{x}^{\lambda}}=[\boldsymbol{P_{1}^{\lambda}},\boldsymbol{P_{2}^{\lambda}},\cdots,\boldsymbol{P_{2^{n}}^{\lambda}}]$,
where
$\boldsymbol{P_{1}^{\lambda}}=[P_{1}^{\lambda_{1}},P_{1}^{\lambda_{2}},\cdots,P_{1}^{\lambda_{J}}]$
and the other elements in $\boldsymbol{P_{x}^{\lambda}}$ have similar
representation. We separately define the zero-noise probabilities
$\boldsymbol{P_{x}^{\lambda_{0}}}=[P_{1}^{\lambda_{0}},\cdots,P_{2^{n}}^{\lambda_{0}}]$,
where $\lambda_{0}=0$. The process of finding
$\boldsymbol{P_{x}^{\lambda_{0}}}$ via extrapolation is illustrated in Fig. 1a
and Fig. 1b. The least square method is typically utilized to find the best-
fit parameters of a chosen extrapolation function. With
$\boldsymbol{P_{x}^{\lambda_{0}}}$, we calculate the zero-noise expectation
value $\left<O\right>^{\lambda_{0}}$ via Eq. (1). We can also extrapolate the
zero-noise expectation value $\left<O\right>^{\lambda_{0}}$ after calculating
the noisy expectation values
$\boldsymbol{\left<O\right>^{\lambda}}=[\left<O\right>^{\lambda_{1}},\cdots,\left<O\right>^{\lambda_{j}},\cdots,\left<O\right>^{\lambda_{J}}]$,
as shown in Fig. 1c. Note that $\left<O\right>^{\lambda_{1}}$, for example, is
calculated through $\\{P_{1}^{\lambda_{1}},\cdots,P_{2^{n}}^{\lambda_{1}}\\}$.
In ZNE, where only one extrapolation function is utilized, this alternate
method will provide identical results to the first method based on
probabilities. Originally, ZNE was proposed with Richardson extrapolation [6],
and this remains a commonly used extrapolation function in ongoing studies of
ZNE [7, 13, 24]. Beyond Richardson extrapolation, other functions can be used,
including linear, polynomial, poly-exponential, and exponential extrapolation
[11].

In ZNE, the best choice of the function with its best-fit parameters is
unknown _a priori._ Moreover, extrapolation is unreliable when the known data
sets ($\boldsymbol{\left<O\right>^{\lambda}}$) have critical fluctuations
and/or the chosen function is a high-order polynomial extrapolation function
[25]. These problems limit the power of ZNE and lead to the fact that
$\left<O\right>^{\lambda_{0}}$ extrapolated via ZNE can be inaccurate at times
[13].

###  II-B Bucket brigade QRAM

Figure 2: Bucket brigade scheme for a QRAM with eight memory cells. The binary
tree nodes are initialized to the $|\cdot\rangle$ state, which is a waiting
state. The queried address qubits $|011\rangle$ are read by the tree nodes
sequentially, and the nodes that receive the address qubits will be activated
and changed to the received qubits. The activated tree nodes generate a route
to the memory cell $D_{011}$.

We consider a tomography application that includes QRAM to benchmark and study
the performance of ZNE implemented on the quantum device. The critical
advantage of QRAM is that multiple classical and/or quantum data stored in
memory cells can be queried in superposition. A QRAM query can be expressed as

$\sum_{d=0}^{N-1}\alpha_{d}|d\rangle|0\rangle\xrightarrow{\text{QRAM}}|\Phi\rangle_{f}=\sum_{d=0}^{N-1}\alpha_{d}|d\rangle|D_{d}\rangle\text{,}$
(2)

where $N$ is the number of the memory cells, $\alpha_{d}$ is the amplitude of
each address $|d\rangle$ in the superposition, and $|D_{d}\rangle$ represents
the data stored in the memory cell addressed $|d\rangle$. One of the most
robust designs for QRAM is the bucket brigade scheme, which requires a binary
tree for querying addresses [18]. A bucket brigade QRAM scheme with eight
memory cells is schematically depicted in Fig. 2. In this QRAM, the binary
tree has seven tree nodes, each of which makes a binary decision. Each binary
tree node is a three-level system (a qutrit) with states $|\cdot\rangle$,
$|0\rangle$, and $|1\rangle$, where the $|\cdot\rangle$ state is called the
waiting state. In this three-level system, each tree node is initialized to
the waiting state. The queried address qubits are injected into the tree nodes
from the root node, and the tree nodes read the address qubits sequentially to
generate routes to the queried memory cells. If the tree node receives the
$|0\rangle$ state (the $|1\rangle$ state), this node activates the left
(right) child, which can be either one of the next-level tree nodes or one of
the memory cells. If the queried address is $|011\rangle$, the root node reads
the first address qubit, which is in the state $|0\rangle$. Then, the chosen
second and third-level nodes read the rest of the two qubits sequentially.
After this reading process, the data stored in the memory cell, labeled as
$D_{011}$, is accessed.

Figure 3: Quantum circuit of a bucket-brigade style QRAM with quantum state
tomography. The four purple gates indicate state preparations of four random
quantum states, namely, $|\eta_{1}\rangle$, $|\eta_{2}\rangle$,
$|\eta_{3}\rangle$, and $|\eta_{4}\rangle$. The $H$ represents the Hadamard
gate, and the $X$ is the NOT gate. The two-qubit gates in blue stand for $CX$
gates. The three-qubit gates in orange and green are $CCX$ and controlled-swap
gates, respectively. The four gray boxes with the dashed line indicate that
quantum state tomography is applied to these four qubits.

Based on this QRAM scheme, we construct a bucket-brigade style QRAM circuit
(with quantum state tomography added), as illustrated in Fig. 3. The entire
circuit includes 20 qubits initialized to the $|0\rangle$ state, including
three address qubits, eight tree-node qubits, eight memory qubits, and one
output qubit. The first three qubits (read from the top) are the address
qubits that contain the addresses intended to be queried. Each address qubit
is prepared to the state $|+\rangle=\left(|0\rangle+|1\rangle\right)/\sqrt{2}$
via a Hadamard gate, indicating the queried addresses are $|000\rangle$,
$|001\rangle$, $\cdots$, and $|111\rangle$, i.e.,
$\sum_{d=0}^{N-1}\alpha_{d}|d\rangle=\left(|000\rangle+\cdots+|111\rangle\right)/2\sqrt{2}$.
The next eight qubits are the tree-node qubits, where the second tree-node
qubit is prepared to the $|1\rangle$ state, and the rest to the $|0\rangle$
state. Since qutrits cannot be implemented on the IBM quantum device, we
utilize eight qubits instead of seven qutrits to act as the seven tree nodes
(of Fig. 2). The next eight qubits of Fig. 3 represent the memory cells
(corresponding to the memory cells $D_{000}$ to $D_{111}$ of Fig. 2), each
containing a quantum state or a classical state. The last qubit is an output
qubit containing all of the queried data after the QRAM query.

Typically, once the output qubit acquires all of the queried data, the states
of the binary tree nodes will be reversed to their initial state. This step
can be done by implementing the Controlled-NOT ($CX$) and Controlled-
Controlled-NOT ($CCX$) gates in the QRAM circuit in reverse order, or by re-
setting each tree node to the $|0\rangle$ state and implementing the $X$ gate
to the second tree-node qubit. For simplicity, we ignore this simple step in
the QRAM circuit. To benchmark the performance of the QRAM, we apply quantum
state tomography to the four “tomography qubits” - the three address qubits
and the output qubit - to reconstruct $|\Phi\rangle_{f}$. The quantum state
tomography is represented by the gray boxes in Fig. 3, and the details on the
state tomography implementation are provided in Appendix Acknowledgment. In
our experiments, this QRAM tomography application is employed with ZNE or sZNE
embedded into it.

##  III Experiments

To benchmark the performance of ZNE embedded into the bucket brigade QRAM, we
select the entanglement fidelity $F$, as our main performance metric, where
$F$ is given by

$F=\left(\text{Tr}\sqrt{\sqrt{\rho}\,\,\rho^{\prime}\sqrt{\rho}}\right)^{2}\text{.}$
(3)

Note that $\rho=|\Phi\rangle_{f}\langle\Phi|$ is the noiseless density matrix,
and $\rho^{\prime}$ is the density matrix that is reconstructed by quantum
state tomography. In our experiments, $U$ is the QRAM circuit which excludes
the quantum state tomography. For the execution of the state tomography (see
Appendix Acknowledgment), 81 tomography circuits ($\mathbb{U}_{1}$ to
$\mathbb{U}_{81}$) with distinct measurement operators are generated. These
measurement operators are $\\{XXXX,XXXY,\cdots,ZZZZ\\}$, and note that the
measurement operator in $\mathbb{U}_{81}$ is $ZZZZ$.

###  III-A Selected-ZNE (sZNE)

Figure 4: Expectation values $\left<O\right>=\left<ZZZZ\right>$ of the QRAM
with eight memory cells with $\epsilon=0$ obtained from the ibm_cairo. Note
that $\Lambda\in\\{\lambda_{0},\lambda_{1},\cdots,\lambda_{J}\\}$,
$\left<O\right>^{\text{ZNE, Poly2}}$ represents $\left<O\right>^{\lambda_{0}}$
obtained via the polynomial extrapolation with order 2, and other symbols
stand for similar meaning. The top inset graph demonstrates the details of
$\left<O\right>^{\lambda_{j}}$. The bottom inset graph illustrates the
absolute errors of the expectation value.

(a)

(b)

Figure 5: (a) $F$ of QRAM with eight memory cells with $\epsilon=0$ obtained
from the ibmq_cairo. (b) Selected rate of the four used extrapolation
functions in $\rm{sZNE}^{\prime}$ or sZNE assuming $\epsilon=0$.

In contrast to ZNE, which applies a chosen extrapolation function to noisy
expectation values, the modified version we introduce here, sZNE, applies
multiple extrapolation functions to noisy probabilities and selects the
optimal extrapolation function among them for each element of
$\boldsymbol{P_{x}^{\lambda}}$. In principle, an infinite number of
extrapolation functions can be used, but in practice, only a limited number
can be accessed. In our experiments, we attempt Richardson extrapolation,
linear extrapolation, and polynomial extrapolation with orders two and three.
We apply these extrapolation functions to each element of
$\boldsymbol{P_{x}^{\lambda}}$ (this step is the same as the schematic shown
in Fig. 1a and Fig. 1b). We then select a specific extrapolated probability
for each element of $\boldsymbol{P_{x}^{\lambda}}$ following

$P_{x}^{\text{sZNE}}=\arg\min_{P\in L}|P-P_{x}^{est}|\text{,}$ (4)

where $P_{x}^{est}$ are estimated noiseless results, and $L$ is a set
including $P_{x}^{\lambda_{1}}$ and all possible extrapolated probabilities.
We further refer to the method with the case where $L$ excludes
$P_{x}^{\lambda_{1}}$ as $\rm{sZNE}^{\prime}$ to distinguish it from sZNE. In
our experiments, we utilize the simulator to generate noiseless simulation
results $P_{x}^{sim}$. As discussed later, $P_{x}^{est}$ could be determined
by various means. However, here we simply simulate this estimate by
introducing Gaussian noise. That is, the generation of $P_{x}^{est}$ is given
by

$P_{x}^{est}=P_{x}^{sim}+\epsilon\text{,}$ (5)

where $\epsilon$ is a random variable given by a zero-mean Gaussian
distribution, i.e., $\epsilon\sim\mathcal{N}(0,\,\sigma^{2})$. The fundamental
idea of sZNE involves exploring various extrapolation functions for individual
elements of $\boldsymbol{P_{x}^{\lambda}}$, with different functions selected
to calculate the expectation value. In contrast, ZNE exclusively employs the
same extrapolation function for all elements of
$\boldsymbol{P_{x}^{\lambda}}$. The selected extrapolated probabilities,
$P_{x}^{\text{sZNE}}$, are utilized to compute $\left<O\right>^{\text{sZNE}}$
via Eq. (1).

###  III-B Experimental Results

We embed ZNE and sZNE into the tomography application containing QRAM to
investigate their performance when implemented on the ibm_cairo. Transpilation
is necessary for executing any quantum circuit on this device. This process
converts quantum gates to basis quantum gates, enabling them to be executed
physically and directly on the device. The basis gates are $CX$, $I$, $X$,
$\sqrt{X}$, and $RZ$ gates, where the $RZ$ gate rotates a single-qubit about
the $Z$-axis with a phase factor. Therefore, the $81$ tomography circuits need
to be transpiled to transpiled tomography circuits first. In our experiments,
$\boldsymbol{\lambda}=[1,1.4,1.7,2.1,2.5]$ and we fold gates locally at random
to generate the noise-scaled circuits, where each transpiled tomography
circuit is converted to five transpiled noise-scaled tomography circuits. The
transpilation process is realized via Qiskit, and Mitiq [26] is utilized to
generate the noise-scaled circuits and to implement extrapolation functions.
Each transpiled noise-scaled tomography circuit is executed $C_{tot}=10,000$
times on the quantum device.

Note, the eight qubits corresponding to the memory cells $D_{000}$ to
$D_{111}$ of Fig. 2, must be initialized (all results _illustrated_ here
assume eight memory cells). In the results shown here we have adopted a memory
allocation given by $|\eta_{1}\rangle$, $|1\rangle$, $|0\rangle$,
$|\eta_{2}\rangle$, $|\eta_{3}\rangle$, $|0\rangle$, $|\eta_{4}\rangle$, and
$|1\rangle$, where $|\eta_{1}\rangle$ to $|\eta_{4}\rangle$ are four random
quantum states. Each one of these four quantum states can be represented by
$\alpha|0\rangle+\beta|1\rangle$: the selected $\alpha$ and $\beta$ of the
four quantum states stored in the memory cells are given in Table. I. Although
not shown, we have also carried out experiments with all classical-data
storage (with all memory qubits set to the $|0\rangle$ state) and all quantum-
data storage (with all memory qubits set to the $|+\rangle$ state). We found
the fidelity results of sZNE considering all classical-data and all quantum-
data storage are improved to 0.97 (from 0.62) and 0.91 (from 0.54),
respectively.

TABLE I: Detailed Information of the Memory Data Quantum State | $\alpha$ | $\beta$
---|---|---
$|\eta_{1}\rangle$ | $0.82+0.26i$ | $0.43-0.28i$
$|\eta_{2}\rangle$ | $-0.62+0.51i$ | $-0.15-0.57i$
$|\eta_{3}\rangle$ | $0.25+0.74i$ | $0.31+0.54i$
$|\eta_{4}\rangle$ | $0.44+0.56i$ | $-0.59-0.38i$

To provide some additional insight into what follows, it is perhaps useful to
consider how our algorithms work on one specific observable. For this we
choose the expectation value of $O=ZZZZ$ via the circuit $\mathbb{U}_{81}$,
the results of which are shown in Fig. 4. We see that $\rm{sZNE}^{\prime}$ and
sZNE both significantly outperform ZNE regardless of which extrapolation
function is used by ZNE. The inset line graph (top) in Fig. 4 demonstrates the
detailed information of the noisy expectation values. We further evaluate
absolute errors between the experimental expectation values and
$\left<O\right>^{sim}$, as shown in the inset bar graph (bottom). The absolute
error $\Delta_{O}$ is defined as

$\Delta_{O}=|\left<O\right>^{\prime}-\left<O\right>^{sim}|\text{,}$ (6)

where
$\left<O\right>^{\prime}\in\\{\left<O\right>^{\lambda_{1}},\left<O\right>^{\text{ZNE,
Poly2}},\left<O\right>^{\text{sZNE'}},\left<O\right>^{\text{sZNE}}\\}$. Note
that $\left<O\right>^{sim}$ represents the expectation value calculated via
the noiseless simulation results, $P_{x}^{sim}$.

We consider the $\epsilon=0$ case in sZNE to evaluate the significance of
employing proper extrapolation functions to the noisy probabilities. The
fidelity results of the tomography application that includes the QRAM with
eight memory cells are illustrated in Fig. 5a, and we see that
$\rm{sZNE}^{\prime}$ and sZNE provide for enhancement in $F$, it being
increased from $0.4$ to $0.76$ and $0.86$, respectively. The selected rates of
the extrapolation functions in $\rm{sZNE}^{\prime}$ and sZNE are demonstrated
in Fig. 5b. These experimental results suggest that the linear extrapolation
function is the most effective in ZNE for our deployed QRAM tomography
application. Note, “unmitigated” refers to the use of $P_{x}^{\lambda_{1}}$
values only.

Beyond the QRAM with eight memory cells, the results of which are explicitly
shown here, we have also evaluated the performance of QRAMs with four and ten
memory cells. The sZNE method improves $F$ of the QRAM with four memory cells
from 0.49 to 0.77 and with ten memory cells from 0.25 to 0.7. Despite the
implementation of sZNE, we observe a decrease in $F$ as the number of memory
cells increases, highlighting the larger scalability challenge of QRAM. That
is, sZNE can alleviate the problem of QRAM scalability, albeit to a limited
extent. Scalability is a known obstacle for constructing a large-scale QRAM
[27], an issue that demands a practical solution before such a quantum-enabled
memory can be fully implemented. The number of qubits and the circuit depth of
a QRAM circuit grow with the number of queried memory cells. As errors
accumulate with circuit depth growth when executing the circuit, the quantum
advantage of QRAMs can be negated [28]. Solutions to this issue remain an open
problem.

Figure 6:  $F$ of the QRAM as a function of the standard deviation, $\sigma$,
of the Gaussian noise with eight memory cells for sZNE and
$\rm{sZNE}^{\prime}$. The dashed line shows the unmitigated results.

(a)

(b)

Figure 7:  Selected rates of the four chosen extrapolation functions in
$\rm{sZNE}^{\prime}$ (a) and sZNE (b).

We then conduct $\rm{sZNE}^{\prime}$ and sZNE with $P_{x}^{est}$, which is
generated by introducing the Gaussian noise to the noiseless simulation
results. The results are shown in Fig. 6. Note that these fidelity results are
averaged from $1000$ repetitions. We see that sZNE provides improved fidelity
results if $\sigma$ is smaller than approximately 0.15. The selected rates of
the four chosen extrapolation functions are illustrated in Fig. 7. The
Richardson extrapolation (the linear extrapolation) is more effective than
other extrapolation functions when $\sigma$ is relatively high (low).

##  IV Discussion

In the above, we have simulated $P_{x}^{est}$ by adding Gaussian noise to the
true value obtained from noiseless classical simulations. Other noise models
could be considered, such as the addition of bias terms or non-Gaussian noise.
Of course, if we could always classically simulate an accurate value for all
probabilities we use, there would be no requirement for ZNE (or variants
thereof). We emphasize again that in most of our calculations, we have assumed
$P_{x}^{est}$ is reliable (close to the true value), meaning that our study
shows how a judicious choice of extrapolation function on a per measurement
basis can dramatically improve the ZNE technique. This is the main message of
our study. We hope this observation motivates the development of new
techniques that can assist in the choice of ZNE extrapolation on a per-
application and per-measurement basis.

We have left open how best to find such a reliable $P_{x}^{est}$ as the
circuits under study scale. As the circuits scale up (e.g. a larger number of
memory cells), exact classical simulations become impossible. In practice, a
potential method to obtain $P_{x}^{est}$ in large circuits is via the
execution of Clifford circuits (on a Clifford simulator) that are approximate
to the circuit of interest. The general-purpose simulator provided by Qiskit
[16] can only simulate up to 32 qubits, while the Qiskit Clifford simulator
(simulator_stabilizer) can simulate up to $5000$ qubits. However, the
condition for simulating a quantum circuit on the Clifford simulator, of
course, is that the quantum circuit only consists of Clifford gates.

Another approximation idea (mentioned in the Introduction) is CDR - a
learning-based error mitigation method using “near-Clifford” circuits - an
approach that has previously delivered some useful outcomes [13]. If future
CDR-like methods can provide for a $P_{x}^{est}$ of reasonable accuracy, then
the algorithm we have outlined here can provide for gain relative to standard
ZNE. One example of this could even be when $P_{x}^{est}$ does not always
enable us to select the best extrapolation function but simply rule out the
poorest extrapolation functions. We could envisage an approach that combines
CDR with a sZNE algorithm in which CDR is used to predict $P_{x}^{est}$ on a
per measurement basis, and the best extrapolation function is chosen based on
that estimate. We suggest this approach as a possible future study not only
for QRAM but also for any application running on a NISQ device.

##  V Conclusions

We introduced a modified ZNE, referred to as sZNE, and applied it to a QRAM
application with quantum state tomography on NISQ devices. Specifically, we
implemented a QRAM with multiple memory cells on a 27-qubit quantum device. We
first conducted sZNE with noiseless simulation results, showing how the
performance of the QRAM was improved significantly in terms of fidelity. Our
experimental data emphasized the significance of the individual selection of
extrapolation functions to manifest the full potential of ZNE. We then
executed sZNE with estimated simulation results generated by introducing
Gaussian noise to the noiseless simulation results. These additional
experimental results demonstrated that sZNE is effective when the standard
deviation of the Gaussian noise is was small. In practice, the estimated
simulation results may be obtained by executing Clifford circuits, or
approximate-Clifford circuits in conjunction with machine learning. In the
NISQ era, quantum error mitigation is likely to remain a critical method for
near-term quantum applications. Improving and bench-marking error mitigation
methods will remain important tasks and will ensure near-term quantum devices
continue to play a constructive role in the path towards full fault-tolerant
quantum computing.

## Acknowledgment

We acknowledge the use of IBM Quantum services for this work and the advanced
services provided by IBM Quantum Hub at the University of Melbourne. RM
acknowledges insightful discussions with Martin Savage. WS is supported by the
China Scholarship Council and the Sydney Quantum Academy, Sydney, NSW,
Australia. NKK acknowledges the support from the INSPIRE Faculty Fellowship
awarded by the Department of Science and Technology, Government of India (Reg.
No.: IFA22‐ENG 344) and the New Faculty Seed Grant from the Indian Institute
of Technology Delhi. MRM is supported by an Australian Research Council Future
Fellowship, funded by the Australian Government (project number FT200100928).

[Quantum State Tomography]

We realize quantum state tomography via Qiskit. In doing this for our
experiments, the 4-qubit density matrix $\rho^{\prime}$ is reconstructed. This
can be expressed as

$\begin{split}\rho^{\prime}&=\frac{1}{16}\sum_{l_{1},l_{2},l_{3},l_{4}=0}^{3}S_{l_{1},l_{2},l_{3},l_{4}}\left(\hat{\sigma}_{l_{1}}\otimes\hat{\sigma}_{l_{2}}\otimes\hat{\sigma}_{l_{3}}\otimes\hat{\sigma}_{l_{4}}\right)\\\
&=\frac{1}{16}\large\left[S_{0,0,0,0}\left(\hat{\sigma}_{0}\hat{\sigma}_{0}\hat{\sigma}_{0}\hat{\sigma}_{0}\right)+\cdots+S_{3,3,3,3}\left(\hat{\sigma}_{3}\hat{\sigma}_{3}\hat{\sigma}_{3}\hat{\sigma}_{3}\right)\large\right]\text{,}\end{split}$
(7)

where $S_{l_{1},l_{2},l_{3},l_{4}}$ are parameters determined by the
measurement results of the tomography circuits, and $S_{0,0,\cdots,0}=1$ (due
to normalization). Here, $\hat{\sigma}_{0}$ to $\hat{\sigma}_{3}$ are the
Pauli matrices, given by

$\begin{split}\hat{\sigma}_{0}&=I=\begin{pmatrix}1&0\\\
0&1\end{pmatrix}\text{,}\quad\hat{\sigma}_{1}=X=\begin{pmatrix}0&1\\\
1&0\end{pmatrix}\text{,}\\\ \hat{\sigma}_{2}&=Y=\begin{pmatrix}0&-i\\\
i&0\end{pmatrix}\text{, and }\,\hat{\sigma}_{3}=Z=\begin{pmatrix}1&0\\\
0&-1\end{pmatrix}\text{.}\end{split}$ (8)

Typically, $3^{n}$ tomography circuits with different measurement operators
are generated for a $n$-qubit state tomography. As the state tomography is
applied to the four tomography qubits, $S_{l_{1},l_{2},l_{3},l_{4}}$ are
determined by the outcomes of the 81 tomography circuits (i.e.,
$\mathbb{U}_{1}$ to $\mathbb{U}_{81}$) in the operational perspective. For the
tomography circuit with the measurement operator $ZXYZ$, for example, the
$Z$-, $X$-, $Y$-, and $Z$-basis measurements are applied to the four
tomography qubits. Qiskit [16] only supports the $Z$-basis measurements, which
means that to implement the $X$-basis measurement, we need to apply the
Hadamard gate before the $Z$-basis measurement. To conduct the $Y$-basis
measurement, we implement the $S^{{\dagger}}$ gate and the Hadamard gate
sequentially before the $Z$-basis measurement, where $S^{{\dagger}}$ is a
phase gate which induces a $-\pi/2$ phase.

The parameters $S_{l_{1},l_{2},l_{3},l_{4}}$ are determined by the results of
the tomography circuits. For instance,
$S_{0,1,2,3}=\left(P_{Z_{1}^{+1}}+P_{Z_{1}^{-1}}\right)\otimes\left(P_{X_{2}^{+1}}-P_{X_{2}^{-1}}\right)\otimes\left(P_{Y_{3}^{+1}}-P_{Y_{3}^{-1}}\right)\otimes\left(P_{Z_{4}^{+1}}-P_{Z_{4}^{-1}}\right)$,
where $P_{Z_{4}^{+1}}$ and $P_{Z_{4}^{-1}}$ are the probabilities of obtaining
the $+1$ and $-1$ eigenvalues, respectively, when the $Z$-basis measurement is
applied to the fourth tomography qubit. Based on the expression of
$S_{0,1,2,3}$, we can find that the parameters $S_{0,1,2,3}$, $S_{0,1,2,0}$,
$S_{3,1,2,0}$, and $S_{3,1,2,3}$ are all determined by the results of the
tomography circuits with the measurement operator $ZXYZ$. After collecting the
results of the $81$ tomography circuits, we can reconstruct $\rho^{\prime}$
via Eq. (7).

The results of $\mathbb{U}_{81}$ are utilized for evaluating the expectation
value of $ZZZZ$ through Eq. (1). There are a total of $16$ potential outcomes,
each associated with a probability, denoted as
$\\{P_{x},\,x=1,2,\cdots,16\\}$. It is evident that, for example,
$P_{1}=P_{Z_{1}^{+1}}P_{Z_{2}^{+1}}P_{Z_{3}^{+1}}P_{Z_{4}^{+1}}$. After
obtaining the values of $P_{x}$, the expectation value of $ZZZZ$ can be
computed.

## References

  * [1] J. Preskill, “Quantum Computing in the NISQ era and beyond,” _Quantum_ , vol. 2, 79, 2018.
  * [2] P. Czarnik, A. Arrasmith, P. J. Coles, and L. Cincio, “Error mitigation with Clifford quantum-circuit data,” _Quantum_ , vol. 5, 592, 2021.
  * [3] D. Qin, X. Xu, and Y. Li, “An overview of quantum error mitigation formulas,” _Chinese Physics B_ , vol. 31, no. 9, 090306, 2022.
  * [4] C. J. Wood, “Special session: Noise characterization and error mitigation in near-term quantum computers,” in _2020 IEEE 38th International Conference on Computer Design (ICCD)_ , 2020, pp. 13–16.
  * [5] E. Wilson, S. Singh, and F. Mueller, “Just-in-time quantum circuit transpilation reduces noise,” in _2020 IEEE International Conference on Quantum Computing and Engineering (QCE)_ , 2020, pp. 345–355.
  * [6] K. Temme, S. Bravyi, and J. M. Gambetta, “Error mitigation for short-depth quantum circuits,” _Physical Review Letters_ , vol. 119, 180509, 2017.
  * [7] A. Mari, N. Shammah, and W. J. Zeng, “Extending quantum probabilistic error cancellation by noise scaling,” _Physical Review A_ , vol. 104, 052607, 2021.
  * [8] Z. Cai, R. Babbush, S. C. Benjamin, S. Endo, W. J. Huggins, Y. Li, J. R. McClean, and T. E. O’Brien, “Quantum error mitigation,” _arXiv:2210.00921_ , 2023.
  * [9] D. Bultrini, M. H. Gordon, P. Czarnik, A. Arrasmith, M. Cerezo, P. J. Coles, and L. Cincio, “Unifying and benchmarking state-of-the-art quantum error mitigation techniques,” _Quantum_ , vol. 7, 1034, 2023.
  * [10] A. Kandala, K. Temme, A. D. Córcoles, A. Mezzacapo, J. M. Chow, and J. M. Gambetta, “Error mitigation extends the computational reach of a noisy quantum processor,” _Nature_ , vol. 567, no. 7749, pp. 491–495, 2019.
  * [11] T. Giurgica-Tiron, Y. Hindy, R. LaRose, A. Mari, and W. J. Zeng, “Digital zero noise extrapolation for quantum error mitigation,” in _2020 IEEE International Conference on Quantum Computing and Engineering (QCE)_ , 2020, pp. 306–316.
  * [12] S. Zhang, Y. Lu, K. Zhang, W. Chen, Y. Li, J.-N. Zhang, and K. Kim, “Error-mitigated quantum gates exceeding physical fidelities in a trapped-ion system,” _Nature Communications_ , vol. 11, no. 1, 587, 2020.
  * [13] A. Lowe, M. H. Gordon, P. Czarnik, A. Arrasmith, P. J. Coles, and L. Cincio, “Unified approach to data-driven quantum error mitigation,” _Physical Review Research_ , vol. 3 033098, 2021.
  * [14] “Measurement error mitigation,” qiskit.org. https://qiskit.org/ documentation/stable/0.26/tutorials/noise/3_measurement_error_mitigation.html.
  * [15] “IBM Quantum,” ibm.com. https://quantum-computing.ibm.com.
  * [16] M. S. Anis _et al._ , “Qiskit: An open-source framework for quantum computing,” doi.org. https://doi.org/10.5281/zenodo.2573505.
  * [17] V. Giovannetti, S. Lloyd, and L. Maccone, “Quantum random access memory,” _Physical Review Letters_ , vol. 100, 160501, 2008.
  * [18] S. Arunachalam, V. Gheorghiu, T. Jochym-O’Connor, M. Mosca, and P. V. Srinivasan, “On the robustness of bucket brigade quantum RAM,” _New Journal of Physics_ , vol. 17, no. 12, 123010, 2015.
  * [19] O. D. Matteo, V. Gheorghiu, and M. Mosca, “Fault-tolerant resource estimation of quantum random-access memories,” _IEEE Transactions on Quantum Engineering_ , vol. 1, pp. 1–13, 2020.
  * [20] C. T. Hann, G. Lee, S. Girvin, and L. Jiang, “Resilience of quantum random access memory to generic noise,” _PRX Quantum_ , vol. 2, 020311, 2021.
  * [21] O. D. Matteo, V. Gheorghiu, and M. Mosca, “Fault-tolerant resource estimation of quantum random-access memories,” _IEEE Transactions on Quantum Engineering_ , vol. 1, pp. 1–13, 2020.
  * [22] A. Paler, O. Oumarou, and R. Basmadjian, “Parallelizing the queries in a bucket-brigade quantum random access memory,” _Physical Review A_ , vol. 102, 032608, 2020.
  * [23] M. C. Tran, K. Sharma, and K. Temme, “Locality and error mitigation of quantum circuits,” _arXiv:2303.06496_ , 2023.
  * [24] A. He, B. Nachman, W. A. de Jong, and C. W. Bauer, “Zero-noise extrapolation for quantum-gate error mitigation with identity insertions,” _Physical Review A_ , vol. 102, 012426, 2020.
  * [25] G. J. Hahn, “The hazards of extrapolation in regression analysis,” _Journal of Quality Technology_ , vol. 9, no. 4, pp. 159–165, 1977.
  * [26] R. LaRose, A. Mari, S. Kaiser, P. J. Karalekas, A. A. Alves, P. Czarnik, M. El Mandouh, M. H. Gordon, Y. Hindy, A. Robertson, P. Thakre, M. Wahl, D. Samuel, R. Mistri, M. Tremblay, N. Gardner, N. T. Stemen, N. Shammah, and W. J. Zeng, “Mitiq: A software package for error mitigation on noisy quantum computers,” _Quantum_ , vol. 6, 774, 2022.
  * [27] K. Phalak, A. Chatterjee, and S. Ghosh, “Quantum random access memory for dummies,” _arXiv:2305.01178_ , 2023.
  * [28] S. Xu, C. T. Hann, B. Foxman, S. M. Girvin, and Y. Ding, “Systems architecture for quantum random access memory,” _arXiv:2306.03242_ , 2023.


utf8

# The User-Aware Arabic Gender Rewriter

Bashar Alhafni, Ossama Obeid, Nizar Habash
Computational Approaches to Modeling Language Lab
New York University Abu Dhabi
<EMAIL_ADDRESS>
###### Abstract

utf8

##  1 Introduction

Gender stereotypes, both negative and positive, are manifest in most of the
world’s languages Maass and Arcuri (1996); Menegatti and Rubini (2017) and are
further propagated and amplified by NLP systems Sun et al. (2019); Blodgett et
al. (2020) (see Figure 1). This is because NLP systems rely on human-created
language corpora that mirror the societal biases and inequalities of the world
we live in Boyd and Crawford (2012); Olteanu et al. (2019). For instance,
Figure 2(a) presents part of a cooking recipe published on an Arabic popular
cooking website targeting female readers,222https://www.atyabtabkha.com/
whereas Figure 2(b) shows part of an article on career advice that is
published on Harvard Business Review in Arabic targeting male
readers.333https://hbrarabic.com/ However, even if overt gender biases are
removed from datasets before using them to build NLP models, this will not
ultimately reduce the biases produced by systems that are designed to generate
a single text output without taking their target users’ gender preferences
into consideration. Some commercial NLP systems have solved this problem by
generating more than one gender-specific output when the system encounters
ambiguous scenarios. For instance, Google Translate generates both feminine
and masculine translations when translating gender-neutral English sentences
(e.g., I am a doctor) to a limited number of languages, such as Spanish
Kuczmarski (2018); Johnson (2020). However, this approach does not work well
in multi-user contexts (first and second persons, with independent grammatical
gender preferences), particularly when dealing with gender-marking
morphologically rich languages. One example of this phenomenon is the Arabic
machine translation of the sentence I am a doctor and you are a nurse. Figure
1 shows that Google Translate outputs the Arabic translation أنا طبيب وأنت
ممرضة> ÂnA Tbyb wÂnt mmrD$\hbar$444Arabic HSB transliteration Habash et al.
(2007). ‘I am a [male] doctor and you are a [female] nurse’, whereas a more
suitable output would include all four possible Arabic translations.

Figure 1: Google Translate’s output for “I am a doctor and you are a nurse” in
Arabic. Doctor is translated to the masculine form (‘طبيب>’ Tbyb), whereas
nurse is translated to the feminine form (‘ممرضة>’ mmrD$\hbar$).

(a) | (b)
---|---
|

Figure 2: Examples of gender-specific text in the wild. Figure (a) is an
example of text targeting female readers from a website about cooking recipes.
The example is the introduction to a recipe for Baba Ghannouj. Figure (b) is
an example of text targeting male readers from a website about career advice.
The example is about an advice on how to find a new job. The underlined words
are morphologically marked for the second person feminine in (a), and the
second person masculine in (b).

One approach to mitigate the ambiguity is to provide the users with the
ability to specify their desired target gender preferences so that NLP systems
would generate personalized unbiased outputs. To this end, we build on the
work of Alhafni et al. (2022b) where they formally introduced the task of
gender rewriting and developed a user-centric gender rewriting model for
Arabic.555https://github.com/CAMeL-Lab/gender-rewriting/ We introduce the
User-Aware Arabic Gender Rewriter, a user-centric web-based system for Arabic
gender rewriting in contexts involving two users. Our system takes either
Arabic or English sentences as input, and provides users with the ability to
specify their desired first and/or second person grammatical target genders.
The system outputs gender rewritten alternatives of the Arabic input sentences
(or their Arabic translations in case of English input) to match the target
users’ gender preferences. To the best of our knowledge, this is the first
open-access web-based system for Arabic gender rewriting. Our goal behind
creating an easy-to-use web-based multi-user Arabic gender rewriting tool is
to enable users to rewrite any Arabic text based on their grammatical gender
preferences that are consistent with their social identities. This reduces the
gender bias that is caused by user-unaware NLP systems and increases the
inclusiveness of Arabic NLP applications, leading to a better user experience.
We envision a future in which websites such as those in Figure 2 could use
automatic gender rewriting that fits the private preferences of their readers,
or that is adjusted with simple website controls comparable to selecting
different languages. The rest of this paper is organized as follows. We
discuss related work and Arabic linguistic facts in §2 and §3, respectively.
We describe the design and implementation of the web-based Arabic gender
rewriter in §4 and conclude in §5.

##  2 Related Work

Research has shown that NLP systems embed and amplify gender bias in a variety
of core tasks such as machine translation (MT) Rabinovich et al. (2017);
Elaraby et al. (2018); Vanmassenhove et al. (2018); Escudé Font and Costa-
jussà (2019); Stanovsky et al. (2019); Costa-jussà and de Jorge (2020); Gonen
and Webster (2020); Saunders and Byrne (2020); Saunders et al. (2020);
Stafanovičs et al. (2020); Savoldi et al. (2021); Ciora et al. (2021); Savoldi
et al. (2022b, a) and dialogue systems Cercas Curry et al. (2020); Dinan et
al. (2020); Liu et al. (2020a, b); Sheng et al. (2021). Most existing
solutions to mitigate gender bias in NLP systems either focus on debiasing
pretrained representations used in downstream tasks Bolukbasi et al. (2016);
Zhao et al. (2018b); Manzini et al. (2019); Zhao et al. (2020) or on training
systems on gender-balanced corpora Lu et al. (2018); Rudinger et al. (2018);
Zhao et al. (2018a); Hall Maudslay et al. (2019); Zmigrod et al. (2019). More
recently, text rewriting models were introduced to mitigate gender bias by
either neutralizing the outputs of NLP systems or changing their grammatical
genders to match provided users’ gender preferences. Vanmassenhove et al.
(2021) and Sun et al. (2021) presented rule-based and neural rewriting models
to generate gender-neutral sentences in English. For morphologically rich
languages and specifically Arabic, Habash et al. (2019) and Alhafni et al.
(2020), introduced gender identification and rewriting models to rewrite
first-person-singular Arabic sentences based on the target user gender
requirements. The task of gender rewriting was formally introduced by Alhafni
et al. (2022b) where they developed a new approach for Arabic gender rewriting
in contexts involving two users (I and/or You) – first and second grammatical
persons with independent grammatical gender preferences, and showed
improvements over both Habash et al. (2019) and Alhafni et al. (2020) systems.
The tool we introduce in this work uses the best gender rewriting model
developed by Alhafni et al. (2022b).5 It is worth noting that our tool is
similar to the recently introduced Fairslator Měchura (2022), a human-in-the-
loop web-based tool for detecting and correcting gender bias in the output of
MT systems translating from English to French, German, Czech, or
Irish.666https://www.fairslator.com/ However, our work is different from
theirs in the following ways:

  * •

Input: our system takes either Arabic or English sentences as an input,
whereas Fairslator only handles English sentences.

  * •

Models: the Arabic gender rewriter relies internally on both rule-based and
neural models as opposed to Fairslator’s rule-based gender reinflection
system.

  * •

Evaluation: the underlying gender rewriting model we use has been evaluated on
Arabic gender rewriting and post-editing MT output, and it achieves state-of-
the-art results, whereas Fairslator was not evaluated on any of the four
languages it targets.

  * •

Visualization: we focus on visualization by highlighting Arabic gender-marking
words in both the input and the output to provide a better user-experience.

##  3 Arabic Linguistic Background

Arabic has a rich morphological system that inflects for gender, number,
person, case, state, aspect, mood and voice, in addition to numerous
attachable clitics (prepositions, particles, pronouns) Habash (2010). Arabic
nouns, adjectives, and verbs inflect for gender: masculine (M) and feminine
(F), and for number: singular (S), dual (D) and plural (P). Grammatical gender
and number are commonly expressed using inflectional suffixes that represent
some number and gender combination. Pronominal clitics also express gender and
number combinations, e.g., طبيبتكم> Tbyb+km ‘your [masculine plural] doctor
[feminine singular]. Gender and number participate in the morpho-syntactic
agreement within specific constructions such as nouns and their adjectives and
verbs and their subjects. In practice, gender-specific words that are
candidates for gender rewriting account for 10% of all words in all sentences
and 17% of all words in gender-specific sentences. These statistics are
calculated from the Arabic Parallel Gender Corpus (APGC) v2.1 Alhafni et al.
(2022a), which we use to train our models.

##  4 Design and Implementation

(a) | (b)
---|---
|
(c) | (d)
|

Figure 3: The Arabic Gender Rewriter interface showing gender rewritten
alternatives of three input sentences in four modes: (a) Target speaker
$\female$ gender rewrites, (b) Target speaker $\female$ and target listener
$\female$ and $\male$ gender rewrites, (c) Target speaker $\female$ and
$\male$ and target listener $\female$ gender rewrites, and (d) Target speaker
$\female$ and $\male$ and target listener $\female$ and $\male$ gender
rewrites. Speaker gendered words are in blue and listener gendered words are
in orange.

###  4.1 User Interface

Our gender rewriting interface is publicly available at: http://gen-
rewrite.camel-lab.com/. Figure 3(a) shows the basic structure of the
interface. At the top, there is a text box to input either English or Arabic
text. At each side of the text box, there are two selection buttons to
indicate the desired target gender preferences for the speaker and the
listener ($\male$ is for masculine and $\female$ is for feminine). The user is
able to select any possible combination of the desired target genders,
including no target gender selection (i.e., requesting no rewriting). Once the
user clicks on the Translate & Rewrite button, all input English sentences
will be passed to Google Translate’s API to translate them into Arabic before
generating their gender alternatives. When the gender rewriting process is
done, additional text boxes will appear: the first text box will always
contain the gender-identified Arabic inputs and the rest of the text boxes
will contain the gender rewritten alternatives. Each gender marking word in
the gender-identified input text box will be labeled as either masculine
($\male$) or feminine ($\female$). First-person (i.e., speaker) gendered words
are colored in blue and second-person (i.e., listener) gendered words are
colored in orange. The number of the text boxes containing the gender
rewritten alternatives is based on the selected target gender preferences.
Each one of those boxes will have a label at its sides indicating a particular
target gender combination based on the users’ selections. For instance, Figure
3(a) has one text box containing first-person feminine gendered alternatives
of the input sentences. We discuss the screenshots in Figure 3 in more details
in §4.2.

#### Front-end

The front-end was implemented using Preact777https://preactjs.com/ for view
control and Bulma888https://bulma.io/ for styling.

#### Back-end

The back-end was implemented in Python using Flask to create a web API wrapper
for the gender rewriting model.999http://flask.pocoo.org/ We use the best
performing gender rewriting model described in Alhafni et al. (2022b). The
model was trained on the APGC v2.1 in addition to augmented data from the
OpenSubtitles 2018 dataset Lison and Tiedemann (2016) and it consists of three
components: gender identification, out-of-context word gender rewriting, and
in-context ranking and selection. The gender identification component
identifies the word-level gender label for each word in the input sentence. It
leverages a word-level BERT-based Devlin et al. (2019) classifier that was
built by fine-tuning CAMeLBERT MSA Inoue et al. (2021). Once the gender labels
have been identified for each word in the input and given the desired users
target genders, out-of-context word gender rewriting is triggered based on the
compatibility between the provided users’ target genders and the predicted
word-level gender labels. The gender rewriting component employs three word-
level gender alternative generation models in a backoff cascade setup: 1)
Corpus-based Rewriter: a bigram maximum likelihood estimation lookup model; 2)
Morphological Rewriter: a morphological analyzer and generator provided by
CAMeL Tools Obeid et al. (2020); and 3) Neural Rewriter: a character-level
sequence-to-sequence model with side constraints Sennrich et al. (2016). Since
the three implemented word-level gender rewriting models are out of context
and given Arabic’s morphological richness, this leads to producing multiple
candidate gender alternative sentences. To select the best candidate output
sentence, we rank all candidates in full sentential context based on their
pseudo-log-likelihood scores Salazar et al. (2020). Results on the test set of
APGC v2.1 show that the best gender rewriting model achieves an M2 Dahlmeier
and Ng (2012) F0.5 score of 88.42 and an average of 1.2 BLEU Papineni et al.
(2002) increase when automatically post-editing Google Translate’s output.

###  4.2 Examples and Use Cases

Figure 3 presents the different outputs of the gender rewriting tool for three
input sentences, one in English and two in Arabic. The three sentences come
from the examples presented in Figure 1, Figure 2(a), and Figure 2(b),
respectively. In Figure 3(a), only the feminine target gender for the speaker
is selected by the user. In this case, the system performs gender
identification and then generates the first-person feminine gender alternative
of the input sentences where all first-person masculine words are rewritten to
feminine. Figure 3(b) shows an example where the feminine target gender for
the speaker, and both the feminine and the masculine target genders for the
listener are selected. In this case, the system outputs two gender rewritten
alternatives for each input sentence, one for each selected target gender
combination (i.e., speaker feminine – listener feminine, speaker feminine –
listener masculine). Similarly, Figure 3(c) shows an example where both the
feminine and the masculine target genders for the speaker, and the feminine
target gender for the listener are selected. Lastly, Figure 3(d) is where all
the target gender preferences are selected for both the speaker and the
listener. In this case, the system generates all four possible gender
rewritten alternatives for each input sentence.

##  5 Conclusion and Future Work

We introduced the User-Aware Arabic Gender Rewriter, a user-centric web-based
system for Arabic gender rewriting in contexts involving two users. Our system
takes either Arabic or English sentences as input, and provides users with the
ability to specify their desired first and/or second persons target genders.
The system outputs gender rewritten alternatives of the Arabic input sentences
(or their Arabic translations in case of English input) to match the target
users’ gender preferences. Moreover, the system highlights Arabic gender-
marking words in both the input and the output to provide a better user-
experience. In future work, we plan to continue improving our gender rewriting
back-end by adding better gender rewriting models and enhancing inference
efficiency, as well as expanding gender identification and rewriting to third
person entities. We also plan to improve the interface by enabling users to
provide feedback that can be collected and used to enhance the performance of
gender rewriting. We will also improve the visualization we use to highlight
Arabic gender marking words by examining the added value it provides to
different end users, from language learners to native text editors.

## Limitations and Ethical Considerations

We acknowledge that by limiting the choice of gender expressions to the
grammatical gender choices in Arabic, we exclude other alternatives such as
non-binary gender or no-gender expressions. However, we are not aware of any
sociolinguistics published research that discusses such alternatives for
Arabic. We further recognize the limitations of the gender identification
component we use in the back-end of the Arabic gender rewriter as it is based
on a language model pretrained on a large monolingual Arabic corpus, which
could possibly contain biased text. We realize the potential risks of
maliciously misusing our system to intentionally produce gender alternatives
that do not match the target users’ gender preferences; as well as the
potential risks of negative reactions due to output errors.

## References

  * Alhafni et al. (2020) Bashar Alhafni, Nizar Habash, and Houda Bouamor. 2020.  Gender-aware reinflection using linguistically enhanced neural models.  In _Proceedings of the Second Workshop on Gender Bias in Natural Language Processing_ , pages 139–150, Barcelona, Spain (Online). Association for Computational Linguistics.
  * Alhafni et al. (2022a) Bashar Alhafni, Nizar Habash, and Houda Bouamor. 2022a.  The Arabic parallel gender corpus 2.0: Extensions and analyses.  In _Proceedings of the Thirteenth Language Resources and Evaluation Conference_ , pages 1870–1884, Marseille, France. European Language Resources Association.
  * Alhafni et al. (2022b) Bashar Alhafni, Nizar Habash, and Houda Bouamor. 2022b.  User-centric gender rewriting.  In _Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies_ , pages 618–631, Seattle, United States. Association for Computational Linguistics.
  * Blodgett et al. (2020) Su Lin Blodgett, Solon Barocas, Hal Daumé III, and Hanna Wallach. 2020.  Language (technology) is power: A critical survey of “bias” in NLP.  In _Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics_ , pages 5454–5476, Online. Association for Computational Linguistics.
  * Bolukbasi et al. (2016) Tolga Bolukbasi, Kai-Wei Chang, James Y Zou, Venkatesh Saligrama, and Adam T Kalai. 2016.  Man is to computer programmer as woman is to homemaker? debiasing word embeddings.  In _Advances in Neural Information Processing Systems_ , volume 29. Curran Associates, Inc.
  * Boyd and Crawford (2012) Danah Boyd and Kate Crawford. 2012.  Critical questions for big data.  _Information, Communication & Society_, 15(5):662–679.
  * Cercas Curry et al. (2020) Amanda Cercas Curry, Judy Robertson, and Verena Rieser. 2020.  Conversational assistants and gender stereotypes: Public perceptions and desiderata for voice personas.  In _Proceedings of the Second Workshop on Gender Bias in Natural Language Processing_ , pages 72–78, Barcelona, Spain (Online). Association for Computational Linguistics.
  * Ciora et al. (2021) Chloe Ciora, Nur Iren, and Malihe Alikhani. 2021.  Examining covert gender bias: A case study in Turkish and English machine translation models.  In _Proceedings of the 14th International Conference on Natural Language Generation_ , pages 55–63, Aberdeen, Scotland, UK. Association for Computational Linguistics.
  * Costa-jussà and de Jorge (2020) Marta R. Costa-jussà and Adrià de Jorge. 2020.  Fine-tuning neural machine translation on gender-balanced datasets.  In _Proceedings of the Second Workshop on Gender Bias in Natural Language Processing_ , pages 26–34, Barcelona, Spain (Online). Association for Computational Linguistics.
  * Dahlmeier and Ng (2012) Daniel Dahlmeier and Hwee Tou Ng. 2012.  Better evaluation for grammatical error correction.  In _Proceedings of the 2012 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies_ , pages 568–572, Montréal, Canada.
  * Devlin et al. (2019) Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019.  BERT: Pre-training of deep bidirectional transformers for language understanding.  In _Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers)_ , pages 4171–4186, Minneapolis, Minnesota. Association for Computational Linguistics.
  * Dinan et al. (2020) Emily Dinan, Angela Fan, Adina Williams, Jack Urbanek, Douwe Kiela, and Jason Weston. 2020.  Queens are powerful too: Mitigating gender bias in dialogue generation.  In _Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)_ , pages 8173–8188, Online. Association for Computational Linguistics.
  * Elaraby et al. (2018) Mostafa Elaraby, Ahmed Y. Tawfik, Mahmoud Khaled, Hany Hassan, and Aly Osama. 2018\.  Gender aware spoken language translation applied to english-arabic.  In _2018 2nd International Conference on Natural Language and Speech Processing (ICNLSP)_ , pages 1–6.
  * Escudé Font and Costa-jussà (2019) Joel Escudé Font and Marta R. Costa-jussà. 2019.  Equalizing gender bias in neural machine translation with word embeddings techniques.  In _Proceedings of the First Workshop on Gender Bias in Natural Language Processing_ , pages 147–154, Florence, Italy. Association for Computational Linguistics.
  * Gonen and Webster (2020) Hila Gonen and Kellie Webster. 2020.  Automatically identifying gender issues in machine translation using perturbations.  In _Findings of the Association for Computational Linguistics: EMNLP 2020_ , pages 1991–1995, Online. Association for Computational Linguistics.
  * Habash et al. (2019) Nizar Habash, Houda Bouamor, and Christine Chung. 2019.  Automatic gender identification and reinflection in Arabic.  In _Proceedings of the First Workshop on Gender Bias in Natural Language Processing_ , pages 155–165, Florence, Italy.
  * Habash et al. (2007) Nizar Habash, Abdelhadi Soudi, and Tim Buckwalter. 2007.  On Arabic Transliteration.  In A. van den Bosch and A. Soudi, editors, _Arabic Computational Morphology: Knowledge-based and Empirical Methods_ , pages 15–22. Springer, Netherlands.
  * Habash (2010) Nizar Y Habash. 2010.  _Introduction to Arabic natural language processing_ , volume 3.  Morgan & Claypool Publishers.
  * Hall Maudslay et al. (2019) Rowan Hall Maudslay, Hila Gonen, Ryan Cotterell, and Simone Teufel. 2019.  It’s all in the name: Mitigating gender bias with name-based counterfactual data substitution.  In _Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP)_ , pages 5267–5275, Hong Kong, China.
  * Inoue et al. (2021) Go Inoue, Bashar Alhafni, Nurpeiis Baimukan, Houda Bouamor, and Nizar Habash. 2021\.  The interplay of variant, size, and task type in Arabic pre-trained language models.  In _Proceedings of the Sixth Arabic Natural Language Processing Workshop_ , pages 92–104, Kyiv, Ukraine (Virtual). Association for Computational Linguistics.
  * Johnson (2020) Melvin Johnson. 2020.  A scalable approach to reducing gender bias in google translate.  Google AI Blog.
  * Kuczmarski (2018) James Kuczmarski. 2018.  Reducing gender bias in google translate.  Google Blog.
  * Lison and Tiedemann (2016) Pierre Lison and Jörg Tiedemann. 2016.  OpenSubtitles2016: Extracting large parallel corpora from movie and TV subtitles.  In _Proceedings of the Tenth International Conference on Language Resources and Evaluation (LREC’16)_ , pages 923–929, Portorož, Slovenia. European Language Resources Association (ELRA).
  * Liu et al. (2020a) Haochen Liu, Jamell Dacon, Wenqi Fan, Hui Liu, Zitao Liu, and Jiliang Tang. 2020a.  Does gender matter? towards fairness in dialogue systems.  In _Proceedings of the 28th International Conference on Computational Linguistics_ , pages 4403–4416, Barcelona, Spain (Online). International Committee on Computational Linguistics.
  * Liu et al. (2020b) Haochen Liu, Wentao Wang, Yiqi Wang, Hui Liu, Zitao Liu, and Jiliang Tang. 2020b.  Mitigating gender bias for neural dialogue generation with adversarial learning.  In _Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP)_ , pages 893–903, Online. Association for Computational Linguistics.
  * Lu et al. (2018) Kaiji Lu, Piotr Mardziel, Fangjing Wu, Preetam Amancharla, and Anupam Datta. 2018\.  Gender bias in neural natural language processing.
  * Maass and Arcuri (1996) Anne Maass and Luciano Arcuri. 1996.  Language and stereotyping.  _Stereotypes and stereotyping_ , pages 193–226.
  * Manzini et al. (2019) Thomas Manzini, Lim Yao Chong, Alan W Black, and Yulia Tsvetkov. 2019.  Black is to criminal as caucasian is to police: Detecting and removing multiclass bias in word embeddings.  In _Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers)_ , pages 615–621, Minneapolis, Minnesota. Association for Computational Linguistics.
  * Měchura (2022) Michal Měchura. 2022.  A taxonomy of bias-causing ambiguities in machine translation.  In _Proceedings of the 4th Workshop on Gender Bias in Natural Language Processing (GeBNLP)_ , pages 168–173, Seattle, Washington. Association for Computational Linguistics.
  * Menegatti and Rubini (2017) Michela Menegatti and Monica Rubini. 2017.  Gender bias and sexism in language.  In _Oxford Research Encyclopedia of Communication_. Oxford University Press.
  * Obeid et al. (2020) Ossama Obeid, Nasser Zalmout, Salam Khalifa, Dima Taji, Mai Oudah, Bashar Alhafni, Go Inoue, Fadhl Eryani, Alexander Erdmann, and Nizar Habash. 2020.  CAMeL tools: An open source python toolkit for Arabic natural language processing.  In _Proceedings of The 12th Language Resources and Evaluation Conference_ , pages 7022–7032, Marseille, France. European Language Resources Association.
  * Olteanu et al. (2019) Alexandra Olteanu, Carlos Castillo, Fernando Diaz, and Emr Kıcıman. 2019.  Social data: Biases, methodological pitfalls, and ethical boundaries.  _Frontiers in Big Data_ , 2.
  * Papineni et al. (2002) Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. 2002.  BLEU: a Method for Automatic Evaluation of Machine Translation.  In _Proceedings of the Conference of the Association for Computational Linguistics (ACL)_ , pages 311–318, Philadelphia, Pennsylvania, USA.
  * Rabinovich et al. (2017) Ella Rabinovich, Raj Nath Patel, Shachar Mirkin, Lucia Specia, and Shuly Wintner. 2017.  Personalized machine translation: Preserving original author traits.  In _Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics: Volume 1, Long Papers_ , pages 1074–1084, Valencia, Spain.
  * Rudinger et al. (2018) Rachel Rudinger, Jason Naradowsky, Brian Leonard, and Benjamin Van Durme. 2018.  Gender bias in coreference resolution.  In _Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers)_ , pages 8–14, New Orleans, Louisiana.
  * Salazar et al. (2020) Julian Salazar, Davis Liang, Toan Q. Nguyen, and Katrin Kirchhoff. 2020.  Masked language model scoring.  In _Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics_ , pages 2699–2712, Online. Association for Computational Linguistics.
  * Saunders and Byrne (2020) Danielle Saunders and Bill Byrne. 2020.  Reducing gender bias in neural machine translation as a domain adaptation problem.  In _Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics_ , pages 7724–7736, Online. Association for Computational Linguistics.
  * Saunders et al. (2020) Danielle Saunders, Rosie Sallis, and Bill Byrne. 2020.  Neural machine translation doesn’t translate gender coreference right unless you make it.  In _Proceedings of the Second Workshop on Gender Bias in Natural Language Processing_ , pages 35–43, Barcelona, Spain (Online). Association for Computational Linguistics.
  * Savoldi et al. (2021) Beatrice Savoldi, Marco Gaido, Luisa Bentivogli, Matteo Negri, and Marco Turchi. 2021.  Gender Bias in Machine Translation.  _Transactions of the Association for Computational Linguistics_ , 9:845–874.
  * Savoldi et al. (2022a) Beatrice Savoldi, Marco Gaido, Luisa Bentivogli, Matteo Negri, and Marco Turchi. 2022a.  On the dynamics of gender learning in speech translation.  In _Proceedings of the 4th Workshop on Gender Bias in Natural Language Processing (GeBNLP)_ , pages 94–111, Seattle, Washington. Association for Computational Linguistics.
  * Savoldi et al. (2022b) Beatrice Savoldi, Marco Gaido, Luisa Bentivogli, Matteo Negri, and Marco Turchi. 2022b.  Under the morphosyntactic lens: A multifaceted evaluation of gender bias in speech translation.  In _Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)_ , pages 1807–1824, Dublin, Ireland. Association for Computational Linguistics.
  * Sennrich et al. (2016) Rico Sennrich, Barry Haddow, and Alexandra Birch. 2016.  Controlling politeness in neural machine translation via side constraints.  In _Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies_ , pages 35–40, San Diego, California. Association for Computational Linguistics.
  * Sheng et al. (2021) Emily Sheng, Kai-Wei Chang, Prem Natarajan, and Nanyun Peng. 2021.  “nice try, kiddo”: Investigating ad hominems in dialogue responses.  In _Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies_ , pages 750–767, Online. Association for Computational Linguistics.
  * Stafanovičs et al. (2020) Artūrs Stafanovičs, Toms Bergmanis, and Mārcis Pinnis. 2020.  Mitigating gender bias in machine translation with target gender annotations.
  * Stanovsky et al. (2019) Gabriel Stanovsky, Noah A. Smith, and Luke Zettlemoyer. 2019.  Evaluating gender bias in machine translation.  In _Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics_ , pages 1679–1684, Florence, Italy.
  * Sun et al. (2019) Tony Sun, Andrew Gaut, Shirlyn Tang, Yuxin Huang, Mai ElSherief, Jieyu Zhao, Diba Mirza, Elizabeth Belding, Kai-Wei Chang, and William Yang Wang. 2019.  Mitigating gender bias in natural language processing: Literature review.  In _Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics_ , pages 1630–1640, Florence, Italy. Association for Computational Linguistics.
  * Sun et al. (2021) Tony Sun, Kellie Webster, Apu Shah, William Yang Wang, and Melvin Johnson. 2021\.  They, them, theirs: Rewriting with gender-neutral english.
  * Vanmassenhove et al. (2021) Eva Vanmassenhove, Chris Emmery, and Dimitar Shterionov. 2021.  NeuTral Rewriter: A rule-based and neural approach to automatic rewriting into gender neutral alternatives.  In _Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing_ , pages 8940–8948, Online and Punta Cana, Dominican Republic. Association for Computational Linguistics.
  * Vanmassenhove et al. (2018) Eva Vanmassenhove, Christian Hardmeier, and Andy Way. 2018.  Getting gender right in neural machine translation.  In _Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing_ , pages 3003–3008, Brussels, Belgium.
  * Zhao et al. (2020) Jieyu Zhao, Subhabrata Mukherjee, Saghar Hosseini, Kai-Wei Chang, and Ahmed Hassan Awadallah. 2020.  Gender bias in multilingual embeddings and cross-lingual transfer.  In _Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics_ , pages 2896–2907, Online. Association for Computational Linguistics.
  * Zhao et al. (2018a) Jieyu Zhao, Tianlu Wang, Mark Yatskar, Vicente Ordonez, and Kai-Wei Chang. 2018a.  Gender bias in coreference resolution: Evaluation and debiasing methods.  In _Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers)_ , pages 15–20, New Orleans, Louisiana.
  * Zhao et al. (2018b) Jieyu Zhao, Yichao Zhou, Zeyu Li, Wei Wang, and Kai-Wei Chang. 2018b.  Learning gender-neutral word embeddings.  In _Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing_ , pages 4847–4853, Brussels, Belgium.
  * Zmigrod et al. (2019) Ran Zmigrod, Sabrina J. Mielke, Hanna Wallach, and Ryan Cotterell. 2019.  Counterfactual data augmentation for mitigating gender stereotypes in languages with rich morphology.  In _Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics_ , pages 1651–1661, Florence, Italy.