stream2sentence 0.3.0__tar.gz → 0.3.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.
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/PKG-INFO +60 -5
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/README.md +45 -0
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/setup.py +4 -4
- stream2sentence-0.3.2/stream2sentence/__init__.py +14 -0
- stream2sentence-0.3.2/stream2sentence/avoid_pause_words.py +65 -0
- stream2sentence-0.3.2/stream2sentence/delimiter_ignore_prefixes.py +34 -0
- stream2sentence-0.3.2/stream2sentence/stream2sentence.py +662 -0
- stream2sentence-0.3.2/stream2sentence/stream2sentence_time_based.py +241 -0
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/stream2sentence.egg-info/PKG-INFO +60 -5
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/stream2sentence.egg-info/SOURCES.txt +5 -1
- stream2sentence-0.3.2/stream2sentence.egg-info/requires.txt +3 -0
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/tests/test_stream2sentence.py +2 -1
- stream2sentence-0.3.2/tests/test_stream_from_llm.py +20 -0
- stream2sentence-0.3.2/tests/test_time_based.py +134 -0
- stream2sentence-0.3.0/stream2sentence/__init__.py +0 -5
- stream2sentence-0.3.0/stream2sentence/stream2sentence.py +0 -513
- stream2sentence-0.3.0/stream2sentence.egg-info/requires.txt +0 -3
- stream2sentence-0.3.0/tests/test_stream_from_llm.py +0 -48
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/setup.cfg +0 -0
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/stream2sentence.egg-info/dependency_links.txt +0 -0
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/stream2sentence.egg-info/top_level.txt +0 -0
- {stream2sentence-0.3.0 → stream2sentence-0.3.2}/tests/test_stream_from_llm_old_api.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: stream2sentence
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Real-time processing and delivery of sentences from a continuous stream of characters or text chunks.
|
|
5
5
|
Home-page: https://github.com/KoljaB/stream2sentence
|
|
6
6
|
Author: Kolja Beigel
|
|
@@ -11,9 +11,19 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
11
11
|
Classifier: Operating System :: OS Independent
|
|
12
12
|
Requires-Python: >=3.6
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
|
-
Requires-Dist: nltk==3.9.
|
|
15
|
-
Requires-Dist: emoji==2.
|
|
16
|
-
Requires-Dist: stanza==1.
|
|
14
|
+
Requires-Dist: nltk==3.9.4
|
|
15
|
+
Requires-Dist: emoji==2.15.0
|
|
16
|
+
Requires-Dist: stanza==1.11.1
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: keywords
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
Dynamic: summary
|
|
17
27
|
|
|
18
28
|
# Real-Time Sentence Detection
|
|
19
29
|
|
|
@@ -170,6 +180,51 @@ These parameters control how quickly and frequently the generator yields sentenc
|
|
|
170
180
|
- Ensures timely output even with long opening sentences.
|
|
171
181
|
- Default: 15 words
|
|
172
182
|
|
|
183
|
+
|
|
184
|
+
## Time based strategy
|
|
185
|
+
Instead of a purely lexigraphical strategy, a time based strategy is available.
|
|
186
|
+
A target tokens per second (tps) is input, and generate_sentences will yield the best
|
|
187
|
+
available output (full sentence, longest fragment, or any available buffer, in that order) if it is approaching a "deadline"
|
|
188
|
+
where what has been output would be slower than the input tps target. If LLM is more than
|
|
189
|
+
two full sentences ahead of the target it will output a sentence even if it's ahead of the "deadline"
|
|
190
|
+
|
|
191
|
+
`from stream2sentence.stream2sentence_time_based import generate_sentences_time_based`
|
|
192
|
+
|
|
193
|
+
### Parameters
|
|
194
|
+
- `generator (Iterator[str])`
|
|
195
|
+
- A generator that yields chunks of text as a stream of characters.`
|
|
196
|
+
- `target_tps: float = 4`
|
|
197
|
+
- the rate in tokens per second you want to use to calculate deadlines for output.
|
|
198
|
+
- Default is 4. (approximately the speed of human speech)
|
|
199
|
+
- `lead_time: float = 1`
|
|
200
|
+
- amount of time in seconds to wait for the buffer to build for before returning values.
|
|
201
|
+
- `max_wait_for_fragments = [3, 2]`
|
|
202
|
+
- Max amount of time in seconds that the Nth sentence will wait beyond the "deadline" for a "fragment" (text preceeding a fragment delimiter), which is preferred over a piece of buffer.
|
|
203
|
+
- The last value in the array is used for all subsequent checks.
|
|
204
|
+
- `min_output_lengths: int[] = [2, 3, 3, 4]`
|
|
205
|
+
- An array that corresponds to the minimum output size in words for the corresponding output sentence, the last value in the array is used for all remaining output.
|
|
206
|
+
- For example [4,5,6] would mean the first piece of output must have 4 words, the second 5 words, and all subsequent 6.
|
|
207
|
+
- `preferred_sentence_fragment_delimiters: str[] = ['. ', '? ', '! ', '\n']`
|
|
208
|
+
- Array of strings that deliniate a sentence fragment. "Preferred" are checked first and always used if the fragment meets the length requirement over the other fragment delimiters.
|
|
209
|
+
- Note the trailing spaces, added to differentiate between values like $3.5 and a proper sentence end
|
|
210
|
+
- `sentence_fragment_delimiters: str[] = ['; ', ': ', ', ', '* ', '**', '– ']`
|
|
211
|
+
- Array of strings that are checked after "preferred" delimiters
|
|
212
|
+
- `delimiter_ignore_prefixes: str[]`
|
|
213
|
+
- Array of strings that will not be considered "delimiters" if preceeded by a delimiter.
|
|
214
|
+
- Used to ignore common abbreviations for things like Mr. Dr. and Mrs. where we don't want to split
|
|
215
|
+
- Default is a long list documented in delimiter_ignore_prefixes
|
|
216
|
+
- `wait_for_if_non_fragment: str[]`
|
|
217
|
+
- Array of strings that the algorithm will not use as the last value if the whole buffer is being output (not a fragment or sentence).
|
|
218
|
+
- Avoids awkward pauses on common words that are unnatural to pause at.
|
|
219
|
+
- Default is a long list of common words documented in avoid_pause_words.py
|
|
220
|
+
- `deadline_offsets_static: float[] = [1]`
|
|
221
|
+
- Constant amount of time in seconds to subtract from the deadline for first n sentences.
|
|
222
|
+
- Last value applied to all subsequent sentences
|
|
223
|
+
- `deadline_offsets_dynamic: float[] = [0]`:
|
|
224
|
+
- Added to account for the time it takes a TTS engine to generate output.
|
|
225
|
+
- For example, if it takes your TTS engine around 1 second to generate 10 words, you can use a value of 0.1 so that the TTS generation time is included in the deadline.
|
|
226
|
+
- Applied to first n sentences, last value applied to all subsequent
|
|
227
|
+
|
|
173
228
|
## Contributing
|
|
174
229
|
|
|
175
230
|
Any Contributions you make are welcome and **greatly appreciated**.
|
|
@@ -153,6 +153,51 @@ These parameters control how quickly and frequently the generator yields sentenc
|
|
|
153
153
|
- Ensures timely output even with long opening sentences.
|
|
154
154
|
- Default: 15 words
|
|
155
155
|
|
|
156
|
+
|
|
157
|
+
## Time based strategy
|
|
158
|
+
Instead of a purely lexigraphical strategy, a time based strategy is available.
|
|
159
|
+
A target tokens per second (tps) is input, and generate_sentences will yield the best
|
|
160
|
+
available output (full sentence, longest fragment, or any available buffer, in that order) if it is approaching a "deadline"
|
|
161
|
+
where what has been output would be slower than the input tps target. If LLM is more than
|
|
162
|
+
two full sentences ahead of the target it will output a sentence even if it's ahead of the "deadline"
|
|
163
|
+
|
|
164
|
+
`from stream2sentence.stream2sentence_time_based import generate_sentences_time_based`
|
|
165
|
+
|
|
166
|
+
### Parameters
|
|
167
|
+
- `generator (Iterator[str])`
|
|
168
|
+
- A generator that yields chunks of text as a stream of characters.`
|
|
169
|
+
- `target_tps: float = 4`
|
|
170
|
+
- the rate in tokens per second you want to use to calculate deadlines for output.
|
|
171
|
+
- Default is 4. (approximately the speed of human speech)
|
|
172
|
+
- `lead_time: float = 1`
|
|
173
|
+
- amount of time in seconds to wait for the buffer to build for before returning values.
|
|
174
|
+
- `max_wait_for_fragments = [3, 2]`
|
|
175
|
+
- Max amount of time in seconds that the Nth sentence will wait beyond the "deadline" for a "fragment" (text preceeding a fragment delimiter), which is preferred over a piece of buffer.
|
|
176
|
+
- The last value in the array is used for all subsequent checks.
|
|
177
|
+
- `min_output_lengths: int[] = [2, 3, 3, 4]`
|
|
178
|
+
- An array that corresponds to the minimum output size in words for the corresponding output sentence, the last value in the array is used for all remaining output.
|
|
179
|
+
- For example [4,5,6] would mean the first piece of output must have 4 words, the second 5 words, and all subsequent 6.
|
|
180
|
+
- `preferred_sentence_fragment_delimiters: str[] = ['. ', '? ', '! ', '\n']`
|
|
181
|
+
- Array of strings that deliniate a sentence fragment. "Preferred" are checked first and always used if the fragment meets the length requirement over the other fragment delimiters.
|
|
182
|
+
- Note the trailing spaces, added to differentiate between values like $3.5 and a proper sentence end
|
|
183
|
+
- `sentence_fragment_delimiters: str[] = ['; ', ': ', ', ', '* ', '**', '– ']`
|
|
184
|
+
- Array of strings that are checked after "preferred" delimiters
|
|
185
|
+
- `delimiter_ignore_prefixes: str[]`
|
|
186
|
+
- Array of strings that will not be considered "delimiters" if preceeded by a delimiter.
|
|
187
|
+
- Used to ignore common abbreviations for things like Mr. Dr. and Mrs. where we don't want to split
|
|
188
|
+
- Default is a long list documented in delimiter_ignore_prefixes
|
|
189
|
+
- `wait_for_if_non_fragment: str[]`
|
|
190
|
+
- Array of strings that the algorithm will not use as the last value if the whole buffer is being output (not a fragment or sentence).
|
|
191
|
+
- Avoids awkward pauses on common words that are unnatural to pause at.
|
|
192
|
+
- Default is a long list of common words documented in avoid_pause_words.py
|
|
193
|
+
- `deadline_offsets_static: float[] = [1]`
|
|
194
|
+
- Constant amount of time in seconds to subtract from the deadline for first n sentences.
|
|
195
|
+
- Last value applied to all subsequent sentences
|
|
196
|
+
- `deadline_offsets_dynamic: float[] = [0]`:
|
|
197
|
+
- Added to account for the time it takes a TTS engine to generate output.
|
|
198
|
+
- For example, if it takes your TTS engine around 1 second to generate 10 words, you can use a value of 0.1 so that the TTS generation time is included in the deadline.
|
|
199
|
+
- Applied to first n sentences, last value applied to all subsequent
|
|
200
|
+
|
|
156
201
|
## Contributing
|
|
157
202
|
|
|
158
203
|
Any Contributions you make are welcome and **greatly appreciated**.
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
7
|
name="stream2sentence",
|
|
8
|
-
version="0.3.
|
|
8
|
+
version="0.3.2",
|
|
9
9
|
author="Kolja Beigel",
|
|
10
10
|
author_email="kolja.beigel@web.de",
|
|
11
11
|
description="Real-time processing and delivery of sentences from a continuous stream of characters or text chunks.",
|
|
@@ -20,9 +20,9 @@ setuptools.setup(
|
|
|
20
20
|
],
|
|
21
21
|
python_requires='>=3.6',
|
|
22
22
|
install_requires=[
|
|
23
|
-
'nltk==3.9.
|
|
24
|
-
'emoji==2.
|
|
25
|
-
'stanza==1.
|
|
23
|
+
'nltk==3.9.4',
|
|
24
|
+
'emoji==2.15.0',
|
|
25
|
+
'stanza==1.11.1'
|
|
26
26
|
],
|
|
27
27
|
keywords='realtime, text streaming, stream, sentence, sentence detection, sentence generation, tts, speech synthesis, nltk, text analysis, audio processing, boundary detection, sentence boundary detection'
|
|
28
28
|
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .stream2sentence import (
|
|
2
|
+
generate_sentences,
|
|
3
|
+
generate_sentences_async,
|
|
4
|
+
init_tokenizer,
|
|
5
|
+
SentenceSplitter,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
from .stream2sentence_time_based import (
|
|
9
|
+
generate_sentences_time_based,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from .avoid_pause_words import (
|
|
13
|
+
AVOID_PAUSE_WORDS,
|
|
14
|
+
)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
# Conjunctions
|
|
4
|
+
conjunctions = ["and", "or", "but", "so", "for", "nor", "yet"]
|
|
5
|
+
|
|
6
|
+
# Prepositions
|
|
7
|
+
prepositions = [
|
|
8
|
+
"in", "on", "at", "by", "with", "about", "of", "to", "for",
|
|
9
|
+
"from", "as", "over", "under", "through", "between", "during", "there"
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
# Articles
|
|
13
|
+
articles = ["a", "an", "the"]
|
|
14
|
+
|
|
15
|
+
# Possessives and Demonstratives
|
|
16
|
+
possessives_and_demonstratives = [
|
|
17
|
+
"my", "your", "his", "her", "its", "our", "their",
|
|
18
|
+
"this", "that", "these", "those"
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
# Auxiliary/Helping Verbs
|
|
22
|
+
auxiliary_verbs = [
|
|
23
|
+
"is", "are", "was", "were", "am", "be", "been", "being",
|
|
24
|
+
"do", "does", "did", "have", "has", "had",
|
|
25
|
+
"can", "could", "shall", "should",
|
|
26
|
+
"will", "would", "may", "might", "must"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
# Pronouns
|
|
30
|
+
pronouns = [
|
|
31
|
+
"I", "we", "you", "he", "she", "it", "they",
|
|
32
|
+
"who", "whom", "whose", "which", "that"
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
# Quantifiers
|
|
36
|
+
quantifiers = ["some", "many", "few", "all", "any", "most", "much", "none", "several"]
|
|
37
|
+
|
|
38
|
+
# Adverbs that Modify Flow
|
|
39
|
+
adverbs = ["very", "too", "just", "quite", "almost", "nearly", "only"]
|
|
40
|
+
|
|
41
|
+
# Interrogatives
|
|
42
|
+
interrogatives = ["what", "where", "when", "why", "how"]
|
|
43
|
+
|
|
44
|
+
# Relative Pronouns
|
|
45
|
+
relative_pronouns = ["who", "which", "that"]
|
|
46
|
+
|
|
47
|
+
# Subordinating Conjunctions
|
|
48
|
+
subordinating_conjunctions = [
|
|
49
|
+
"although", "because", "if", "since",
|
|
50
|
+
"though", "while", "until", "unless"
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
AVOID_PAUSE_WORDS = set(
|
|
54
|
+
conjunctions +
|
|
55
|
+
prepositions +
|
|
56
|
+
articles +
|
|
57
|
+
possessives_and_demonstratives +
|
|
58
|
+
auxiliary_verbs +
|
|
59
|
+
pronouns +
|
|
60
|
+
quantifiers +
|
|
61
|
+
adverbs +
|
|
62
|
+
interrogatives +
|
|
63
|
+
subordinating_conjunctions
|
|
64
|
+
)
|
|
65
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
titles_and_abbreviations = [
|
|
3
|
+
"Mr.", "Mrs.", "Ms.", "Dr.", "Prof.", "Rev.", "St.",
|
|
4
|
+
"Ph.D.", "Phd.", "PhD.", "M.D.", "B.A.", "M.A.", "D.D.S.", "J.D.",
|
|
5
|
+
"Co.", "Corp.", "Ave.", "Blvd.", "Rd.", "Mt.",
|
|
6
|
+
"a.m.", "p.m.", "Jr.", "Sr.",
|
|
7
|
+
"Gov.", "Gen.", "Capt.", "Lt.", "Maj.", "Col.", "Adm.", "Cmdr.",
|
|
8
|
+
"Sgt.", "Cpl.", "Pvt.", "U.S.", "U.K.", "vs.", "i.e.", "e.g.",
|
|
9
|
+
"Vol.", "Art.", "Sec.", "Chap.", "Fig.", "Ref.", "Dept."
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
dates_and_times = [
|
|
13
|
+
"Jan.", "Feb.", "Mar.", "Apr.", "Jun.", "Jul.", "Aug.",
|
|
14
|
+
"Sep.", "Oct.", "Nov.", "Dec.",
|
|
15
|
+
"Mon.", "Tue.", "Wed.", "Thu.", "Fri.", "Sat.", "Sun.",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
financial_abbreviations = [
|
|
19
|
+
"Inc.", "Ltd.", "Corp.", "PLC.", "LLC.", "LLP.",
|
|
20
|
+
"P/E.", "EPS.", "NAV.", "ROI.", "ROA.", "ROE.",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
country_abbreviations = [
|
|
24
|
+
"U.S.A.", "U.K.", "U.A.E.", "P.R.C.", "D.R.C.", "R.O.C.",
|
|
25
|
+
"E.U.", "U.N.", "A.U.",
|
|
26
|
+
"U.S.", "U.K.", "E.U.", "P.R.C.", "D.R.C.", "R.O.C.",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
DELIMITER_IGNORE_PREFIXES = set(
|
|
30
|
+
titles_and_abbreviations + dates_and_times +
|
|
31
|
+
financial_abbreviations + country_abbreviations
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|