← Research journal

Research note

CNN or LSTM: which should read a sensor pen?

CNN, LSTM or both? Why Vahini reads pen motion with a CNN-BiLSTM, and when a GRU, Transformer or autoencoder would fit better.

Revised 8 October 2026 · Measured results from the imu2text benchmarks, with sources below

CNN finds strokes → BiLSTM orders them → Attention weighs moments
CNN finds strokes → BiLSTM orders them → Attention weighs moments. Explanatory diagram, not experimental data.

The question

CNN, LSTM or both? Why Vahini reads pen motion with a CNN-BiLSTM, and when a GRU, Transformer or autoencoder would fit better.

A sensor pen does not see ink. It records 13 numbers 100 times a second from two accelerometers, a gyroscope, a magnetometer and a force sensor, and one letter is about a second of that. A model has two jobs: find short stroke shapes, then put them in order. A CNN is good at the first and a BiLSTM at the second, which is why the pair is the usual design on the Fraunhofer OnHW datasets. Background: Fraunhofer IIS: the OnHW datasets; imu2text: benchmarks and method; Vahini Playground; Vahini Playground: how CNN, LSTM and hybrid networks read handwriting.

On the official OnHW-chars test (52 classes, writers the model never saw, seed 0) our tuned CNN-BiLSTM reads 72.46% of letters; the CNN-BiLSTM published by Ott et al. reads 68.06%. Five runs of the same design voting together read 74.46%. On a small left-handed set whose split shares writers, the plain designs rank CNN-BiLSTM 64.8%, BiLSTM 56.2%, CNN 48.7% and LSTM 43.8%.

Bigger did not help. A two-layer BiLSTM scored 99.2% on its own training letters and 70.4% on new people: it memorised. GRUs, Transformers, autoencoders and VAEs have not been measured on this data yet, and the Vahini Playground lists them as open experiments.

Each part has one job. A CNN slides a small filter along the signal and fires wherever a short stroke appears, early or late. An LSTM reads the signal one moment at a time and carries a memory, so a loop at the start of a letter still counts at the end; a BiLSTM adds a second LSTM reading backwards. Attention then scores every moment and lets the deciding ones, a crossbar or a loop, count most. Adding attention took new people from 70.0% to 70.9%. The Vahini Playground animates each of these steps.

Worked example

Pick the design from the data you have

Few labelled recordings and short signals: start with a CNN-BiLSTM. Many recordings without answers: train an autoencoder on them first, then teach it letters. A rare group, such as left-handed writers (59.47% against 74.46% for right-handed writers): make extra recordings with a VAE or GAN, or augment. A small chip inside the pen: try a CNN or a CNN-GRU. Much more data than OnHW has: try a Transformer.

How to evaluate it

  1. 01

    Hold out whole writers for testing, and fit normalisation only on training writers.

  2. 02

    Compare designs on the same split, seed and number of training rounds, and report the spread over several seeds.

  3. 03

    Watch the gap between training and test accuracy. A design that memorises looks best on the data it trained on.

What remains open

Many small and capital letters are the same movement at a different size, and the pen measures motion, not position. On OnHW-chars 43.1% of the tuned model's errors are this mix-up, and no choice of design removes it alone.

Sources & scope

Related Vahini work: Project Akshara · Specifications and measurement status.

Try it on your own handwriting.

Upload one photo and get a 20-factor breakdown, free, in about a minute.