spark-nlp 4.2.6__py2.py3-none-any.whl → 6.2.1__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.
Files changed (221) hide show
  1. com/johnsnowlabs/ml/__init__.py +0 -0
  2. com/johnsnowlabs/ml/ai/__init__.py +10 -0
  3. spark_nlp-6.2.1.dist-info/METADATA +362 -0
  4. spark_nlp-6.2.1.dist-info/RECORD +292 -0
  5. {spark_nlp-4.2.6.dist-info → spark_nlp-6.2.1.dist-info}/WHEEL +1 -1
  6. sparknlp/__init__.py +81 -28
  7. sparknlp/annotation.py +3 -2
  8. sparknlp/annotator/__init__.py +6 -0
  9. sparknlp/annotator/audio/__init__.py +2 -0
  10. sparknlp/annotator/audio/hubert_for_ctc.py +188 -0
  11. sparknlp/annotator/audio/wav2vec2_for_ctc.py +14 -14
  12. sparknlp/annotator/audio/whisper_for_ctc.py +251 -0
  13. sparknlp/{base → annotator}/chunk2_doc.py +4 -7
  14. sparknlp/annotator/chunker.py +1 -2
  15. sparknlp/annotator/classifier_dl/__init__.py +17 -0
  16. sparknlp/annotator/classifier_dl/albert_for_multiple_choice.py +161 -0
  17. sparknlp/annotator/classifier_dl/albert_for_question_answering.py +3 -15
  18. sparknlp/annotator/classifier_dl/albert_for_sequence_classification.py +4 -18
  19. sparknlp/annotator/classifier_dl/albert_for_token_classification.py +3 -17
  20. sparknlp/annotator/classifier_dl/albert_for_zero_shot_classification.py +211 -0
  21. sparknlp/annotator/classifier_dl/bart_for_zero_shot_classification.py +225 -0
  22. sparknlp/annotator/classifier_dl/bert_for_multiple_choice.py +161 -0
  23. sparknlp/annotator/classifier_dl/bert_for_question_answering.py +6 -20
  24. sparknlp/annotator/classifier_dl/bert_for_sequence_classification.py +3 -17
  25. sparknlp/annotator/classifier_dl/bert_for_token_classification.py +3 -17
  26. sparknlp/annotator/classifier_dl/bert_for_zero_shot_classification.py +212 -0
  27. sparknlp/annotator/classifier_dl/camembert_for_question_answering.py +168 -0
  28. sparknlp/annotator/classifier_dl/camembert_for_sequence_classification.py +5 -19
  29. sparknlp/annotator/classifier_dl/camembert_for_token_classification.py +5 -19
  30. sparknlp/annotator/classifier_dl/camembert_for_zero_shot_classification.py +202 -0
  31. sparknlp/annotator/classifier_dl/classifier_dl.py +4 -4
  32. sparknlp/annotator/classifier_dl/deberta_for_question_answering.py +3 -17
  33. sparknlp/annotator/classifier_dl/deberta_for_sequence_classification.py +4 -19
  34. sparknlp/annotator/classifier_dl/deberta_for_token_classification.py +5 -21
  35. sparknlp/annotator/classifier_dl/deberta_for_zero_shot_classification.py +193 -0
  36. sparknlp/annotator/classifier_dl/distil_bert_for_question_answering.py +3 -17
  37. sparknlp/annotator/classifier_dl/distil_bert_for_sequence_classification.py +4 -18
  38. sparknlp/annotator/classifier_dl/distil_bert_for_token_classification.py +3 -17
  39. sparknlp/annotator/classifier_dl/distil_bert_for_zero_shot_classification.py +211 -0
  40. sparknlp/annotator/classifier_dl/distilbert_for_multiple_choice.py +161 -0
  41. sparknlp/annotator/classifier_dl/longformer_for_question_answering.py +3 -17
  42. sparknlp/annotator/classifier_dl/longformer_for_sequence_classification.py +4 -18
  43. sparknlp/annotator/classifier_dl/longformer_for_token_classification.py +3 -17
  44. sparknlp/annotator/classifier_dl/mpnet_for_question_answering.py +148 -0
  45. sparknlp/annotator/classifier_dl/mpnet_for_sequence_classification.py +188 -0
  46. sparknlp/annotator/classifier_dl/mpnet_for_token_classification.py +173 -0
  47. sparknlp/annotator/classifier_dl/multi_classifier_dl.py +3 -3
  48. sparknlp/annotator/classifier_dl/roberta_for_multiple_choice.py +161 -0
  49. sparknlp/annotator/classifier_dl/roberta_for_question_answering.py +3 -17
  50. sparknlp/annotator/classifier_dl/roberta_for_sequence_classification.py +4 -18
  51. sparknlp/annotator/classifier_dl/roberta_for_token_classification.py +1 -1
  52. sparknlp/annotator/classifier_dl/roberta_for_zero_shot_classification.py +225 -0
  53. sparknlp/annotator/classifier_dl/sentiment_dl.py +4 -4
  54. sparknlp/annotator/classifier_dl/tapas_for_question_answering.py +2 -2
  55. sparknlp/annotator/classifier_dl/xlm_roberta_for_multiple_choice.py +149 -0
  56. sparknlp/annotator/classifier_dl/xlm_roberta_for_question_answering.py +3 -17
  57. sparknlp/annotator/classifier_dl/xlm_roberta_for_sequence_classification.py +4 -18
  58. sparknlp/annotator/classifier_dl/xlm_roberta_for_token_classification.py +6 -20
  59. sparknlp/annotator/classifier_dl/xlm_roberta_for_zero_shot_classification.py +225 -0
  60. sparknlp/annotator/classifier_dl/xlnet_for_sequence_classification.py +4 -18
  61. sparknlp/annotator/classifier_dl/xlnet_for_token_classification.py +3 -17
  62. sparknlp/annotator/cleaners/__init__.py +15 -0
  63. sparknlp/annotator/cleaners/cleaner.py +202 -0
  64. sparknlp/annotator/cleaners/extractor.py +191 -0
  65. sparknlp/annotator/coref/spanbert_coref.py +4 -18
  66. sparknlp/annotator/cv/__init__.py +15 -0
  67. sparknlp/annotator/cv/blip_for_question_answering.py +172 -0
  68. sparknlp/annotator/cv/clip_for_zero_shot_classification.py +193 -0
  69. sparknlp/annotator/cv/convnext_for_image_classification.py +269 -0
  70. sparknlp/annotator/cv/florence2_transformer.py +180 -0
  71. sparknlp/annotator/cv/gemma3_for_multimodal.py +346 -0
  72. sparknlp/annotator/cv/internvl_for_multimodal.py +280 -0
  73. sparknlp/annotator/cv/janus_for_multimodal.py +351 -0
  74. sparknlp/annotator/cv/llava_for_multimodal.py +328 -0
  75. sparknlp/annotator/cv/mllama_for_multimodal.py +340 -0
  76. sparknlp/annotator/cv/paligemma_for_multimodal.py +308 -0
  77. sparknlp/annotator/cv/phi3_vision_for_multimodal.py +328 -0
  78. sparknlp/annotator/cv/qwen2vl_transformer.py +332 -0
  79. sparknlp/annotator/cv/smolvlm_transformer.py +426 -0
  80. sparknlp/annotator/cv/swin_for_image_classification.py +242 -0
  81. sparknlp/annotator/cv/vision_encoder_decoder_for_image_captioning.py +240 -0
  82. sparknlp/annotator/cv/vit_for_image_classification.py +36 -4
  83. sparknlp/annotator/dataframe_optimizer.py +216 -0
  84. sparknlp/annotator/date2_chunk.py +88 -0
  85. sparknlp/annotator/dependency/dependency_parser.py +2 -3
  86. sparknlp/annotator/dependency/typed_dependency_parser.py +3 -4
  87. sparknlp/annotator/document_character_text_splitter.py +228 -0
  88. sparknlp/annotator/document_normalizer.py +37 -1
  89. sparknlp/annotator/document_token_splitter.py +175 -0
  90. sparknlp/annotator/document_token_splitter_test.py +85 -0
  91. sparknlp/annotator/embeddings/__init__.py +11 -0
  92. sparknlp/annotator/embeddings/albert_embeddings.py +4 -18
  93. sparknlp/annotator/embeddings/auto_gguf_embeddings.py +539 -0
  94. sparknlp/annotator/embeddings/bert_embeddings.py +9 -22
  95. sparknlp/annotator/embeddings/bert_sentence_embeddings.py +12 -24
  96. sparknlp/annotator/embeddings/bge_embeddings.py +199 -0
  97. sparknlp/annotator/embeddings/camembert_embeddings.py +4 -20
  98. sparknlp/annotator/embeddings/chunk_embeddings.py +1 -2
  99. sparknlp/annotator/embeddings/deberta_embeddings.py +2 -16
  100. sparknlp/annotator/embeddings/distil_bert_embeddings.py +5 -19
  101. sparknlp/annotator/embeddings/doc2vec.py +7 -1
  102. sparknlp/annotator/embeddings/e5_embeddings.py +195 -0
  103. sparknlp/annotator/embeddings/e5v_embeddings.py +138 -0
  104. sparknlp/annotator/embeddings/elmo_embeddings.py +2 -2
  105. sparknlp/annotator/embeddings/instructor_embeddings.py +204 -0
  106. sparknlp/annotator/embeddings/longformer_embeddings.py +3 -17
  107. sparknlp/annotator/embeddings/minilm_embeddings.py +189 -0
  108. sparknlp/annotator/embeddings/mpnet_embeddings.py +192 -0
  109. sparknlp/annotator/embeddings/mxbai_embeddings.py +184 -0
  110. sparknlp/annotator/embeddings/nomic_embeddings.py +181 -0
  111. sparknlp/annotator/embeddings/roberta_embeddings.py +9 -21
  112. sparknlp/annotator/embeddings/roberta_sentence_embeddings.py +7 -21
  113. sparknlp/annotator/embeddings/sentence_embeddings.py +2 -3
  114. sparknlp/annotator/embeddings/snowflake_embeddings.py +202 -0
  115. sparknlp/annotator/embeddings/uae_embeddings.py +211 -0
  116. sparknlp/annotator/embeddings/universal_sentence_encoder.py +3 -3
  117. sparknlp/annotator/embeddings/word2vec.py +7 -1
  118. sparknlp/annotator/embeddings/word_embeddings.py +4 -5
  119. sparknlp/annotator/embeddings/xlm_roberta_embeddings.py +9 -21
  120. sparknlp/annotator/embeddings/xlm_roberta_sentence_embeddings.py +7 -21
  121. sparknlp/annotator/embeddings/xlnet_embeddings.py +4 -18
  122. sparknlp/annotator/er/entity_ruler.py +37 -23
  123. sparknlp/annotator/keyword_extraction/yake_keyword_extraction.py +2 -3
  124. sparknlp/annotator/ld_dl/language_detector_dl.py +2 -2
  125. sparknlp/annotator/lemmatizer.py +3 -4
  126. sparknlp/annotator/matcher/date_matcher.py +35 -3
  127. sparknlp/annotator/matcher/multi_date_matcher.py +1 -2
  128. sparknlp/annotator/matcher/regex_matcher.py +3 -3
  129. sparknlp/annotator/matcher/text_matcher.py +2 -3
  130. sparknlp/annotator/n_gram_generator.py +1 -2
  131. sparknlp/annotator/ner/__init__.py +3 -1
  132. sparknlp/annotator/ner/ner_converter.py +18 -0
  133. sparknlp/annotator/ner/ner_crf.py +4 -5
  134. sparknlp/annotator/ner/ner_dl.py +10 -5
  135. sparknlp/annotator/ner/ner_dl_graph_checker.py +293 -0
  136. sparknlp/annotator/ner/ner_overwriter.py +2 -2
  137. sparknlp/annotator/ner/zero_shot_ner_model.py +173 -0
  138. sparknlp/annotator/normalizer.py +2 -2
  139. sparknlp/annotator/openai/__init__.py +16 -0
  140. sparknlp/annotator/openai/openai_completion.py +349 -0
  141. sparknlp/annotator/openai/openai_embeddings.py +106 -0
  142. sparknlp/annotator/pos/perceptron.py +6 -7
  143. sparknlp/annotator/sentence/sentence_detector.py +2 -2
  144. sparknlp/annotator/sentence/sentence_detector_dl.py +3 -3
  145. sparknlp/annotator/sentiment/sentiment_detector.py +4 -5
  146. sparknlp/annotator/sentiment/vivekn_sentiment.py +4 -5
  147. sparknlp/annotator/seq2seq/__init__.py +17 -0
  148. sparknlp/annotator/seq2seq/auto_gguf_model.py +304 -0
  149. sparknlp/annotator/seq2seq/auto_gguf_reranker.py +334 -0
  150. sparknlp/annotator/seq2seq/auto_gguf_vision_model.py +336 -0
  151. sparknlp/annotator/seq2seq/bart_transformer.py +420 -0
  152. sparknlp/annotator/seq2seq/cohere_transformer.py +357 -0
  153. sparknlp/annotator/seq2seq/cpm_transformer.py +321 -0
  154. sparknlp/annotator/seq2seq/gpt2_transformer.py +1 -1
  155. sparknlp/annotator/seq2seq/llama2_transformer.py +343 -0
  156. sparknlp/annotator/seq2seq/llama3_transformer.py +381 -0
  157. sparknlp/annotator/seq2seq/m2m100_transformer.py +392 -0
  158. sparknlp/annotator/seq2seq/marian_transformer.py +124 -3
  159. sparknlp/annotator/seq2seq/mistral_transformer.py +348 -0
  160. sparknlp/annotator/seq2seq/nllb_transformer.py +420 -0
  161. sparknlp/annotator/seq2seq/olmo_transformer.py +326 -0
  162. sparknlp/annotator/seq2seq/phi2_transformer.py +326 -0
  163. sparknlp/annotator/seq2seq/phi3_transformer.py +330 -0
  164. sparknlp/annotator/seq2seq/phi4_transformer.py +387 -0
  165. sparknlp/annotator/seq2seq/qwen_transformer.py +340 -0
  166. sparknlp/annotator/seq2seq/starcoder_transformer.py +335 -0
  167. sparknlp/annotator/seq2seq/t5_transformer.py +54 -4
  168. sparknlp/annotator/similarity/__init__.py +0 -0
  169. sparknlp/annotator/similarity/document_similarity_ranker.py +379 -0
  170. sparknlp/annotator/spell_check/context_spell_checker.py +116 -17
  171. sparknlp/annotator/spell_check/norvig_sweeting.py +3 -6
  172. sparknlp/annotator/spell_check/symmetric_delete.py +1 -1
  173. sparknlp/annotator/stemmer.py +2 -3
  174. sparknlp/annotator/stop_words_cleaner.py +3 -4
  175. sparknlp/annotator/tf_ner_dl_graph_builder.py +1 -1
  176. sparknlp/annotator/token/__init__.py +0 -1
  177. sparknlp/annotator/token/recursive_tokenizer.py +2 -3
  178. sparknlp/annotator/token/tokenizer.py +2 -3
  179. sparknlp/annotator/ws/word_segmenter.py +35 -10
  180. sparknlp/base/__init__.py +2 -3
  181. sparknlp/base/doc2_chunk.py +0 -3
  182. sparknlp/base/document_assembler.py +5 -5
  183. sparknlp/base/embeddings_finisher.py +14 -2
  184. sparknlp/base/finisher.py +15 -4
  185. sparknlp/base/gguf_ranking_finisher.py +234 -0
  186. sparknlp/base/image_assembler.py +69 -0
  187. sparknlp/base/light_pipeline.py +53 -21
  188. sparknlp/base/multi_document_assembler.py +9 -13
  189. sparknlp/base/prompt_assembler.py +207 -0
  190. sparknlp/base/token_assembler.py +1 -2
  191. sparknlp/common/__init__.py +2 -0
  192. sparknlp/common/annotator_type.py +1 -0
  193. sparknlp/common/completion_post_processing.py +37 -0
  194. sparknlp/common/match_strategy.py +33 -0
  195. sparknlp/common/properties.py +914 -9
  196. sparknlp/internal/__init__.py +841 -116
  197. sparknlp/internal/annotator_java_ml.py +1 -1
  198. sparknlp/internal/annotator_transformer.py +3 -0
  199. sparknlp/logging/comet.py +2 -2
  200. sparknlp/partition/__init__.py +16 -0
  201. sparknlp/partition/partition.py +244 -0
  202. sparknlp/partition/partition_properties.py +902 -0
  203. sparknlp/partition/partition_transformer.py +200 -0
  204. sparknlp/pretrained/pretrained_pipeline.py +1 -1
  205. sparknlp/pretrained/resource_downloader.py +126 -2
  206. sparknlp/reader/__init__.py +15 -0
  207. sparknlp/reader/enums.py +19 -0
  208. sparknlp/reader/pdf_to_text.py +190 -0
  209. sparknlp/reader/reader2doc.py +124 -0
  210. sparknlp/reader/reader2image.py +136 -0
  211. sparknlp/reader/reader2table.py +44 -0
  212. sparknlp/reader/reader_assembler.py +159 -0
  213. sparknlp/reader/sparknlp_reader.py +461 -0
  214. sparknlp/training/__init__.py +1 -0
  215. sparknlp/training/conll.py +8 -2
  216. sparknlp/training/spacy_to_annotation.py +57 -0
  217. sparknlp/util.py +26 -0
  218. spark_nlp-4.2.6.dist-info/METADATA +0 -1256
  219. spark_nlp-4.2.6.dist-info/RECORD +0 -196
  220. {spark_nlp-4.2.6.dist-info → spark_nlp-6.2.1.dist-info}/top_level.txt +0 -0
  221. /sparknlp/annotator/{token/token2_chunk.py → token2_chunk.py} +0 -0
