textslinger 0.2.3__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. {textslinger-0.2.3 → textslinger-0.2.4}/PKG-INFO +82 -6
  2. {textslinger-0.2.3 → textslinger-0.2.4}/README.md +80 -5
  3. textslinger-0.2.4/assets/download_hf_models.py +23 -0
  4. {textslinger-0.2.3 → textslinger-0.2.4}/pyproject.toml +1 -0
  5. textslinger-0.2.4/tests/conftest.py +464 -0
  6. textslinger-0.2.4/tests/fixtures/__init__.py +1 -0
  7. textslinger-0.2.4/tests/fixtures/causal_byte.py +105 -0
  8. textslinger-0.2.4/tests/fixtures/causal_subword.py +119 -0
  9. textslinger-0.2.4/tests/fixtures/ngram.py +250 -0
  10. textslinger-0.2.4/tests/fixtures/phrases.py +18 -0
  11. textslinger-0.2.4/tests/fixtures/ppm.py +30 -0
  12. textslinger-0.2.4/tests/helpers.py +946 -0
  13. textslinger-0.2.4/tests/keyboard_touch_model.py +183 -0
  14. textslinger-0.2.4/tests/test_causal_byte.py +432 -0
  15. textslinger-0.2.4/tests/test_causal_byte_predict_characters.py +355 -0
  16. textslinger-0.2.4/tests/test_causal_byte_predict_words.py +1235 -0
  17. textslinger-0.2.4/tests/test_causal_subword.py +416 -0
  18. textslinger-0.2.4/tests/test_causal_subword_predict_characters.py +891 -0
  19. textslinger-0.2.4/tests/test_causal_subword_predict_words.py +668 -0
  20. textslinger-0.2.4/tests/test_constants.py +118 -0
  21. textslinger-0.2.4/tests/test_helpers.py +311 -0
  22. textslinger-0.2.4/tests/test_keyboard_touch_model.py +131 -0
  23. {textslinger-0.2.3 → textslinger-0.2.4}/tests/test_keystroke_savings_ngram.py +10 -4
  24. textslinger-0.2.4/tests/test_ngram.py +328 -0
  25. textslinger-0.2.4/tests/test_ngram_predict_characters.py +552 -0
  26. textslinger-0.2.4/tests/test_ngram_predict_words.py +1362 -0
  27. textslinger-0.2.4/tests/test_ppm.py +1 -0
  28. textslinger-0.2.4/tests/test_ppm_predict_characters.py +16 -0
  29. textslinger-0.2.4/tests/test_ppm_predict_words.py +42 -0
  30. textslinger-0.2.4/textslinger/__init__.py +52 -0
  31. textslinger-0.2.4/textslinger/causal_byte.py +988 -0
  32. textslinger-0.2.4/textslinger/causal_subword.py +1534 -0
  33. {textslinger-0.2.3 → textslinger-0.2.4}/textslinger/eval_helper.py +184 -157
  34. textslinger-0.2.4/textslinger/exceptions.py +24 -0
  35. {textslinger-0.2.3 → textslinger-0.2.4}/textslinger/helpers.py +15 -10
  36. textslinger-0.2.4/textslinger/language_model.py +172 -0
  37. textslinger-0.2.4/textslinger/ngram.py +618 -0
  38. textslinger-0.2.4/textslinger/ppm.py +798 -0
  39. {textslinger-0.2.3 → textslinger-0.2.4}/textslinger.egg-info/PKG-INFO +82 -6
  40. textslinger-0.2.4/textslinger.egg-info/SOURCES.txt +45 -0
  41. {textslinger-0.2.3 → textslinger-0.2.4}/textslinger.egg-info/requires.txt +1 -0
  42. textslinger-0.2.3/tests/conftest.py +0 -65
  43. textslinger-0.2.3/tests/helpers.py +0 -166
  44. textslinger-0.2.3/tests/test_causal_byte.py +0 -696
  45. textslinger-0.2.3/tests/test_causal_subword_basic.py +0 -111
  46. textslinger-0.2.3/tests/test_causal_subword_local.py +0 -103
  47. textslinger-0.2.3/tests/test_causal_subword_repoid.py +0 -26
  48. textslinger-0.2.3/tests/test_constants.py +0 -80
  49. textslinger-0.2.3/tests/test_ngram.py +0 -660
  50. textslinger-0.2.3/tests/test_ngram_predict_words.py +0 -706
  51. textslinger-0.2.3/textslinger/__init__.py +0 -25
  52. textslinger-0.2.3/textslinger/causal_byte.py +0 -521
  53. textslinger-0.2.3/textslinger/causal_subword.py +0 -768
  54. textslinger-0.2.3/textslinger/exceptions.py +0 -26
  55. textslinger-0.2.3/textslinger/language_model.py +0 -97
  56. textslinger-0.2.3/textslinger/ngram.py +0 -642
  57. textslinger-0.2.3/textslinger.egg-info/SOURCES.txt +0 -28
  58. {textslinger-0.2.3 → textslinger-0.2.4}/LICENSE +0 -0
  59. {textslinger-0.2.3 → textslinger-0.2.4}/setup.cfg +0 -0
  60. {textslinger-0.2.3 → textslinger-0.2.4}/tests/__init__.py +0 -0
  61. {textslinger-0.2.3 → textslinger-0.2.4}/textslinger.egg-info/dependency_links.txt +0 -0
  62. {textslinger-0.2.3 → textslinger-0.2.4}/textslinger.egg-info/top_level.txt +0 -0
  63. {textslinger-0.2.3 → textslinger-0.2.4}/textslinger.egg-info/zip-safe +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: textslinger
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: TextSlinger: Fast and accurate text predictions in Python
5
5
  Author-email: Keith Vertanen <vertanen@mtu.edu>, Dylan Gaines <dgaine20@kennesaw.edu>, Soufia Bahmani <sbahmani@mtu.edu>
