|
1 | | -# TensorFlow Lite Transformers w/ Android demo |
| 1 | +# TensorFlow Lite Transformers w/ Android demos |
2 | 2 |
|
3 | 3 | Convert Transformers models |
4 | 4 | imported from the [🤗 Transformers](https://github.com/huggingface/transformers) library |
5 | 5 | and use them on Android. You can also check out our |
6 | 6 | [swift-coreml-transformers](https://github.com/huggingface/swift-coreml-transformers) repo |
7 | 7 | if you're looking for Transformers on iOS. |
8 | 8 |
|
9 | | -## DistilBERT for Question Answering |
| 9 | +# [Question Answering with DistilBERT](bert) |
10 | 10 |
|
11 | | -The app contains a demo of the [DistilBERT](https://arxiv.org/abs/1910.01108) model |
| 11 | +Demo of the [DistilBERT](https://arxiv.org/abs/1910.01108) model |
12 | 12 | (97% of BERT’s performance on GLUE) fine-tuned for Question answering on the SQuAD dataset. |
13 | 13 | It provides 48 passages from the dataset for users to choose from. |
14 | 14 |
|
15 | 15 |  |
16 | 16 |
|
17 | | -> Available models: |
18 | | -> * "original" converted DistilBERT (254MB) |
19 | | -> * FP16 post-training-quantized DistilBERT (131MB) |
20 | | -> * "hybrid" (8-bits precision weights) post-training-quantized DistilBERT (64MB) |
| 17 | +# [Text Generation with GPT-2/DistilGPT2](gpt2) |
21 | 18 |
|
22 | | -### Coming soon: GPT-2, quantization... and much more! |
| 19 | +On-device text generation using [GPT-2](https://d4mucfpksywv.cloudfront.net/better-language-models/language_models_are_unsupervised_multitask_learners.pdf) or [DistilGPT2](https://medium.com/huggingface/distilbert-8cf3380435b5) (same distillation process than DistilBERT, 2x faster and 33% smaller than GPT-2) |
23 | 20 |
|
24 | | ---- |
25 | | - |
26 | | -## Build the demo app using Android Studio |
27 | | - |
28 | | -### Prerequisites |
29 | | - |
30 | | -* If you don't have already, install |
31 | | - [Android Studio](https://developer.android.com/studio/index.html), following |
32 | | - the instructions on the website. |
33 | | -* Android Studio 3.2 or later. |
34 | | -* You need an Android device or Android emulator and Android development |
35 | | - environment with minimum API 15. |
36 | | -* The `app/libs` directory contains a custom build of |
37 | | - [TensorFlow Lite with TensorFlow ops built-in](https://www.tensorflow.org/lite/guide/ops_select), |
38 | | - which is used by the app. It results in a bigger binary than the "normal" build but allows |
39 | | - compatibility with models such as DistilBERT. |
40 | | - |
41 | | -### Building |
42 | | - |
43 | | -* Open Android Studio, and from the Welcome screen, select `Open an existing |
44 | | - Android Studio project`. |
45 | | -* From the Open File or Project window that appears, select the directory where you cloned this repo. |
46 | | -* You may also need to install various platforms and tools according to error |
47 | | - messages. |
48 | | -* If it asks you to use Instant Run, click Proceed Without Instant Run. |
49 | | - |
50 | | -### Running |
51 | | - |
52 | | -* You need to have an Android device plugged in with developer options enabled |
53 | | - at this point. See [here](https://developer.android.com/studio/run/device) |
54 | | - for more details on setting up developer devices. |
55 | | -* If you already have Android emulator installed in Android Studio, select a |
56 | | - virtual device with minimum API 15. |
57 | | -* Click `Run` to run the demo app on your Android device. |
58 | | - |
59 | | -## Build the demo using gradle (command line) |
60 | | - |
61 | | -### Building and Installing |
62 | | - |
63 | | -* Use the following command to build a demo apk: |
64 | | - |
65 | | -``` |
66 | | -./gradlew build |
67 | | -``` |
68 | | - |
69 | | -* Use the following command to install the apk onto your connected device: |
70 | | - |
71 | | -``` |
72 | | -adb install app/build/outputs/apk/debug/app-debug.apk |
73 | | -``` |
| 21 | + |
74 | 22 |
|
75 | 23 | --- |
76 | 24 |
|
77 | | -## Change the model |
78 | | - |
79 | | -To choose which model to use in the app: |
80 | | -* Remove/rename the current `model.tflite` file in `app/src/main/assets` |
81 | | -* Comment/uncomment the model to download in the `download.gradle` config file: |
82 | | -```java |
83 | | -"https://s3.amazonaws.com/models.huggingface.co/bert/distilbert-base-uncased-distilled-squad-384.tflite": "model.tflite", // <- "original" converted DistilBERT (default) |
84 | | -// "https://s3.amazonaws.com/models.huggingface.co/bert/distilbert-base-uncased-distilled-squad-384-fp16.tflite": "model.tflite", // <- fp16 quantized version of DistilBERT |
85 | | -// "https://s3.amazonaws.com/models.huggingface.co/bert/distilbert-base-uncased-distilled-squad-384-8bits.tflite": "model.tflite", // <- hybrid quantized version of DistilBERT |
86 | | -``` |
87 | | - |
88 | 25 | ## Models generation |
89 | 26 |
|
90 | | -Example scripts used to convert models are available in the `models_generation` directory. |
| 27 | +Example scripts used to convert the models are available in the `models_generation` directory. |
91 | 28 | Please note that they require the nightly version of TensorFlow and might thus be unstable. |
92 | 29 |
|
93 | | ---- |
94 | | - |
95 | | -## Credits |
96 | | - |
97 | | -The Android app is forked from the `bertqa` example in the |
98 | | -[tensorflow/examples](https://github.com/tensorflow/examples) repository and uses the same |
99 | | -tokenizer with DistilBERT. |
100 | | - |
101 | 30 | ## License |
102 | 31 |
|
103 | 32 | [Apache License 2.0](LICENSE) |
0 commit comments