Skip to content
CleverKeys Wiki
implemented v1.2.7 User guide

Swipe Typing Technical Specification

Overview

Neural swipe typing uses an ONNX transformer model with beam search to predict words from gesture paths.

Key Components

ComponentFilePurpose
Trajectory ProcessorSwipeTrajectoryProcessor.ktConvert touch points to key sequence
Neural EngineNeuralPredictionEngine.ktONNX model inference
Beam SearchBeamSearchDecoder.ktFind top-k word predictions
VocabularyOptimizedVocabulary.ktDictionary and trie lookup
Keyboard GridKeyboardGrid.ktMap coordinates to keys

Architecture

Touch Events (Pointers.kt)

SwipeTrajectoryProcessor
    ↓ (key sequence)
NeuralPredictionEngine
    ↓ (token probabilities)
BeamSearchDecoder
    ↓ (top-k candidates)
SuggestionHandler → UI

Gesture Sampling Robustness

There is no minimum-speed gate on swipe typing — a slow swipe is not rejected for being slow. Word activation depends on registering ≥2 keys plus swipe_min_distance of path, which a slow-but-complete swipe satisfies just like a fast one (path length is bounded by key geometry, not by speed).

ImprovedSwipeGestureRecognizer.addPoint does, however, drop samples whose inter-sample gap exceeds MAX_POINT_INTERVAL_MS (500 ms). To keep a mid-gesture pause (a deliberate swiper holding still to aim) from permanently stalling the gesture, the recognizer re-anchors _lastPointTime to the resume timestamp when a long gap is seen, then resumes on the next sample. Without this re-anchor a single >500 ms gap left _lastPointTime stale, so every later sample’s delta grew larger and the remainder of the swipe was dropped — the second key never registered and no word was produced.

Neural Model

PropertyValue
FormatONNX Runtime Mobile
ArchitectureTransformer encoder
InputKey token sequence
OutputProbability distribution over vocabulary
Size~2 MB per language

Beam Search Configuration

From Config.kt:

SettingKeyDefaultRangeSource
Beam Widthneural_beam_width61-32Config.kt:130, validator backup/SettingsValidation.kt
Max Lengthneural_max_length2010-50Config.kt (NEURAL_MAX_LENGTH)
Confidence Thresholdneural_confidence_threshold0.010.0-1.0Config.kt:132 (NEURAL_CONFIDENCE_THRESHOLD)
ONNX Modelsbundled assetssrc/main/assets/models/swipe_{encoder,decoder}_android.onnx

Key Methods

SwipeTrajectoryProcessor.kt

// Line ~120: Convert swipe to tokens
fun processTrajectory(points: List<TouchPoint>): List<Int>

// Line ~180: Get nearest key for point
fun getNearestKeyToken(x: Float, y: Float): Int

NeuralPredictionEngine.kt

// Line ~80: Run inference
suspend fun predict(tokens: IntArray): FloatArray

// Line ~150: Load ONNX model
fun loadModel(context: Context, language: String)

Performance Metrics

Typical inference times:

Device TierInference Time
High-end15-25 ms
Mid-range30-50 ms
Low-end80-150 ms