SonicPerformance 1.1.0__tar.gz → 1.2__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.
- sonicperformance-1.2/PKG-INFO +147 -0
- sonicperformance-1.2/README.md +132 -0
- {sonicperformance-1.1.0 → sonicperformance-1.2}/pyproject.toml +1 -1
- sonicperformance-1.2/src/SonicPerformance.egg-info/PKG-INFO +147 -0
- {sonicperformance-1.1.0 → sonicperformance-1.2}/src/SonicPerformance.egg-info/SOURCES.txt +3 -1
- sonicperformance-1.2/src/sonic/sonic.bigram.py +34 -0
- sonicperformance-1.2/src/sonic/sonic.py +80 -0
- sonicperformance-1.2/src/sonic/sonic.transformer.py +0 -0
- sonicperformance-1.1.0/PKG-INFO +0 -55
- sonicperformance-1.1.0/README.md +0 -40
- sonicperformance-1.1.0/src/SonicPerformance.egg-info/PKG-INFO +0 -55
- sonicperformance-1.1.0/src/sonic/sonic.py +0 -88
- {sonicperformance-1.1.0 → sonicperformance-1.2}/LICENSE +0 -0
- {sonicperformance-1.1.0 → sonicperformance-1.2}/setup.cfg +0 -0
- {sonicperformance-1.1.0 → sonicperformance-1.2}/src/SonicPerformance.egg-info/dependency_links.txt +0 -0
- {sonicperformance-1.1.0 → sonicperformance-1.2}/src/SonicPerformance.egg-info/top_level.txt +0 -0
- {sonicperformance-1.1.0 → sonicperformance-1.2}/src/sonic/__init__.py +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: SonicPerformance
|
|
3
|
+
Version: 1.2
|
|
4
|
+
Summary: A statistical, low-memory AI-model pipeline for generation or tokenizing.
|
|
5
|
+
Author: AobanZ
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AobanZ-MinecraftYoutuber/PySonic
|
|
8
|
+
Project-URL: Issues, https://github.com/AobanZ-MinecraftYoutuber/PySonic/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Sonic
|
|
17
|
+
|
|
18
|
+
Sonic is a lightweight statistical AI model library written in Python which provides AI features for Deep Learning.
|
|
19
|
+
It is intended to be a lightweight and simplistic alternative to PyTorch, having easy-to-use functions.
|
|
20
|
+
|
|
21
|
+
## Libraries
|
|
22
|
+
Sonic consists of these lightweight components:
|
|
23
|
+
|
|
24
|
+
| Component | Description |
|
|
25
|
+
| -------- | -------- |
|
|
26
|
+
| sonic | General usage library |
|
|
27
|
+
| sonic.bigram | Library to make a Sonic-Native Bigram. |
|
|
28
|
+
| sonic.transformer | Transformer Implemenation, work in progress |
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install sonicperformance
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
This is an implementation of a basic Bigram Model.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import sonic
|
|
42
|
+
import sonic.bigram
|
|
43
|
+
import numpy
|
|
44
|
+
import re
|
|
45
|
+
|
|
46
|
+
text = sonic.OpenFile("yourfile.txt") # replace with a string or your file path
|
|
47
|
+
words = sonic.Tokenize(text)
|
|
48
|
+
|
|
49
|
+
model = sonic.bigram.Model(32, 16)
|
|
50
|
+
|
|
51
|
+
temp = sonic.bigram.InitModel(model)
|
|
52
|
+
|
|
53
|
+
def Generate(words, input, model):
|
|
54
|
+
output = []
|
|
55
|
+
next_word = input
|
|
56
|
+
|
|
57
|
+
for _ in range(model.mdiv + 1):
|
|
58
|
+
pos_probs = {}
|
|
59
|
+
|
|
60
|
+
for position, word in enumerate(words[:-1]):
|
|
61
|
+
if word == next_word:
|
|
62
|
+
following = words[position + 1]
|
|
63
|
+
pos_probs[following] = pos_probs.get(following, 0) + 1
|
|
64
|
+
|
|
65
|
+
if not pos_probs:
|
|
66
|
+
break
|
|
67
|
+
|
|
68
|
+
keys = list(pos_probs.keys())
|
|
69
|
+
|
|
70
|
+
p = sonic.p(probs=pos_probs, model=model, method="cpu")
|
|
71
|
+
|
|
72
|
+
# or use cupy here
|
|
73
|
+
next_word = str(
|
|
74
|
+
numpy.random.choice(keys, p=p)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
output.append(next_word)
|
|
78
|
+
|
|
79
|
+
output_string = " ".join(output)
|
|
80
|
+
|
|
81
|
+
output_string = re.sub(
|
|
82
|
+
r"User:|Assistant:|[\[\]\'\",]",
|
|
83
|
+
"",
|
|
84
|
+
output_string
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
return re.sub(r"\s+", " ", output_string).strip()
|
|
88
|
+
|
|
89
|
+
print(Generate(words, "the", temp))
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Features
|
|
93
|
+
|
|
94
|
+
* **Text tokenization**: Tokenize text into a list, or turn them into token embeddings
|
|
95
|
+
* Word frequency analysis
|
|
96
|
+
* Text generation
|
|
97
|
+
|
|
98
|
+
## Generation Implementation
|
|
99
|
+
This is a baseline level implementation for generation using Sonic.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
def Generate(words, input, model):
|
|
103
|
+
output = []
|
|
104
|
+
next_word = input
|
|
105
|
+
|
|
106
|
+
for _ in range(model.mdiv + 1):
|
|
107
|
+
pos_probs = {}
|
|
108
|
+
|
|
109
|
+
for position, word in enumerate(words[:-1]):
|
|
110
|
+
if word == next_word:
|
|
111
|
+
following = words[position + 1]
|
|
112
|
+
pos_probs[following] = pos_probs.get(following, 0) + 1
|
|
113
|
+
|
|
114
|
+
if not pos_probs:
|
|
115
|
+
break
|
|
116
|
+
|
|
117
|
+
keys = list(pos_probs.keys())
|
|
118
|
+
|
|
119
|
+
p = sonic.p(probs=pos_probs, model=model, method="cpu")
|
|
120
|
+
|
|
121
|
+
next_word = str(
|
|
122
|
+
numpy.random.choice(keys, p=p)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
output.append(next_word)
|
|
126
|
+
|
|
127
|
+
output_string = " ".join(output)
|
|
128
|
+
|
|
129
|
+
output_string = re.sub(
|
|
130
|
+
r"User:|Assistant:|[\[\]\'\",]",
|
|
131
|
+
"",
|
|
132
|
+
output_string
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
return re.sub(r"\s+", " ", output_string).strip()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Requirements
|
|
139
|
+
* Cupy
|
|
140
|
+
* NumPy
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
145
|
+
|
|
146
|
+
## Incorporation
|
|
147
|
+
Sonic can be used as a pipeline in text-generation projects, tokenizing, or NLP experimenting for beginners.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Sonic
|
|
2
|
+
|
|
3
|
+
Sonic is a lightweight statistical AI model library written in Python which provides AI features for Deep Learning.
|
|
4
|
+
It is intended to be a lightweight and simplistic alternative to PyTorch, having easy-to-use functions.
|
|
5
|
+
|
|
6
|
+
## Libraries
|
|
7
|
+
Sonic consists of these lightweight components:
|
|
8
|
+
|
|
9
|
+
| Component | Description |
|
|
10
|
+
| -------- | -------- |
|
|
11
|
+
| sonic | General usage library |
|
|
12
|
+
| sonic.bigram | Library to make a Sonic-Native Bigram. |
|
|
13
|
+
| sonic.transformer | Transformer Implemenation, work in progress |
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install sonicperformance
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
This is an implementation of a basic Bigram Model.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import sonic
|
|
27
|
+
import sonic.bigram
|
|
28
|
+
import numpy
|
|
29
|
+
import re
|
|
30
|
+
|
|
31
|
+
text = sonic.OpenFile("yourfile.txt") # replace with a string or your file path
|
|
32
|
+
words = sonic.Tokenize(text)
|
|
33
|
+
|
|
34
|
+
model = sonic.bigram.Model(32, 16)
|
|
35
|
+
|
|
36
|
+
temp = sonic.bigram.InitModel(model)
|
|
37
|
+
|
|
38
|
+
def Generate(words, input, model):
|
|
39
|
+
output = []
|
|
40
|
+
next_word = input
|
|
41
|
+
|
|
42
|
+
for _ in range(model.mdiv + 1):
|
|
43
|
+
pos_probs = {}
|
|
44
|
+
|
|
45
|
+
for position, word in enumerate(words[:-1]):
|
|
46
|
+
if word == next_word:
|
|
47
|
+
following = words[position + 1]
|
|
48
|
+
pos_probs[following] = pos_probs.get(following, 0) + 1
|
|
49
|
+
|
|
50
|
+
if not pos_probs:
|
|
51
|
+
break
|
|
52
|
+
|
|
53
|
+
keys = list(pos_probs.keys())
|
|
54
|
+
|
|
55
|
+
p = sonic.p(probs=pos_probs, model=model, method="cpu")
|
|
56
|
+
|
|
57
|
+
# or use cupy here
|
|
58
|
+
next_word = str(
|
|
59
|
+
numpy.random.choice(keys, p=p)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
output.append(next_word)
|
|
63
|
+
|
|
64
|
+
output_string = " ".join(output)
|
|
65
|
+
|
|
66
|
+
output_string = re.sub(
|
|
67
|
+
r"User:|Assistant:|[\[\]\'\",]",
|
|
68
|
+
"",
|
|
69
|
+
output_string
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
return re.sub(r"\s+", " ", output_string).strip()
|
|
73
|
+
|
|
74
|
+
print(Generate(words, "the", temp))
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Features
|
|
78
|
+
|
|
79
|
+
* **Text tokenization**: Tokenize text into a list, or turn them into token embeddings
|
|
80
|
+
* Word frequency analysis
|
|
81
|
+
* Text generation
|
|
82
|
+
|
|
83
|
+
## Generation Implementation
|
|
84
|
+
This is a baseline level implementation for generation using Sonic.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
def Generate(words, input, model):
|
|
88
|
+
output = []
|
|
89
|
+
next_word = input
|
|
90
|
+
|
|
91
|
+
for _ in range(model.mdiv + 1):
|
|
92
|
+
pos_probs = {}
|
|
93
|
+
|
|
94
|
+
for position, word in enumerate(words[:-1]):
|
|
95
|
+
if word == next_word:
|
|
96
|
+
following = words[position + 1]
|
|
97
|
+
pos_probs[following] = pos_probs.get(following, 0) + 1
|
|
98
|
+
|
|
99
|
+
if not pos_probs:
|
|
100
|
+
break
|
|
101
|
+
|
|
102
|
+
keys = list(pos_probs.keys())
|
|
103
|
+
|
|
104
|
+
p = sonic.p(probs=pos_probs, model=model, method="cpu")
|
|
105
|
+
|
|
106
|
+
next_word = str(
|
|
107
|
+
numpy.random.choice(keys, p=p)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
output.append(next_word)
|
|
111
|
+
|
|
112
|
+
output_string = " ".join(output)
|
|
113
|
+
|
|
114
|
+
output_string = re.sub(
|
|
115
|
+
r"User:|Assistant:|[\[\]\'\",]",
|
|
116
|
+
"",
|
|
117
|
+
output_string
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
return re.sub(r"\s+", " ", output_string).strip()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Requirements
|
|
124
|
+
* Cupy
|
|
125
|
+
* NumPy
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
|
130
|
+
|
|
131
|
+
## Incorporation
|
|
132
|
+
Sonic can be used as a pipeline in text-generation projects, tokenizing, or NLP experimenting for beginners.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: SonicPerformance
|
|
3
|
+
Version: 1.2
|
|
4
|
+
Summary: A statistical, low-memory AI-model pipeline for generation or tokenizing.
|
|
5
|
+
Author: AobanZ
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AobanZ-MinecraftYoutuber/PySonic
|
|
8
|
+
Project-URL: Issues, https://github.com/AobanZ-MinecraftYoutuber/PySonic/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Sonic
|
|
17
|
+
|
|
18
|
+
Sonic is a lightweight statistical AI model library written in Python which provides AI features for Deep Learning.
|
|
19
|
+
It is intended to be a lightweight and simplistic alternative to PyTorch, having easy-to-use functions.
|
|
20
|
+
|
|
21
|
+
## Libraries
|
|
22
|
+
Sonic consists of these lightweight components:
|
|
23
|
+
|
|
24
|
+
| Component | Description |
|
|
25
|
+
| -------- | -------- |
|
|
26
|
+
| sonic | General usage library |
|
|
27
|
+
| sonic.bigram | Library to make a Sonic-Native Bigram. |
|
|
28
|
+
| sonic.transformer | Transformer Implemenation, work in progress |
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install sonicperformance
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
This is an implementation of a basic Bigram Model.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import sonic
|
|
42
|
+
import sonic.bigram
|
|
43
|
+
import numpy
|
|
44
|
+
import re
|
|
45
|
+
|
|
46
|
+
text = sonic.OpenFile("yourfile.txt") # replace with a string or your file path
|
|
47
|
+
words = sonic.Tokenize(text)
|
|
48
|
+
|
|
49
|
+
model = sonic.bigram.Model(32, 16)
|
|
50
|
+
|
|
51
|
+
temp = sonic.bigram.InitModel(model)
|
|
52
|
+
|
|
53
|
+
def Generate(words, input, model):
|
|
54
|
+
output = []
|
|
55
|
+
next_word = input
|
|
56
|
+
|
|
57
|
+
for _ in range(model.mdiv + 1):
|
|
58
|
+
pos_probs = {}
|
|
59
|
+
|
|
60
|
+
for position, word in enumerate(words[:-1]):
|
|
61
|
+
if word == next_word:
|
|
62
|
+
following = words[position + 1]
|
|
63
|
+
pos_probs[following] = pos_probs.get(following, 0) + 1
|
|
64
|
+
|
|
65
|
+
if not pos_probs:
|
|
66
|
+
break
|
|
67
|
+
|
|
68
|
+
keys = list(pos_probs.keys())
|
|
69
|
+
|
|
70
|
+
p = sonic.p(probs=pos_probs, model=model, method="cpu")
|
|
71
|
+
|
|
72
|
+
# or use cupy here
|
|
73
|
+
next_word = str(
|
|
74
|
+
numpy.random.choice(keys, p=p)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
output.append(next_word)
|
|
78
|
+
|
|
79
|
+
output_string = " ".join(output)
|
|
80
|
+
|
|
81
|
+
output_string = re.sub(
|
|
82
|
+
r"User:|Assistant:|[\[\]\'\",]",
|
|
83
|
+
"",
|
|
84
|
+
output_string
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
return re.sub(r"\s+", " ", output_string).strip()
|
|
88
|
+
|
|
89
|
+
print(Generate(words, "the", temp))
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Features
|
|
93
|
+
|
|
94
|
+
* **Text tokenization**: Tokenize text into a list, or turn them into token embeddings
|
|
95
|
+
* Word frequency analysis
|
|
96
|
+
* Text generation
|
|
97
|
+
|
|
98
|
+
## Generation Implementation
|
|
99
|
+
This is a baseline level implementation for generation using Sonic.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
def Generate(words, input, model):
|
|
103
|
+
output = []
|
|
104
|
+
next_word = input
|
|
105
|
+
|
|
106
|
+
for _ in range(model.mdiv + 1):
|
|
107
|
+
pos_probs = {}
|
|
108
|
+
|
|
109
|
+
for position, word in enumerate(words[:-1]):
|
|
110
|
+
if word == next_word:
|
|
111
|
+
following = words[position + 1]
|
|
112
|
+
pos_probs[following] = pos_probs.get(following, 0) + 1
|
|
113
|
+
|
|
114
|
+
if not pos_probs:
|
|
115
|
+
break
|
|
116
|
+
|
|
117
|
+
keys = list(pos_probs.keys())
|
|
118
|
+
|
|
119
|
+
p = sonic.p(probs=pos_probs, model=model, method="cpu")
|
|
120
|
+
|
|
121
|
+
next_word = str(
|
|
122
|
+
numpy.random.choice(keys, p=p)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
output.append(next_word)
|
|
126
|
+
|
|
127
|
+
output_string = " ".join(output)
|
|
128
|
+
|
|
129
|
+
output_string = re.sub(
|
|
130
|
+
r"User:|Assistant:|[\[\]\'\",]",
|
|
131
|
+
"",
|
|
132
|
+
output_string
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
return re.sub(r"\s+", " ", output_string).strip()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Requirements
|
|
139
|
+
* Cupy
|
|
140
|
+
* NumPy
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
145
|
+
|
|
146
|
+
## Incorporation
|
|
147
|
+
Sonic can be used as a pipeline in text-generation projects, tokenizing, or NLP experimenting for beginners.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class Model:
|
|
2
|
+
def __init__(self, dim, batch, ddiv=32, mdiv=32):
|
|
3
|
+
self.dim = dim
|
|
4
|
+
self.batch = batch
|
|
5
|
+
self.ddiv = ddiv
|
|
6
|
+
self.mdiv = mdiv
|
|
7
|
+
|
|
8
|
+
@staticmethod
|
|
9
|
+
def Parameters(tdim, words):
|
|
10
|
+
"""
|
|
11
|
+
Returns bigram Parameters
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
print(f"True Dimensions: {tdim}")
|
|
15
|
+
print(f"Vocab: {len(words)}")
|
|
16
|
+
|
|
17
|
+
def InitModel(model):
|
|
18
|
+
"""
|
|
19
|
+
# sonic.bigram.InitModel
|
|
20
|
+
**WARNING: Only use this model for GENERATION**
|
|
21
|
+
|
|
22
|
+
Creates a temporary model that can generate text.
|
|
23
|
+
Put in your model from sonic.bigram.Model as an argument.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
if model.batch == model.dim or model.batch == model.mdiv:
|
|
27
|
+
raise ValueError("Model size invalid")
|
|
28
|
+
|
|
29
|
+
model.mdiv = int(model.mdiv * model.dim / model.batch)
|
|
30
|
+
|
|
31
|
+
model.tdiv = model.ddiv * model.mdiv
|
|
32
|
+
model.tdim = round(model.dim / model.ddiv)
|
|
33
|
+
|
|
34
|
+
return model
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
import cupy
|
|
4
|
+
import numpy
|
|
5
|
+
from safetensors.numpy import save_file
|
|
6
|
+
from safetensors import safe_open
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def OpenFile(file):
|
|
10
|
+
path = os.path.join(os.path.dirname(__file__), file)
|
|
11
|
+
|
|
12
|
+
with open(path, "r", encoding="utf-8") as f:
|
|
13
|
+
return f.read()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def Tokenize(text, method="words", by=None):
|
|
17
|
+
if method == "words":
|
|
18
|
+
return text.split(by)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def Probs(words):
|
|
22
|
+
probs = {}
|
|
23
|
+
|
|
24
|
+
for word in words:
|
|
25
|
+
probs[word] = probs.get(word, 0) + 1
|
|
26
|
+
|
|
27
|
+
return probs
|
|
28
|
+
|
|
29
|
+
def p(probs, model, method="cpu", dtype="float32"):
|
|
30
|
+
"""
|
|
31
|
+
P operation to calculate probabilities.\n\n**probs** = Dict\n\n**model** = model\n\n**method** = cpu, cuda\n\n**dtype** = float32, float64, etc
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
if method == "cpu":
|
|
35
|
+
p = numpy.array(
|
|
36
|
+
list(probs.values()),
|
|
37
|
+
dtype=dtype
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
p = p ** (model.tdim / 32)
|
|
41
|
+
p /= p.sum()
|
|
42
|
+
return p
|
|
43
|
+
if method == "cuda":
|
|
44
|
+
p = cupy.array(
|
|
45
|
+
list(probs.values()),
|
|
46
|
+
dtype=dtype
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
p = p ** (model.tdim / 32)
|
|
50
|
+
p /= p.sum()
|
|
51
|
+
return p.get()
|
|
52
|
+
|
|
53
|
+
class SaveTensor:
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def Bigram(model, method, dtype="float32", filename="model.safetensors"):
|
|
57
|
+
"""
|
|
58
|
+
A simple function to save a Bigram model as a safetensors file.
|
|
59
|
+
|
|
60
|
+
**Method** = cuda, cpu
|
|
61
|
+
|
|
62
|
+
**model** = your model
|
|
63
|
+
|
|
64
|
+
**filename** = filename
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
if method == "cuda":
|
|
68
|
+
mdiv = cupy.array([model.mdiv], [model.dim], [model.batch], dtype=dtype)
|
|
69
|
+
tdiv = cupy.array([model.ddiv], [model.mdiv], dtype=dtype)
|
|
70
|
+
tdim = cupy.array([model.dim], [model.ddiv], dtype=dtype)
|
|
71
|
+
|
|
72
|
+
tensors = {"mdiv": cupy.asnumpy(mdiv), "tdiv": cupy.asnumpy(tdiv), "tdim": cupy.asnumpy(tdim)}
|
|
73
|
+
save_file(tensors, filename)
|
|
74
|
+
if method == "cpu":
|
|
75
|
+
mdiv = numpy.array([model.mdiv, model.dim, model.batch], dtype=dtype)
|
|
76
|
+
tdiv = numpy.array([model.ddiv, model.mdiv], dtype=dtype)
|
|
77
|
+
tdim = numpy.array([model.dim, model.ddiv], dtype=dtype)
|
|
78
|
+
|
|
79
|
+
tensors = {"mdiv": numpy.asarray(mdiv), "tdiv": numpy.asarray(tdiv), "tdim": numpy.asarray(tdim)}
|
|
80
|
+
save_file(tensors, filename)
|
|
File without changes
|
sonicperformance-1.1.0/PKG-INFO
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: SonicPerformance
|
|
3
|
-
Version: 1.1.0
|
|
4
|
-
Summary: A statistical, low-memory AI-model pipeline for generation or tokenizing.
|
|
5
|
-
Author: AobanZ
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/AobanZ-MinecraftYoutuber/PySonic
|
|
8
|
-
Project-URL: Issues, https://github.com/AobanZ-MinecraftYoutuber/PySonic/issues
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.9
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
|
-
# Sonic
|
|
17
|
-
|
|
18
|
-
Sonic is a lightweight statistical AI model pipeline written in Python, aimed at improving AI performance on simple CPUs. Any of its functions can be incorporated in many projects.
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
pip install sonicperformance
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Usage
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
import sonic
|
|
30
|
-
|
|
31
|
-
text = sonic.OpenFile("all.txt")
|
|
32
|
-
words = sonic.Tokenize(text)
|
|
33
|
-
|
|
34
|
-
model = sonic.Model(32, 16)
|
|
35
|
-
model.InitModel()
|
|
36
|
-
|
|
37
|
-
print(model.Generate(words, "the"))
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Features
|
|
41
|
-
|
|
42
|
-
* Simple text tokenization
|
|
43
|
-
* Word frequency analysis
|
|
44
|
-
* Statistical text generation
|
|
45
|
-
* Lightweight NumPy-based implementation
|
|
46
|
-
|
|
47
|
-
## Requirements
|
|
48
|
-
* NumPy
|
|
49
|
-
|
|
50
|
-
## License
|
|
51
|
-
|
|
52
|
-
MIT
|
|
53
|
-
|
|
54
|
-
## Incorporation
|
|
55
|
-
Sonic can be used as a pipeline in text-generation projects, tokenizing, or NLP experimenting for beginners.
|
sonicperformance-1.1.0/README.md
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# Sonic
|
|
2
|
-
|
|
3
|
-
Sonic is a lightweight statistical AI model pipeline written in Python, aimed at improving AI performance on simple CPUs. Any of its functions can be incorporated in many projects.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pip install sonicperformance
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```python
|
|
14
|
-
import sonic
|
|
15
|
-
|
|
16
|
-
text = sonic.OpenFile("all.txt")
|
|
17
|
-
words = sonic.Tokenize(text)
|
|
18
|
-
|
|
19
|
-
model = sonic.Model(32, 16)
|
|
20
|
-
model.InitModel()
|
|
21
|
-
|
|
22
|
-
print(model.Generate(words, "the"))
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Features
|
|
26
|
-
|
|
27
|
-
* Simple text tokenization
|
|
28
|
-
* Word frequency analysis
|
|
29
|
-
* Statistical text generation
|
|
30
|
-
* Lightweight NumPy-based implementation
|
|
31
|
-
|
|
32
|
-
## Requirements
|
|
33
|
-
* NumPy
|
|
34
|
-
|
|
35
|
-
## License
|
|
36
|
-
|
|
37
|
-
MIT
|
|
38
|
-
|
|
39
|
-
## Incorporation
|
|
40
|
-
Sonic can be used as a pipeline in text-generation projects, tokenizing, or NLP experimenting for beginners.
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: SonicPerformance
|
|
3
|
-
Version: 1.1.0
|
|
4
|
-
Summary: A statistical, low-memory AI-model pipeline for generation or tokenizing.
|
|
5
|
-
Author: AobanZ
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/AobanZ-MinecraftYoutuber/PySonic
|
|
8
|
-
Project-URL: Issues, https://github.com/AobanZ-MinecraftYoutuber/PySonic/issues
|
|
9
|
-
Classifier: Programming Language :: Python :: 3
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.9
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
Dynamic: license-file
|
|
15
|
-
|
|
16
|
-
# Sonic
|
|
17
|
-
|
|
18
|
-
Sonic is a lightweight statistical AI model pipeline written in Python, aimed at improving AI performance on simple CPUs. Any of its functions can be incorporated in many projects.
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
pip install sonicperformance
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Usage
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
import sonic
|
|
30
|
-
|
|
31
|
-
text = sonic.OpenFile("all.txt")
|
|
32
|
-
words = sonic.Tokenize(text)
|
|
33
|
-
|
|
34
|
-
model = sonic.Model(32, 16)
|
|
35
|
-
model.InitModel()
|
|
36
|
-
|
|
37
|
-
print(model.Generate(words, "the"))
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Features
|
|
41
|
-
|
|
42
|
-
* Simple text tokenization
|
|
43
|
-
* Word frequency analysis
|
|
44
|
-
* Statistical text generation
|
|
45
|
-
* Lightweight NumPy-based implementation
|
|
46
|
-
|
|
47
|
-
## Requirements
|
|
48
|
-
* NumPy
|
|
49
|
-
|
|
50
|
-
## License
|
|
51
|
-
|
|
52
|
-
MIT
|
|
53
|
-
|
|
54
|
-
## Incorporation
|
|
55
|
-
Sonic can be used as a pipeline in text-generation projects, tokenizing, or NLP experimenting for beginners.
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import numpy
|
|
3
|
-
import re
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def OpenFile(file):
|
|
7
|
-
path = os.path.join(os.path.dirname(__file__), file)
|
|
8
|
-
|
|
9
|
-
with open(path, "r", encoding="utf-8") as f:
|
|
10
|
-
return f.read()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def Parameters(tdim, words):
|
|
14
|
-
print(f"True Dimensions: {tdim}")
|
|
15
|
-
print(f"Vocab: {len(words)}")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def Tokenize(text, by=None):
|
|
19
|
-
return text.split(by)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def Probs(words):
|
|
23
|
-
probs = {}
|
|
24
|
-
|
|
25
|
-
for word in words:
|
|
26
|
-
probs[word] = probs.get(word, 0) + 1
|
|
27
|
-
|
|
28
|
-
return probs
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class Model:
|
|
32
|
-
def __init__(self, dim, batch, ddiv=32, mdiv=32):
|
|
33
|
-
self.dim = dim
|
|
34
|
-
self.batch = batch
|
|
35
|
-
self.ddiv = ddiv
|
|
36
|
-
self.mdiv = mdiv
|
|
37
|
-
|
|
38
|
-
self.InitModel()
|
|
39
|
-
|
|
40
|
-
def InitModel(self):
|
|
41
|
-
if self.batch == self.dim or self.batch == self.mdiv:
|
|
42
|
-
raise ValueError("Model size invalid")
|
|
43
|
-
|
|
44
|
-
self.mdiv = int(self.mdiv * self.dim / self.batch)
|
|
45
|
-
|
|
46
|
-
self.tdiv = self.ddiv * self.mdiv
|
|
47
|
-
self.tdim = round(self.dim / self.ddiv)
|
|
48
|
-
|
|
49
|
-
def Generate(self, words, input):
|
|
50
|
-
output = []
|
|
51
|
-
next_word = input
|
|
52
|
-
|
|
53
|
-
for _ in range(self.mdiv + 1):
|
|
54
|
-
pos_probs = {}
|
|
55
|
-
|
|
56
|
-
for position, word in enumerate(words[:-1]):
|
|
57
|
-
if word == next_word:
|
|
58
|
-
following = words[position + 1]
|
|
59
|
-
pos_probs[following] = pos_probs.get(following, 0) + 1
|
|
60
|
-
|
|
61
|
-
if not pos_probs:
|
|
62
|
-
break
|
|
63
|
-
|
|
64
|
-
keys = list(pos_probs.keys())
|
|
65
|
-
|
|
66
|
-
p = numpy.array(
|
|
67
|
-
list(pos_probs.values()),
|
|
68
|
-
dtype=numpy.float64
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
p = p ** (self.tdim / 32)
|
|
72
|
-
p /= p.sum()
|
|
73
|
-
|
|
74
|
-
next_word = str(
|
|
75
|
-
numpy.random.choice(keys, p=p)
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
output.append(next_word)
|
|
79
|
-
|
|
80
|
-
output_string = " ".join(output)
|
|
81
|
-
|
|
82
|
-
output_string = re.sub(
|
|
83
|
-
r"User:|Assistant:|[\[\]\'\",]",
|
|
84
|
-
"",
|
|
85
|
-
output_string
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
return re.sub(r"\s+", " ", output_string).strip()
|
|
File without changes
|
|
File without changes
|
{sonicperformance-1.1.0 → sonicperformance-1.2}/src/SonicPerformance.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|