spark-nlp 6.1.3rc1__py2.py3-none-any.whl → 6.1.4__py2.py3-none-any.whl

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.

Potentially problematic release.


This version of spark-nlp might be problematic. Click here for more details.

@@ -1,174 +0,0 @@
1
- # Copyright 2017-2025 John Snow Labs
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """Contains classes for Extractor."""
15
- from sparknlp.common import *
16
-
17
- class Extractor(AnnotatorModel):
18
- name = "Extractor"
19
-
20
- inputAnnotatorTypes = [AnnotatorType.DOCUMENT]
21
-
22
- outputAnnotatorType = AnnotatorType.CHUNK
23
-
24
- emailDateTimeTzPattern = Param(Params._dummy(),
25
- "emailDateTimeTzPattern",
26
- "Specifies the date-time pattern for email timestamps, including time zone formatting.",
27
- typeConverter=TypeConverters.toString)
28
-
29
- emailAddress = Param(
30
- Params._dummy(),
31
- "emailAddress",
32
- "Specifies the pattern for email addresses.",
33
- typeConverter=TypeConverters.toString
34
- )
35
-
36
- ipAddressPattern = Param(
37
- Params._dummy(),
38
- "ipAddressPattern",
39
- "Specifies the pattern for IP addresses.",
40
- typeConverter=TypeConverters.toString
41
- )
42
-
43
- ipAddressNamePattern = Param(
44
- Params._dummy(),
45
- "ipAddressNamePattern",
46
- "Specifies the pattern for IP addresses with names.",
47
- typeConverter=TypeConverters.toString
48
- )
49
-
50
- mapiIdPattern = Param(
51
- Params._dummy(),
52
- "mapiIdPattern",
53
- "Specifies the pattern for MAPI IDs.",
54
- typeConverter=TypeConverters.toString
55
- )
56
-
57
- usPhoneNumbersPattern = Param(
58
- Params._dummy(),
59
- "usPhoneNumbersPattern",
60
- "Specifies the pattern for US phone numbers.",
61
- typeConverter=TypeConverters.toString
62
- )
63
-
64
- imageUrlPattern = Param(
65
- Params._dummy(),
66
- "imageUrlPattern",
67
- "Specifies the pattern for image URLs.",
68
- typeConverter=TypeConverters.toString
69
- )
70
-
71
- textPattern = Param(
72
- Params._dummy(),
73
- "textPattern",
74
- "Specifies the pattern for text after and before.",
75
- typeConverter=TypeConverters.toString
76
- )
77
-
78
- extractorMode = Param(
79
- Params._dummy(),
80
- "extractorMode",
81
- "possible values: " +
82
- "email_date, email_address, ip_address, ip_address_name, mapi_id, us_phone_numbers, image_urls, bullets, text_after, text_before",
83
- typeConverter=TypeConverters.toString
84
- )
85
-
86
- def setEmailDateTimeTzPattern(self, value):
87
- """Sets specifies the date-time pattern for email timestamps, including time zone formatting.
88
-
89
- Parameters
90
- ----------
91
- value : str
92
- Specifies the date-time pattern for email timestamps, including time zone formatting.
93
- """
94
- return self._set(emailDateTimeTzPattern=value)
95
-
96
- def setEmailAddress(self, value):
97
- """Sets the pattern for email addresses.
98
-
99
- Parameters
100
- ----------
101
- value : str
102
- Specifies the pattern for email addresses.
103
- """
104
- return self._set(emailAddress=value)
105
-
106
- def setIpAddressPattern(self, value):
107
- """Sets the pattern for IP addresses.
108
-
109
- Parameters
110
- ----------
111
- value : str
112
- Specifies the pattern for IP addresses.
113
- """
114
- return self._set(ipAddressPattern=value)
115
-
116
- def setIpAddressNamePattern(self, value):
117
- """Sets the pattern for IP addresses with names.
118
-
119
- Parameters
120
- ----------
121
- value : str
122
- Specifies the pattern for IP addresses with names.
123
- """
124
- return self._set(ipAddressNamePattern=value)
125
-
126
- def setMapiIdPattern(self, value):
127
- """Sets the pattern for MAPI IDs.
128
-
129
- Parameters
130
- ----------
131
- value : str
132
- Specifies the pattern for MAPI IDs.
133
- """
134
- return self._set(mapiIdPattern=value)
135
-
136
- def setUsPhoneNumbersPattern(self, value):
137
- """Sets the pattern for US phone numbers.
138
-
139
- Parameters
140
- ----------
141
- value : str
142
- Specifies the pattern for US phone numbers.
143
- """
144
- return self._set(usPhoneNumbersPattern=value)
145
-
146
- def setImageUrlPattern(self, value):
147
- """Sets the pattern for image URLs.
148
-
149
- Parameters
150
- ----------
151
- value : str
152
- Specifies the pattern for image URLs.
153
- """
154
- return self._set(imageUrlPattern=value)
155
-
156
- def setTextPattern(self, value):
157
- """Sets the pattern for text after and before.
158
-
159
- Parameters
160
- ----------
161
- value : str
162
- Specifies the pattern for text after and before.
163
- """
164
- return self._set(textPattern=value)
165
-
166
- def setExtractorMode(self, value):
167
- return self._set(extractorMode=value)
168
-
169
- @keyword_only
170
- def __init__(self, classname="com.johnsnowlabs.nlp.annotators.Extractor", java_model=None):
171
- super(Extractor, self).__init__(
172
- classname=classname,
173
- java_model=java_model
174
- )
@@ -1,352 +0,0 @@
1
- # Copyright 2017-2023 John Snow Labs
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """Contains classes for OpenAICompletion."""
15
- from sparknlp.common import *
16
-
17
- """Transformer that makes a request for OpenAI Completion API for each executor.
18
-
19
- See OpenAI API Doc: https://platform.openai.com/docs/api-reference/completions/create for reference
20
-
21
- ====================== ======================
22
- Input Annotation types Output Annotation type
23
- ====================== ======================
24
- ``DOCUMENT`` ``DOCUMENT``
25
- ====================== ======================
26
-
27
- Parameters
28
- ----------
29
- model
30
- ID of the OpenAI model to use
31
- suffix
32
- The suffix that comes after a completion of inserted text
33
- maxTokens
34
- The maximum number of tokens to generate in the completion.
35
- temperature
36
- What sampling temperature to use, between 0 and 2
37
- topP
38
- An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass
39
- numberOfCompletions
40
- How many completions to generate for each prompt.
41
- logprobs
42
- Include the log probabilities on the logprobs most likely tokens, as well the chosen tokens.
43
- echo
44
- Echo back the prompt in addition to the completion
45
- stop
46
- Up to 4 sequences where the API will stop generating further tokens.
47
- presencePenalty
48
- Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
49
- frequencyPenalty
50
- Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
51
- bestOf
52
- Generates best_of completions server-side and returns the `best` (the one with the highest log probability per token).
53
- logitBias
54
- Modify the likelihood of specified tokens appearing in the completion.
55
- user
56
- A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
57
-
58
- Examples
59
- --------
60
- >>> import sparknlp
61
- >>> from sparknlp.base import *
62
- >>> from sparknlp.annotator import *
63
- >>> from sparknlp.common import *
64
- >>> from pyspark.ml import Pipeline
65
-
66
- >>> documentAssembler = DocumentAssembler() \\
67
- ... .setInputCol("text") \\
68
- ... .setOutputCol("document")
69
- >>> openai_completion = OpenAICompletion() \\
70
- ... .setInputCols("document") \\
71
- ... .setOutputCol("completion") \\
72
- ... .setModel("text-davinci-003") \\
73
- ... .setMaxTokens(100)
74
- >>> pipeline = Pipeline().setStages([
75
- ... documentAssembler,
76
- ... openai_completion
77
- ... ])
78
- >>> empty_df = spark.createDataFrame([[""]], ["text"])
79
- >>> sample_text= [["Generate a restaurant review."], ["Write a review for a local eatery."], ["Create a JSON with a review of a dining experience."]]
80
- >>> sample_df = spark.createDataFrame(sample_text).toDF("text")
81
- >>> sample_df.show()
82
- +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
83
- |completion |
84
- +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
85
- |[{document, 0, 258, \n\nI had the pleasure of dining at La Fiorita recently, and it was a truly delightful experience! The menu boasted a wonderful selection of classic Italian dishes, all exquisitely prepared and presented. The service staff was friendly and attentive and really, {}, []}]|
86
- |[{document, 0, 227, \n\nI recently visited Barbecue Joe's for dinner and it was amazing! The menu had so many items to choose from including pulled pork, smoked turkey, brisket, pork ribs, and sandwiches. I opted for the pulled pork sandwich and let, {}, []}] |
87
- |[{document, 0, 172, \n\n{ \n "review": { \n "overallRating": 4, \n "reviewBody": "I enjoyed my meal at this restaurant. The food was flavourful, well-prepared and beautifully presented., {}, []}] |
88
- +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
89
- """
90
-
91
-
92
- class OpenAICompletion(AnnotatorModel):
93
-
94
- name = "OpenAICompletion"
95
-
96
- inputAnnotatorTypes = [AnnotatorType.DOCUMENT]
97
-
98
- outputAnnotatorType = AnnotatorType.DOCUMENT
99
-
100
- model = Param(Params._dummy(),
101
- "model",
102
- "ID of the OpenAI model to use",
103
- typeConverter=TypeConverters.toString)
104
-
105
- suffix = Param(Params._dummy(),
106
- "suffix",
107
- "The suffix that comes after a completion of inserted text.",
108
- typeConverter=TypeConverters.toString)
109
-
110
- maxTokens = Param(Params._dummy(),
111
- "maxTokens",
112
- "The maximum number of tokens to generate in the completion.",
113
- typeConverter=TypeConverters.toInt)
114
-
115
- temperature = Param(Params._dummy(),
116
- "temperature",
117
- "What sampling temperature to use, between 0 and 2",
118
- typeConverter=TypeConverters.toFloat)
119
-
120
- topP = Param(Params._dummy(),
121
- "topP",
122
- "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass",
123
- typeConverter=TypeConverters.toFloat)
124
-
125
- numberOfCompletions = Param(Params._dummy(),
126
- "numberOfCompletions",
127
- "How many completions to generate for each prompt.",
128
- typeConverter=TypeConverters.toInt)
129
-
130
- logprobs = Param(Params._dummy(),
131
- "logprobs",
132
- "Include the log probabilities on the logprobs most likely tokens, as well the chosen tokens.",
133
- typeConverter=TypeConverters.toInt)
134
-
135
- echo = Param(Params._dummy(),
136
- "echo",
137
- "Echo back the prompt in addition to the completion",
138
- typeConverter=TypeConverters.toBoolean)
139
-
140
- stop = Param(Params._dummy(),
141
- "stop",
142
- "Up to 4 sequences where the API will stop generating further tokens.",
143
- typeConverter=TypeConverters.toListString)
144
-
145
- presencePenalty = Param(Params._dummy(),
146
- "presencePenalty",
147
- "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.",
148
- typeConverter=TypeConverters.toFloat)
149
-
150
- frequencyPenalty = Param(Params._dummy(),
151
- "frequencyPenalty",
152
- "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.",
153
- typeConverter=TypeConverters.toFloat)
154
-
155
- bestOf = Param(Params._dummy(),
156
- "bestOf",
157
- "Generates best_of completions server-side and returns the `best` (the one with the highest log probability per token).",
158
- typeConverter=TypeConverters.toInt)
159
-
160
- logitBias = Param(Params._dummy(),
161
- "logitBias",
162
- "Modify the likelihood of specified tokens appearing in the completion.",
163
- typeConverter=TypeConverters.identity)
164
-
165
- user = Param(Params._dummy(),
166
- "user",
167
- "A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.",
168
- typeConverter=TypeConverters.toString)
169
-
170
- def setModel(self, value):
171
- """Sets model ID of the OpenAI model to use
172
-
173
- Parameters
174
- ----------
175
- value : str
176
- ID of the OpenAI model to use
177
- """
178
- return self._set(model=value)
179
-
180
- def setSuffix(self, value):
181
- """Sets the suffix that comes after a completion of inserted text.
182
-
183
- Parameters
184
- ----------
185
- value : str
186
- The suffix that comes after a completion of inserted text.
187
- """
188
- return self._set(suffix=value)
189
-
190
- def setMaxTokens(self, value):
191
- """Sets the maximum number of tokens to generate in the completion.
192
- The token count of your prompt plus max_tokens cannot exceed the model's context length.
193
-
194
- Parameters
195
- ----------
196
- value : int
197
- The maximum number of tokens to generate in the completion.
198
- """
199
- return self._set(maxTokens=value)
200
-
201
- def setTemperature(self, value):
202
- """Sets what sampling temperature to use, between 0 and 2.
203
- Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
204
- We generally recommend altering this or top_p but not both.
205
-
206
- Parameters
207
- ----------
208
- value : float
209
- What sampling temperature to use, between 0 and 2
210
- """
211
- return self._set(temperature=value)
212
-
213
- def setTopP(self, value):
214
- """Sets An alternative to sampling with temperature, called nucleus sampling.
215
- Where the model considers the results of the tokens with top_p probability mass.
216
- So 0.1 means only the tokens comprising the top 10% probability mass are considered.
217
- We generally recommend altering this or temperature but not both.
218
-
219
- Parameters
220
- ----------
221
- value : float
222
- An alternative to sampling with temperature, called nucleus sampling, where the model considers the results
223
- of the tokens with top_p probability mass
224
- """
225
- return self._set(topP=value)
226
-
227
- def setNumberOfCompletions(self, value):
228
- """Sets how many completions to generate for each prompt.
229
-
230
- Note: Because this parameter generates many completions, it can quickly consume your token quota.
231
- Use carefully and ensure that you have reasonable settings for max_tokens and stop.
232
-
233
- Parameters
234
- ----------
235
- value : int
236
- How many completions to generate for each prompt.
237
- """
238
- return self._set(numberOfCompletions=value)
239
-
240
- def setLogprobs(self, value):
241
- """Sets the log probabilities on the logprobs most likely tokens, as well the chosen tokens.
242
- For example, if logprobs is 5, the API will return a list of the 5 most likely tokens.
243
- The API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response.
244
- The maximum value for logprobs is 5.
245
-
246
- Parameters
247
- ----------
248
- value : int
249
- How many completions to generate for each prompt.
250
- """
251
- return self._set(logprobs=value)
252
-
253
- def setEcho(self, value):
254
- """Sets echo back the prompt in addition to the completion
255
-
256
- Parameters
257
- ----------
258
- value : str
259
- Echo back the prompt in addition to the completion
260
- """
261
- return self._set(echo=value)
262
-
263
- def setStop(self, value):
264
- """Sets Up to 4 sequences where the API will stop generating further tokens.
265
- The returned text will not contain the stop sequence.
266
-
267
- Parameters
268
- ----------
269
- value : List[str]
270
- Up to 4 sequences where the API will stop generating further tokens.
271
- """
272
- return self._set(stop=value)
273
-
274
- def setPresencePenalty(self, value):
275
- """Sets values to penalize new tokens based on whether they appear in the text so far,
276
- increasing the model's likelihood to talk about new topics.
277
-
278
- Parameters
279
- ----------
280
- value : int
281
- Number between -2.0 and 2.0.
282
- Positive values penalize new tokens based on whether they appear in the text so far,
283
- increasing the model's likelihood to talk about new topics.
284
- """
285
- return self._set(presencePenalty=value)
286
-
287
- def setFrequencyPenalty(self, value):
288
- """Sets values to penalize new tokens based on their existing frequency in the text so far,
289
- decreasing the model's likelihood to repeat the same line verbatim.
290
-
291
- Parameters
292
- ----------
293
- value : int
294
- Number between -2.0 and 2.0.
295
- Positive values penalize new tokens based on their existing frequency in the text so far,
296
- decreasing the model's likelihood to repeat the same line verbatim.
297
- """
298
- return self._set(frequencyPenalty=value)
299
-
300
- def setBestOf(self, value):
301
- """Sets best_of completions server-side and returns the "best" (the one with the highest log probability per token)
302
-
303
- Parameters
304
- ----------
305
- value : int
306
- Generates best_of completions server-side and returns the "best" (the one with the highest log probability per token).
307
- Results cannot be streamed.
308
- When used with n, best_of controls the number of candidate completions and n specifies how many to return – best_of must be greater than n.
309
- Note: Because this parameter generates many completions, it can quickly consume your token quota.
310
- Use carefully and ensure that you have reasonable settings for max_tokens and stop.
311
- """
312
- return self._set(bestOf=value)
313
-
314
- def setLogitBias(self, value):
315
- """Sets the likelihood of specified tokens appearing in the completion
316
-
317
- Parameters
318
- ----------
319
- value : dict
320
- Modify the likelihood of specified tokens appearing in the completion.
321
- Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated
322
- bias value from -100 to 100. You can use this tokenizer tool (which works for both GPT-2 and GPT-3) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
323
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|> token from being generated.
324
- """
325
- return self._set(logitBias=value)
326
-
327
- def setUser(self, value):
328
- """Sets a unique identifier representing your end-user
329
-
330
- Parameters
331
- ----------
332
- value : str
333
- A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
334
- """
335
- return self._set(user=value)
336
-
337
- @keyword_only
338
- def __init__(self, classname="com.johnsnowlabs.ml.ai.OpenAICompletion", java_model=None):
339
- super(OpenAICompletion, self).__init__(
340
- classname=classname,
341
- java_model=java_model
342
- )
343
- self._setDefault(
344
- maxTokens=16,
345
- temperature=1,
346
- topP=1,
347
- numberOfCompletions=1,
348
- echo=False,
349
- presencePenalty=0,
350
- frequencyPenalty=0,
351
- bestOf=1
352
- )