An open API service indexing awesome lists of open source software.

https://github.com/apertium/apertium-keyboard


https://github.com/apertium/apertium-keyboard

Last synced: 8 months ago
JSON representation

Awesome Lists containing this project

README

          

# apertium-keyboard

## Language model

Currently supports a morpheme-aware character language model. Sample Guarani model (```converted_model.tflite```) lives in the
assets directory (`./app/src/main/assets`), along with the set of symbols the LM is aware of (```labels.txt```), in order of
their numerical index as used by the neural net.

Currently, the keyboard uses a simplified prediction logic. It presents continuations of the current input, up to the next
predicted boundary (morpheme, word, or sentence). In the keyboard view, word continuations are presented with a ```"_"```
at the end, morpheme continuations with a ```"@"```, and sentences with a ```""```.

This is achieved via a greedy unroll of the top 3 character predictions given the character history (i.e., running the language
model with it's top choice given some starting point).

## Building

### Building on the command line:

```
$ gradle assembleDebug
```

The `.apk` will be found in `./app/build/outputs/apk/debug/app-debug.apk`.

Make sure you have the following environment variables set:
```
ANDROID_HOME=/path/to/android-sdk/
NDK_HOME=/path/to/android-ndk-r19c
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
```

### Building in android studio.

Note that when you load the keyboard from Android studio, you may need to activate it as an input method:

```Settings -> Languages & Input -> Virtual Keyboard -> Manage Keyboard```

TODO: Add additional logic for rewriting the current unit, rather than just completing it.

## Files

* `./app/src/main/res/xml/qwerty.xml`: This is the main keyboard layout file

* `./src/main/assets`
* `./src/main/java`
* `./src/main/res`

## Key classes and methods:

```LanguageModel/LanguageModelMobileNet```: These classes in the ```tflite``` directory store the code for loading a Tensorflow Lite model, and using it to generate keyboard predictions. See ```LanguageModel::generate()``` for the inference function.

```SmartKeyboard```: This kotlin class in the ```service``` directory contains all the relevant keyboard code. Here are the some important functions:

```SmartKeyboard::updateCandidates() //Get a new set of predicted continuations based on the current input history.```

```SmartKeyboard::getPredictions() //Call the language model to get some number of prediction candidates.```

```SmartKeyboard::pickSuggestion() //What should the keyboard do when the user picks a predicted continuation?```

```SmartKeyboard::handleBackspace() //What should happen if the user made a mistake and backs up?```

## Acknowledgements

The original fork this code is based on was written by Christo Kirov.