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

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