@@ -0,0 +1,349 @@
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
+ class OpenAICompletion(AnnotatorModel):
18
+ """Transformer that makes a request for OpenAI Completion API for each executor.
19
+
20
+ See OpenAI API Doc: https://platform.openai.com/docs/api-reference/completions/create for reference
21
+
22
+ ====================== ======================
23
+ Input Annotation types Output Annotation type
24
+ ====================== ======================
25
+ ``DOCUMENT`` ``DOCUMENT``
26
+ ====================== ======================
27
+
28
+ Parameters
29
+ ----------
30
+ model
31
+ ID of the OpenAI model to use
32
+ suffix
33
+ The suffix that comes after a completion of inserted text
34
+ maxTokens
35
+ The maximum number of tokens to generate in the completion.
36
+ temperature
37
+ What sampling temperature to use, between 0 and 2
38
+ topP
39
+ An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass
40
+ numberOfCompletions
41
+ How many completions to generate for each prompt.
42
+ logprobs
43
+ Include the log probabilities on the logprobs most likely tokens, as well the chosen tokens.
44
+ echo
45
+ Echo back the prompt in addition to the completion
46
+ stop
47
+ Up to 4 sequences where the API will stop generating further tokens.
48
+ presencePenalty
49
+ 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.
50
+ frequencyPenalty
51
+ 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.
52
+ bestOf
53
+ Generates best_of completions server-side and returns the `best` (the one with the highest log probability per token).
54
+ logitBias
55
+ Modify the likelihood of specified tokens appearing in the completion.
56
+ user
57
+ A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
58
+
59
+ Examples
60
+ --------
61
+ >>> import sparknlp
62
+ >>> from sparknlp.base import *
63
+ >>> from sparknlp.annotator import *
64
+ >>> from sparknlp.common import *
65
+ >>> from pyspark.ml import Pipeline
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
+ name = "OpenAICompletion"
92
+
93
+ inputAnnotatorTypes = [AnnotatorType.DOCUMENT]
94
+
95
+ outputAnnotatorType = AnnotatorType.DOCUMENT
96
+
97
+ model = Param(Params._dummy(),
98
+ "model",
99
+ "ID of the OpenAI model to use",
100
+ typeConverter=TypeConverters.toString)
101
+
102
+ suffix = Param(Params._dummy(),
103
+ "suffix",
104
+ "The suffix that comes after a completion of inserted text.",
105
+ typeConverter=TypeConverters.toString)
106
+
107
+ maxTokens = Param(Params._dummy(),
108
+ "maxTokens",
109
+ "The maximum number of tokens to generate in the completion.",
110
+ typeConverter=TypeConverters.toInt)
111
+
112
+ temperature = Param(Params._dummy(),
113
+ "temperature",
114
+ "What sampling temperature to use, between 0 and 2",
115
+ typeConverter=TypeConverters.toFloat)
116
+
117
+ topP = Param(Params._dummy(),
118
+ "topP",
119
+ "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass",
120
+ typeConverter=TypeConverters.toFloat)
121
+
122
+ numberOfCompletions = Param(Params._dummy(),
123
+ "numberOfCompletions",
124
+ "How many completions to generate for each prompt.",
125
+ typeConverter=TypeConverters.toInt)
126
+
127
+ logprobs = Param(Params._dummy(),
128
+ "logprobs",
129
+ "Include the log probabilities on the logprobs most likely tokens, as well the chosen tokens.",
130
+ typeConverter=TypeConverters.toInt)
131
+
132
+ echo = Param(Params._dummy(),
133
+ "echo",
134
+ "Echo back the prompt in addition to the completion",
135
+ typeConverter=TypeConverters.toBoolean)
136
+
137
+ stop = Param(Params._dummy(),
138
+ "stop",
139
+ "Up to 4 sequences where the API will stop generating further tokens.",
140
+ typeConverter=TypeConverters.toListString)
141
+
142
+ presencePenalty = Param(Params._dummy(),
143
+ "presencePenalty",
144
+ "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.",
145
+ typeConverter=TypeConverters.toFloat)
146
+
147
+ frequencyPenalty = Param(Params._dummy(),
148
+ "frequencyPenalty",
149
+ "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.",
150
+ typeConverter=TypeConverters.toFloat)
151
+
152
+ bestOf = Param(Params._dummy(),
153
+ "bestOf",
154
+ "Generates best_of completions server-side and returns the `best` (the one with the highest log probability per token).",
155
+ typeConverter=TypeConverters.toInt)
156
+
157
+ logitBias = Param(Params._dummy(),
158
+ "logitBias",
159
+ "Modify the likelihood of specified tokens appearing in the completion.",
160
+ typeConverter=TypeConverters.identity)
161
+
162
+ user = Param(Params._dummy(),
163
+ "user",
164
+ "A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.",
165
+ typeConverter=TypeConverters.toString)
166
+
167
+ def setModel(self, value):
168
+ """Sets model ID of the OpenAI model to use
169
+
170
+ Parameters
171
+ ----------
172
+ value : str
173
+ ID of the OpenAI model to use
174
+ """
175
+ return self._set(model=value)
176
+
177
+ def setSuffix(self, value):
178
+ """Sets the suffix that comes after a completion of inserted text.
179
+
180
+ Parameters
181
+ ----------
182
+ value : str
183
+ The suffix that comes after a completion of inserted text.
184
+ """
185
+ return self._set(suffix=value)
186
+
187
+ def setMaxTokens(self, value):
188
+ """Sets the maximum number of tokens to generate in the completion.
189
+ The token count of your prompt plus max_tokens cannot exceed the model's context length.
190
+
191
+ Parameters
192
+ ----------
193
+ value : int
194
+ The maximum number of tokens to generate in the completion.
195
+ """
196
+ return self._set(maxTokens=value)
197
+
198
+ def setTemperature(self, value):
199
+ """Sets what sampling temperature to use, between 0 and 2.
200
+ Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
201
+ We generally recommend altering this or top_p but not both.
202
+
203
+ Parameters
204
+ ----------
205
+ value : float
206
+ What sampling temperature to use, between 0 and 2
207
+ """
208
+ return self._set(temperature=value)
209
+
210
+ def setTopP(self, value):
211
+ """Sets An alternative to sampling with temperature, called nucleus sampling.
212
+ Where the model considers the results of the tokens with top_p probability mass.
213
+ So 0.1 means only the tokens comprising the top 10% probability mass are considered.
214
+ We generally recommend altering this or temperature but not both.
215
+
216
+ Parameters
217
+ ----------
218
+ value : float
219
+ An alternative to sampling with temperature, called nucleus sampling, where the model considers the results
220
+ of the tokens with top_p probability mass
221
+ """
222
+ return self._set(topP=value)
223
+
224
+ def setNumberOfCompletions(self, value):
225
+ """Sets how many completions to generate for each prompt.
226
+
227
+ Note: Because this parameter generates many completions, it can quickly consume your token quota.
228
+ Use carefully and ensure that you have reasonable settings for max_tokens and stop.
229
+
230
+ Parameters
231
+ ----------
232
+ value : int
233
+ How many completions to generate for each prompt.
234
+ """
235
+ return self._set(numberOfCompletions=value)
236
+
237
+ def setLogprobs(self, value):
238
+ """Sets the log probabilities on the logprobs most likely tokens, as well the chosen tokens.
239
+ For example, if logprobs is 5, the API will return a list of the 5 most likely tokens.
240
+ The API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response.
241
+ The maximum value for logprobs is 5.
242
+
243
+ Parameters
244
+ ----------
245
+ value : int
246
+ How many completions to generate for each prompt.
247
+ """
248
+ return self._set(logprobs=value)
249
+
250
+ def setEcho(self, value):
251
+ """Sets echo back the prompt in addition to the completion
252
+
253
+ Parameters
254
+ ----------
255
+ value : str
256
+ Echo back the prompt in addition to the completion
257
+ """
258
+ return self._set(echo=value)
259
+
260
+ def setStop(self, value):
261
+ """Sets Up to 4 sequences where the API will stop generating further tokens.
262
+ The returned text will not contain the stop sequence.
263
+
264
+ Parameters
265
+ ----------
266
+ value : List[str]
267
+ Up to 4 sequences where the API will stop generating further tokens.
268
+ """
269
+ return self._set(stop=value)
270
+
271
+ def setPresencePenalty(self, value):
272
+ """Sets values to penalize new tokens based on whether they appear in the text so far,
273
+ increasing the model's likelihood to talk about new topics.
274
+
275
+ Parameters
276
+ ----------
277
+ value : int
278
+ Number between -2.0 and 2.0.
279
+ Positive values penalize new tokens based on whether they appear in the text so far,
280
+ increasing the model's likelihood to talk about new topics.
281
+ """
282
+ return self._set(presencePenalty=value)
283
+
284
+ def setFrequencyPenalty(self, value):
285
+ """Sets values to penalize new tokens based on their existing frequency in the text so far,
286
+ decreasing the model's likelihood to repeat the same line verbatim.
287
+
288
+ Parameters
289
+ ----------
290
+ value : int
291
+ Number between -2.0 and 2.0.
292
+ Positive values penalize new tokens based on their existing frequency in the text so far,
293
+ decreasing the model's likelihood to repeat the same line verbatim.
294
+ """
295
+ return self._set(frequencyPenalty=value)
296
+
297
+ def setBestOf(self, value):
298
+ """Sets best_of completions server-side and returns the "best" (the one with the highest log probability per token)
299
+
300
+ Parameters
301
+ ----------
302
+ value : int
303
+ Generates best_of completions server-side and returns the "best" (the one with the highest log probability per token).
304
+ Results cannot be streamed.
305
+ 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.
306
+ Note: Because this parameter generates many completions, it can quickly consume your token quota.
307
+ Use carefully and ensure that you have reasonable settings for max_tokens and stop.
308
+ """
309
+ return self._set(bestOf=value)
310
+
311
+ def setLogitBias(self, value):
312
+ """Sets the likelihood of specified tokens appearing in the completion
313
+
314
+ Parameters
315
+ ----------
316
+ value : dict
317
+ Modify the likelihood of specified tokens appearing in the completion.
318
+ Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated
319
+ 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.
320
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|> token from being generated.
321
+ """
322
+ return self._set(logitBias=value)
323
+
324
+ def setUser(self, value):
325
+ """Sets a unique identifier representing your end-user
326
+
327
+ Parameters
328
+ ----------
329
+ value : str
330
+ A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
331
+ """
332
+ return self._set(user=value)
333
+
334
+ @keyword_only
335
+ def __init__(self, classname="com.johnsnowlabs.ml.ai.OpenAICompletion", java_model=None):
336
+ super(OpenAICompletion, self).__init__(
337
+ classname=classname,
338
+ java_model=java_model
339
+ )
340
+ self._setDefault(
341
+ maxTokens=16,
342
+ temperature=1,
343
+ topP=1,
344
+ numberOfCompletions=1,
345
+ echo=False,
346
+ presencePenalty=0,
347
+ frequencyPenalty=0,
348
+ bestOf=1
349
+ )