6
6
  License-Expression: MIT
@@ -42,6 +42,7 @@ Requires-Dist: peft~=0.14.0
42
42
  Provides-Extra: dev
43
43
  Requires-Dist: coverage>=7.0; extra == "dev"
44
44
  Requires-Dist: pytest; extra == "dev"
45
+ Requires-Dist: black; extra == "dev"
45
46
  Provides-Extra: release
46
47
  Requires-Dist: twine==5.0.0; extra == "release"
47
48
  Requires-Dist: build>=1.4.0; extra == "release"
@@ -72,6 +73,13 @@ Current features:
72
73
  Our code style is whatever the Black formatter says it should be.
73
74
  You should [configure your IDE to format using Black when you save](https://black.readthedocs.io/en/stable/integrations/editors.html).
74
75
 
76
+ ### Windows
77
+ Windows is not supported by the library dependencies of textslinger.
78
+ To use our library on Windows, you will need to use [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-gb/windows/wsl/).
79
+ Please follow the [installation directions](https://learn.microsoft.com/en-gb/windows/wsl/install) and use the Linux commands below.
80
+ You will also need to install pip to install Python libraries. Follow the
81
+ [pip installation directions](https://pip.pypa.io/en/stable/installation/) before proceeding.
82
+
75
83
  ## Setting up a Python environment
76
84
  If you don't have [Miniforge](https://conda-forge.org/download/) installed in your user account you'll first need to do that.
77
85
 
@@ -81,12 +89,17 @@ curl -LO https://github.com/conda-forge/miniforge/releases/latest/download/Minif
81
89
  zsh Miniforge3-MacOSX-arm64.sh
82
90
  ~/miniforge3/bin/conda init zsh
83
91
  ```
84
- To install Miniforge on Linux:
92
+ To install Miniforge on Linux and WSL:
85
93
  ```
86
94
  curl -LO https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
87
95
  bash Miniforge3-Linux-x86_64.sh
88
96
  ```
89
97
 
98
+ When installing on WSL, enter "yes" when asked if you want to automatically initialize conda. This sets up easier access to conda in your WSL environment. You can disable the automatic start of the base environment using the following conda command after restarting your terminal:
99
+ ```
100
+ conda config --set auto_activate_base false
101
+ ```
102
+
90
103
  After installing Miniforge, be sure to close your terminal and start a new one. Create an environment as follows:
91
104
  ```
92
105
  conda config --remove-key channels
@@ -97,6 +110,7 @@ conda activate textslinger
97
110
  ```
98
111
 
99
112
  ### Installation of PyTorch
113
+
100
114
  MacOS using Apple Silicon:
101
115
  ```
102
116
  pip install torch torchvision torchaudio
@@ -115,6 +129,18 @@ Linux without CUDA support:
115
129
  pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
116
130
  ```
117
131
 
132
+ WSL with CUDA support (GPU driver must support installed library version or greater. Run ```nvidia-smi``` to check driver support).
133
+ Due to a security vulnerability in earlier versions, WSL requires at least torch 2.6:
134
+
135
+ ```
136
+ # CUDA 12.6
137
+ python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
138
+ ```
139
+ WSL without CUDA support:
140
+ ```
141
+ python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
142
+ ```
143
+
118
144
  Test if the PyTorch installation worked:
119
145
  ```
120
146
  python - <<'EOF'
@@ -139,10 +165,18 @@ EOF
139
165
  ```
140
166
 
141
167
  ### Installation of libraries
142
- Install transformers (5.2.0 or greater required).
168
+ Install transformers (5.2.0 or greater required).
169
+
170
+ MacOS and Linux:
143
171
  ```
144
172
  pip install transformers
145
173
  ```
174
+
175
+ WSL:
176
+ ```
177
+ python -m pip install transformers
178
+ ```
179
+
146
180
  Check transformers version and model support:
147
181
  ```
148
182
  python - <<'EOF'
@@ -161,20 +195,57 @@ except Exception as e:
161
195
  print("BLT model missing ❌", e)
162
196
  EOF
163
197
  ```
164
- Install other dependencies:
198
+
199
+ #### Hugging Face Authentication
200
+
201
+ You will need to log in to Hugging Face using the CLI. This CLI is installed with the `transformers` library. Please see the [Hugging Face CLI Login direction](https://huggingface.co/docs/huggingface_hub/en/guides/cli#hf-auth-login) for how to do this. We recommend [using a token](https://huggingface.co/docs/huggingface_hub/en/quick-start#authentication) so you do not need to manually enter your credentials.
202
+
203
+ ```
204
+ hf auth login
205
+ ```
206
+
207
+ Install other dependencies on MacOS and Linux:
165
208
  ```
166
209
  pip install pytest scipy peft psutil datasets
167
210
 
168
211
  # NOTE: increase MAX_ORDER if you plan to load n-gram models with longer context
169
212
  MAX_ORDER=12 pip install https://github.com/kpu/kenlm/archive/master.zip
170
213
  ```
171
- Fix harmless warning message:
214
+
215
+ Install other dependencies on WSL:
216
+ ```
217
+ python -m pip install pytest scipy peft psutil datasets
218
+ ```
219
+
220
+ If using the default WSL Ubuntu installation, the `build-essential` package is needed to build the KenLM library. You also need the `unzip` package to run the `download.sh` script later in this guide.
221
+ ```
222
+ sudo apt-get update && sudo apt-get upgrade
223
+ sudo apt-get install build-essential unzip
224
+ # NOTE: increase MAX_ORDER if you plan to load n-gram models with longer context
225
+ export MAX_ORDER=12
226
+ python -m pip install https://github.com/kpu/kenlm/archive/master.zip
227
+ ```
228
+
229
+ Fix harmless warning message on MacOS and Linux:
172
230
  ```
173
231
  pip install --upgrade --force-reinstall setuptools
174
232
  ```
175
233
 
234
+ Fix harmless warning message on WSL:
235
+
236
+ CUDA 12.6 does not support `setuptools` versions 82.0.0+.
237
+
238
+ ```
239
+ python -m pip install --upgrade --force-reinstall setuptools==81.0.0
240
+ ```
241
+
242
+ Install TextSlinger itself so scripts can import the `textslinger` package from any working directory. Run this from the repository root on all platforms, the directory containing `pyproject.toml`:
243
+ ```
244
+ python -m pip install --no-deps -e .
245
+ ```
246
+
176
247
  ### Testing installation
177
- Download assets needed by the test suite and then run it:
248
+ Download assets needed by the test suite and then run it. If you are on WSL, check if the `assets` directory is owned by `root` using `ls -l`. If so, restart your WSL session and rercheck the ownsership.
178
249
  ```
179
250
  cd textslinger/assets
180
251
  ./download.sh
@@ -182,5 +253,10 @@ cd ..
182
253
  pytest -v -rs
183
254
  ```
184
255
 
256
+ If you encounter an error with line endings (e.g., "\r: no such file or directory") when running `download.sh`, you can change the line endings using:
257
+
258
+ ```
259
+ vim download.sh -c "set ff=unix" -c ":wq"
260
+ ```
185
261
  ---
186
262
  This material is based upon work supported by the NSF under Grant No. IIS-1909089 and IIS-2402876.
@@ -22,6 +22,13 @@ Current features:
22
22
  Our code style is whatever the Black formatter says it should be.
23
23
  You should [configure your IDE to format using Black when you save](https://black.readthedocs.io/en/stable/integrations/editors.html).
24
24
 
25
+ ### Windows
26
+ Windows is not supported by the library dependencies of textslinger.
27
+ To use our library on Windows, you will need to use [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-gb/windows/wsl/).
28
+ Please follow the [installation directions](https://learn.microsoft.com/en-gb/windows/wsl/install) and use the Linux commands below.
29
+ You will also need to install pip to install Python libraries. Follow the
30
+ [pip installation directions](https://pip.pypa.io/en/stable/installation/) before proceeding.
31
+
25
32
  ## Setting up a Python environment
26
33
  If you don't have [Miniforge](https://conda-forge.org/download/) installed in your user account you'll first need to do that.
27
34
 
@@ -31,12 +38,17 @@ curl -LO https://github.com/conda-forge/miniforge/releases/latest/download/Minif
31
38
  zsh Miniforge3-MacOSX-arm64.sh
32
39
  ~/miniforge3/bin/conda init zsh
33
40
  ```
34
- To install Miniforge on Linux:
41
+ To install Miniforge on Linux and WSL:
35
42
  ```
36
43
  curl -LO https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
37
44
  bash Miniforge3-Linux-x86_64.sh
38
45
  ```
39
46
 
47
+ When installing on WSL, enter "yes" when asked if you want to automatically initialize conda. This sets up easier access to conda in your WSL environment. You can disable the automatic start of the base environment using the following conda command after restarting your terminal:
48
+ ```
49
+ conda config --set auto_activate_base false
50
+ ```
51
+
40
52
  After installing Miniforge, be sure to close your terminal and start a new one. Create an environment as follows:
41
53
  ```
42
54
  conda config --remove-key channels
@@ -47,6 +59,7 @@ conda activate textslinger
47
59
  ```
48
60
 
49
61
  ### Installation of PyTorch
62
+
50
63
  MacOS using Apple Silicon:
51
64
  ```
52
65
  pip install torch torchvision torchaudio
@@ -65,6 +78,18 @@ Linux without CUDA support:
65
78
  pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
66
79
  ```
67
80
 
81
+ WSL with CUDA support (GPU driver must support installed library version or greater. Run ```nvidia-smi``` to check driver support).
82
+ Due to a security vulnerability in earlier versions, WSL requires at least torch 2.6:
83
+
84
+ ```
85
+ # CUDA 12.6
86
+ python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
87
+ ```
88
+ WSL without CUDA support:
89
+ ```
90
+ python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
91
+ ```
92
+
68
93
  Test if the PyTorch installation worked:
69
94
  ```
70
95
  python - <<'EOF'
@@ -89,10 +114,18 @@ EOF
89
114
  ```
90
115
 
91
116
  ### Installation of libraries
92
- Install transformers (5.2.0 or greater required).
117
+ Install transformers (5.2.0 or greater required).
118
+
119
+ MacOS and Linux:
93
120
  ```
94
121
  pip install transformers
95
122
  ```
123
+
124
+ WSL:
125
+ ```
126
+ python -m pip install transformers
127
+ ```
128
+
96
129
  Check transformers version and model support:
97
130
  ```
98
131
  python - <<'EOF'
@@ -111,20 +144,57 @@ except Exception as e:
111
144
  print("BLT model missing ❌", e)
112
145
  EOF
113
146
  ```
114
- Install other dependencies:
147
+
148
+ #### Hugging Face Authentication
149
+
150
+ You will need to log in to Hugging Face using the CLI. This CLI is installed with the `transformers` library. Please see the [Hugging Face CLI Login direction](https://huggingface.co/docs/huggingface_hub/en/guides/cli#hf-auth-login) for how to do this. We recommend [using a token](https://huggingface.co/docs/huggingface_hub/en/quick-start#authentication) so you do not need to manually enter your credentials.
151
+
152
+ ```
153
+ hf auth login
154
+ ```
155
+
156
+ Install other dependencies on MacOS and Linux:
115
157
  ```
116
158
  pip install pytest scipy peft psutil datasets
117
159
 
118
160
  # NOTE: increase MAX_ORDER if you plan to load n-gram models with longer context
119
161
  MAX_ORDER=12 pip install https://github.com/kpu/kenlm/archive/master.zip
120
162
  ```
121
- Fix harmless warning message:
163
+
164
+ Install other dependencies on WSL:
165
+ ```
166
+ python -m pip install pytest scipy peft psutil datasets
167
+ ```
168
+
169
+ If using the default WSL Ubuntu installation, the `build-essential` package is needed to build the KenLM library. You also need the `unzip` package to run the `download.sh` script later in this guide.
170
+ ```
171
+ sudo apt-get update && sudo apt-get upgrade
172
+ sudo apt-get install build-essential unzip
173
+ # NOTE: increase MAX_ORDER if you plan to load n-gram models with longer context
174
+ export MAX_ORDER=12
175
+ python -m pip install https://github.com/kpu/kenlm/archive/master.zip
176
+ ```
177
+
178
+ Fix harmless warning message on MacOS and Linux:
122
179
  ```
123
180
  pip install --upgrade --force-reinstall setuptools
124
181
  ```
125
182
 
183
+ Fix harmless warning message on WSL:
184
+
185
+ CUDA 12.6 does not support `setuptools` versions 82.0.0+.
186
+
187
+ ```
188
+ python -m pip install --upgrade --force-reinstall setuptools==81.0.0
189
+ ```
190
+
191
+ Install TextSlinger itself so scripts can import the `textslinger` package from any working directory. Run this from the repository root on all platforms, the directory containing `pyproject.toml`:
192
+ ```
193
+ python -m pip install --no-deps -e .
194
+ ```
195
+
126
196
  ### Testing installation
127
- Download assets needed by the test suite and then run it:
197
+ Download assets needed by the test suite and then run it. If you are on WSL, check if the `assets` directory is owned by `root` using `ls -l`. If so, restart your WSL session and rercheck the ownsership.
128
198
  ```
129
199
  cd textslinger/assets
130
200
  ./download.sh
@@ -132,5 +202,10 @@ cd ..
132
202
  pytest -v -rs
133
203
  ```
134
204
 
205
+ If you encounter an error with line endings (e.g., "\r: no such file or directory") when running `download.sh`, you can change the line endings using:
206
+
207
+ ```
208
+ vim download.sh -c "set ff=unix" -c ":wq"
209
+ ```
135
210
  ---
136
211
  This material is based upon work supported by the NSF under Grant No. IIS-1909089 and IIS-2402876.
@@ -0,0 +1,23 @@
1
+ """Download Hugging Face models used by repository tests into the HF cache."""
2
+
3
+ from huggingface_hub import snapshot_download
4
+
5
+
6
+ MODEL_NAMES = (
7
+ "figmtu/opt-125m-aac",
8
+ "itazap/blt-1b-hf",
9
+ "distilbert/distilgpt2",
10
+ "EleutherAI/pythia-70m",
11
+ "EleutherAI/gpt-neo-125m",
12
+ )
13
+
14
+
15
+ def main() -> None:
16
+ for model_name in MODEL_NAMES:
17
+ print(f"*** Downloading Hugging Face model: {model_name}")
18
+ model_path = snapshot_download(repo_id=model_name)
19
+ print(f" Cached at: {model_path}")
20
+
21
+
22
+ if __name__ == "__main__":
23
+ main()
@@ -52,6 +52,7 @@ dependencies = [
52
52
  dev = [
53
53
  "coverage>=7.0",
54
54
  "pytest",
55
+ "black"
55
56
  ]
56
57
  release = [
57
58
  "twine==5.0.0",