A systematic comparison of four variational quantum circuit (VQC) data-encoding strategies β Angle, Dense Angle, IQP, and Data Re-uploading β for binary sentiment classification, with multi-seed validation on IMDb / SST-2 and real-hardware verification on IBM Quantum (ibm_fez, 156 qubits).
π Preprint: GΓΌndΓΌz, K. G. (2026). Evaluating Quantum Data Encoding Strategies and Gradient Trainability for NLP Sentiment Analysis. ResearchGate. https://doi.org/10.13140/RG.2.2.32211.13607
Local draft:
docs/paper_draft.mdΒ· LaTeX source:docs/paper.tex
- Dataset-agnostic encoding ranking. Angle > Dense > IQP > Re-uploading β preserved across IMDb (5 seeds) and SST-2.
- Gradient variance is informative but not deterministic. High variance helps optimization but does not guarantee accuracy (Re-uploading: variance 9.10 β accuracy 60%); low variance does not preclude strong performance (Dense Angle: 0.86 β 67.6%).
- Sigmoid scaling is a +17 pp design lever. Aligning PCA outputs (~N(0,1)) to the encoder domain
[0, Ο]is a first-order concern, not a hyperparameter footnote. - Hardware validation with T1 bias control. A class-balanced 10-sample test on
ibm_fezreveals 100% simulatorβQPU prediction agreement with symmetric per-class fidelity β no T1 amplitude-damping confound at the scales tested. - 3,400Γ faster training via PyTorch-native statevector simulation with autograd, vs. Qiskit's parameter-shift rule (14 ms vs. 1,501 ms per backward pass).
Text ββDistilBERT (frozen)βββΊ R^768 ββPCAβββΊ R^8 ββΟ(x)Β·ΟβββΊ [0,Ο]^8
β
βββββββββββββββββββββββ
βΌ
Parameterized Quantum Circuit (8 qubits, reps=1)
β
βΌ
β¨Zβ© per qubit ββLinearβββΊ logits β R^2
| Encoding | Qubits | Params | IMDb (mean Β± std) | SST-2 | Grad Var |
|---|---|---|---|---|---|
| Angle | 8 | 50 | 70.1 Β± 1.1 % | 76.4 % | 9.757 |
| Dense Angle | 4 | 26 | 67.6 Β± 0.5 % | 73.0 % | 0.855 |
| IQP | 8 | 50 | 62.7 Β± 0.6 % | 66.5 % | 0.899 |
| Re-uploading* | 8 | 50 | 60.2 Β± 0.9 % | 61.1 % | 9.098 |
| Linear baseline | β | 18 | 72.2 % | β | β |
* Constrained variant (no entangling layer after re-upload β see docs/paper_draft.md Β§5.2).
| Encoding | Sim Acc | QPU Acc | SimβQPU Agreement | L0 Agree | L1 Agree | Transpiled Depth |
|---|---|---|---|---|---|---|
| Angle | 80 % | 80 % | 10/10 (100 %) | 5/5 | 5/5 | 19 |
| Dense | 80 % | 80 % | 10/10 (100 %) | 5/5 | 5/5 | 18 |
| IQP | 80 % | 80 % | 10/10 (100 %) | 5/5 | 5/5 | 101 |
| Reupload | 80 % | 80 % | 10/10 (100 %) | 5/5 | 5/5 | 21 |
Symmetric per-class agreement rules out T1 amplitude-damping bias.
quantum-attention/
βββ data/
β βββ preprocess.py # DistilBERT embedding + PCA fitting
β βββ imdb_embeddings.pt # cached 8-dim PCA features (IMDb)
β βββ sst2_embeddings.pt # cached 8-dim PCA features (SST-2)
βββ models/
β βββ classical_baseline.py # Linear(8,2)
β βββ classical_attention.py # Q/K/V baseline
β βββ quantum_encodings.py # Angle / Dense / IQP / Re-uploading + ansatz
βββ training/
β βββ config.py # TrainingConfig dataclass
β βββ train.py # unified training loop (all model types)
βββ experiments/
β βββ run_multiseed.py # batch runner (skip-if-exists)
β βββ barren_plateau.py # gradient-variance analysis (100 random inits)
β βββ ibm_encoding_inference.py # QPU inference: 4 encodings Γ 10 samples
β βββ ibm_balanced_qpu.py # T1-controlled balanced (5+5) QPU run
β βββ paper_analysis.py # reproduces all paper figures
βββ results/
β βββ logs/ # per-experiment JSON history files
β βββ plots/ # paper figures (fig1 β¦ fig5)
βββ checkpoints/ # trained .pt files (one per (model, dataset, seed))
βββ docs/
β βββ paper_draft.md # full paper draft
β βββ paper.tex # LaTeX source
β βββ plans/ # design + implementation plans
βββ CLAUDE.md # project context for LLM sessions
βββ system_map.md # detailed system map
βββ developments.md # chronological dev log
βββ ibm_quantum_almanac.md # IBM Quantum API notes & gotchas
git clone https://github.com/RsGoksel/quantum-encoding-nlp.git
cd quantum-encoding-nlp
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtTested on Python 3.13, PyTorch 2.6 (CUDA 12.4), Qiskit 2.3, qiskit-ibm-runtime 0.45.
Only needed to reproduce hardware experiments β simulator-only training works without it.
from qiskit_ibm_runtime import QiskitRuntimeService
QiskitRuntimeService.save_account(
channel="ibm_quantum_platform", # NOT 'ibm_quantum' β Qiskit β₯ 2.x
token="YOUR_IBM_QUANTUM_TOKEN", # https://quantum.ibm.com/account
overwrite=True,
)The cached embeddings (data/*.pt) are committed, so step (1) is optional.
# (1) optional β re-embed text with DistilBERT and refit PCA
python data/preprocess.py
# (2) train all (encoding Γ seed) combinations, skip-if-exists
python experiments/run_multiseed.py --dataset imdb --seeds 42 123 456 789 2024
python experiments/run_multiseed.py --dataset sst2 --seeds 42
# (3) gradient-variance analysis (qubit + depth scaling)
python experiments/barren_plateau.py
# (4) IBM Quantum hardware inference (requires IBM account)
python experiments/ibm_balanced_qpu.py # primary balanced 5+5 run
python experiments/ibm_encoding_inference.py # initial 4Γ10 (all label 0)
# (5) regenerate every paper figure + summary table
python experiments/paper_analysis.pyWindows users: prefix Python invocations with
PYTHONIOENCODING=utf-8to avoid Unicode console errors.
python training/train.py \
--model enc_angle \
--dataset imdb \
--reps 1 \
--lr_quantum 0.05 \
--subset \
--seed 42 \
--suffix _seed42--model accepts: baseline, attention, quantum, enc_{angle,dense,iqp,reupload}, with optional _rand suffix for random initialization.
- Quantum simulation. PyTorch-native statevector (256 complex amplitudes for 8 qubits) on CPU, with autograd. ~3,400Γ faster than the parameter-shift rule for our circuits.
- Variational ansatz (shared by all encodings):
Ry Β· Rz β CZ (linear) β Ry Β· Rz,reps=1, identity initialization (ΞΈ = 0) per [Mele et al., 2024]. - Critical bug we fixed. Initial Qiskit circuits used
EfficientSU2with the default CX entanglement, while training used CZ. We replaced them with hand-built CZ circuits and cross-validated against PyTorch to 6 decimal places (seedocs/paper_draft.mdAppendix A). - Sigmoid scaling. PCA features
~ N(0,1)are mapped viaΟ(x)Β·Ο β [0,Ο]to cover the full Bloch arc. Without it, accuracy collapses to ~52 % (majority class).
We make no claim of quantum advantage. The 8-qubit circuits are classically simulable, the linear baseline outperforms all VQCs, and PCA retains only ~36 % of the DistilBERT variance. The contribution is methodological: a controlled comparison + gradient-trainability diagnostic + hardware fidelity protocol for selecting an encoding within the quantum design space. See Β§5.4 of the paper for the full limitations list.
@misc{gunduz2026quantumencoding,
author = {G\"und\"uz, Kadir G\"oksel},
title = {Evaluating Quantum Data Encoding Strategies and Gradient Trainability
for {NLP} Sentiment Analysis},
year = {2026},
month = apr,
publisher = {ResearchGate},
note = {Preprint},
doi = {10.13140/RG.2.2.32211.13607},
url = {https://doi.org/10.13140/RG.2.2.32211.13607},
}Released under the MIT License.
IBM Quantum Open Plan (10 min/month) for free QPU access; HuggingFace for DistilBERT and the IMDb / SST-2 dataset cards; the Qiskit and PyTorch communities.