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,539 @@
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 the AutoGGUFEmbeddings."""
15
+ from sparknlp.common import *
16
+
17
+
18
+ class AutoGGUFEmbeddings(AnnotatorModel, HasBatchedAnnotate):
19
+ """
20
+ Annotator that uses the llama.cpp library to generate text embeddings with large language
21
+ models
22
+
23
+ The type of embedding pooling can be set with the `setPoolingType` method. The default is
24
+ `"MEAN"`. The available options are `"NONE"`, `"MEAN"`, `"CLS"`, and `"LAST"`.
25
+
26
+ Pretrained models can be loaded with :meth:`.pretrained` of the companion
27
+ object:
28
+
29
+ >>> auto_gguf_model = AutoGGUFEmbeddings.pretrained() \\
30
+ ... .setInputCols(["document"]) \\
31
+ ... .setOutputCol("embeddings")
32
+
33
+ The default model is ``"Qwen3_Embedding_0.6B_Q8_0_gguf"``, if no name is provided.
34
+
35
+ For extended examples of usage, see the
36
+ `AutoGGUFEmbeddingsTest <https://github.com/JohnSnowLabs/spark-nlp/tree/master/src/test/scala/com/johnsnowlabs/nlp/embeddings/AutoGGUFEmbeddingsTest.scala>`__
37
+ and the
38
+ `example notebook <https://github.com/JohnSnowLabs/spark-nlp/tree/master/examples/python/llama.cpp/llama.cpp_in_Spark_NLP_AutoGGUFEmbeddings.ipynb>`__.
39
+
40
+ For available pretrained models please see the `Models Hub <https://sparknlp.org/models>`__.
41
+
42
+ ====================== ======================
43
+ Input Annotation types Output Annotation type
44
+ ====================== ======================
45
+ ``DOCUMENT`` ``SENTENCE_EMBEDDINGS``
46
+ ====================== ======================
47
+
48
+ Parameters
49
+ ----------
50
+ nThreads
51
+ Set the number of threads to use during generation
52
+ nThreadsBatch
53
+ Set the number of threads to use during batch and prompt processing
54
+ nCtx
55
+ Set the size of the prompt context
56
+ nBatch
57
+ Set the logical batch size for prompt processing (must be >=32 to use BLAS)
58
+ nUbatch
59
+ Set the physical batch size for prompt processing (must be >=32 to use BLAS)
60
+ nChunks
61
+ Set the maximal number of chunks to process
62
+ nSequences
63
+ Set the number of sequences to decode
64
+ nGpuLayers
65
+ Set the number of layers to store in VRAM (-1 - use default)
66
+ gpuSplitMode
67
+ Set how to split the model across GPUs
68
+ mainGpu
69
+ Set the main GPU that is used for scratch and small tensors.
70
+ tensorSplit
71
+ Set how split tensors should be distributed across GPUs
72
+ grpAttnN
73
+ Set the group-attention factor
74
+ grpAttnW
75
+ Set the group-attention width
76
+ ropeFreqBase
77
+ Set the RoPE base frequency, used by NTK-aware scaling
78
+ ropeFreqScale
79
+ Set the RoPE frequency scaling factor, expands context by a factor of 1/N
80
+ yarnExtFactor
81
+ Set the YaRN extrapolation mix factor
82
+ yarnAttnFactor
83
+ Set the YaRN scale sqrt(t) or attention magnitude
84
+ yarnBetaFast
85
+ Set the YaRN low correction dim or beta
86
+ yarnBetaSlow
87
+ Set the YaRN high correction dim or alpha
88
+ yarnOrigCtx
89
+ Set the YaRN original context size of model
90
+ defragmentationThreshold
91
+ Set the KV cache defragmentation threshold
92
+ numaStrategy
93
+ Set optimization strategies that help on some NUMA systems (if available)
94
+ ropeScalingType
95
+ Set the RoPE frequency scaling method, defaults to linear unless specified by the model
96
+ poolingType
97
+ Set the pooling type for embeddings, use model default if unspecified
98
+ flashAttention
99
+ Whether to enable Flash Attention
100
+ useMmap
101
+ Whether to use memory-map model (faster load but may increase pageouts if not using mlock)
102
+ useMlock
103
+ Whether to force the system to keep model in RAM rather than swapping or compressing
104
+ noKvOffload
105
+ Whether to disable KV offload
106
+
107
+ Notes
108
+ -----
109
+ To use GPU inference with this annotator, make sure to use the Spark NLP GPU package and set
110
+ the number of GPU layers with the `setNGpuLayers` method.
111
+
112
+ When using larger models, we recommend adjusting GPU usage with `setNCtx` and `setNGpuLayers`
113
+ according to your hardware to avoid out-of-memory errors.
114
+
115
+ Examples
116
+ --------
117
+ >>> import sparknlp
118
+ >>> from sparknlp.base import *
119
+ >>> from sparknlp.annotator import *
120
+ >>> from pyspark.ml import Pipeline
121
+ >>> document = DocumentAssembler() \\
122
+ ... .setInputCol("text") \\
123
+ ... .setOutputCol("document")
124
+ >>> autoGGUFEmbeddings = AutoGGUFEmbeddings.pretrained() \\
125
+ ... .setInputCols(["document"]) \\
126
+ ... .setOutputCol("embeddings") \\
127
+ ... .setBatchSize(4) \\
128
+ ... .setNGpuLayers(99) \\
129
+ ... .setPoolingType("MEAN")
130
+ >>> pipeline = Pipeline().setStages([document, autoGGUFEmbeddings])
131
+ >>> data = spark.createDataFrame([["The moons of Jupiter are 77 in total, with 79 confirmed natural satellites and 2 man-made ones."]]).toDF("text")
132
+ >>> result = pipeline.fit(data).transform(data)
133
+ >>> result.select("embeddings.embeddings").show(truncate = False)
134
+ +--------------------------------------------------------------------------------+
135
+ | embeddings|
136
+ +--------------------------------------------------------------------------------+
137
+ |[[-0.034486726, 0.07770534, -0.15982522, -0.017873349, 0.013914132, 0.0365736...|
138
+ +--------------------------------------------------------------------------------+
139
+ """
140
+
141
+ name = "AutoGGUFEmbeddings"
142
+ inputAnnotatorTypes = [AnnotatorType.DOCUMENT]
143
+ outputAnnotatorType = AnnotatorType.DOCUMENT
144
+
145
+ # -------- MODEl PARAMETERS --------
146
+ nThreads = Param(
147
+ Params._dummy(),
148
+ "nThreads",
149
+ "Set the number of threads to use during generation",
150
+ typeConverter=TypeConverters.toInt,
151
+ )
152
+ nThreadsBatch = Param(
153
+ Params._dummy(),
154
+ "nThreadsBatch",
155
+ "Set the number of threads to use during batch and prompt processing",
156
+ typeConverter=TypeConverters.toInt,
157
+ )
158
+ nCtx = Param(
159
+ Params._dummy(),
160
+ "nCtx",
161
+ "Set the size of the prompt context",
162
+ typeConverter=TypeConverters.toInt,
163
+ )
164
+ nBatch = Param(
165
+ Params._dummy(),
166
+ "nBatch",
167
+ "Set the logical batch size for prompt processing (must be >=32 to use BLAS)",
168
+ typeConverter=TypeConverters.toInt,
169
+ )
170
+ nUbatch = Param(
171
+ Params._dummy(),
172
+ "nUbatch",
173
+ "Set the physical batch size for prompt processing (must be >=32 to use BLAS)",
174
+ typeConverter=TypeConverters.toInt,
175
+ )
176
+ nChunks = Param(
177
+ Params._dummy(),
178
+ "nChunks",
179
+ "Set the maximal number of chunks to process",
180
+ typeConverter=TypeConverters.toInt,
181
+ )
182
+ nSequences = Param(
183
+ Params._dummy(),
184
+ "nSequences",
185
+ "Set the number of sequences to decode",
186
+ typeConverter=TypeConverters.toInt,
187
+ )
188
+ nGpuLayers = Param(
189
+ Params._dummy(),
190
+ "nGpuLayers",
191
+ "Set the number of layers to store in VRAM (-1 - use default)",
192
+ typeConverter=TypeConverters.toInt,
193
+ )
194
+ # Set how to split the model across GPUs
195
+ #
196
+ # - NONE: No GPU split
197
+ # - LAYER: Split the model across GPUs by layer
198
+ # - ROW: Split the model across GPUs by rows
199
+ gpuSplitMode = Param(
200
+ Params._dummy(),
201
+ "gpuSplitMode",
202
+ "Set how to split the model across GPUs",
203
+ typeConverter=TypeConverters.toString,
204
+ )
205
+ mainGpu = Param(
206
+ Params._dummy(),
207
+ "mainGpu",
208
+ "Set the main GPU that is used for scratch and small tensors.",
209
+ typeConverter=TypeConverters.toInt,
210
+ )
211
+ tensorSplit = Param(
212
+ Params._dummy(),
213
+ "tensorSplit",
214
+ "Set how split tensors should be distributed across GPUs",
215
+ typeConverter=TypeConverters.toListFloat,
216
+ )
217
+ grpAttnN = Param(
218
+ Params._dummy(),
219
+ "grpAttnN",
220
+ "Set the group-attention factor",
221
+ typeConverter=TypeConverters.toInt,
222
+ )
223
+ grpAttnW = Param(
224
+ Params._dummy(),
225
+ "grpAttnW",
226
+ "Set the group-attention width",
227
+ typeConverter=TypeConverters.toInt,
228
+ )
229
+ ropeFreqBase = Param(
230
+ Params._dummy(),
231
+ "ropeFreqBase",
232
+ "Set the RoPE base frequency, used by NTK-aware scaling",
233
+ typeConverter=TypeConverters.toFloat,
234
+ )
235
+ ropeFreqScale = Param(
236
+ Params._dummy(),
237
+ "ropeFreqScale",
238
+ "Set the RoPE frequency scaling factor, expands context by a factor of 1/N",
239
+ typeConverter=TypeConverters.toFloat,
240
+ )
241
+ yarnExtFactor = Param(
242
+ Params._dummy(),
243
+ "yarnExtFactor",
244
+ "Set the YaRN extrapolation mix factor",
245
+ typeConverter=TypeConverters.toFloat,
246
+ )
247
+ yarnAttnFactor = Param(
248
+ Params._dummy(),
249
+ "yarnAttnFactor",
250
+ "Set the YaRN scale sqrt(t) or attention magnitude",
251
+ typeConverter=TypeConverters.toFloat,
252
+ )
253
+ yarnBetaFast = Param(
254
+ Params._dummy(),
255
+ "yarnBetaFast",
256
+ "Set the YaRN low correction dim or beta",
257
+ typeConverter=TypeConverters.toFloat,
258
+ )
259
+ yarnBetaSlow = Param(
260
+ Params._dummy(),
261
+ "yarnBetaSlow",
262
+ "Set the YaRN high correction dim or alpha",
263
+ typeConverter=TypeConverters.toFloat,
264
+ )
265
+ yarnOrigCtx = Param(
266
+ Params._dummy(),
267
+ "yarnOrigCtx",
268
+ "Set the YaRN original context size of model",
269
+ typeConverter=TypeConverters.toInt,
270
+ )
271
+ defragmentationThreshold = Param(
272
+ Params._dummy(),
273
+ "defragmentationThreshold",
274
+ "Set the KV cache defragmentation threshold",
275
+ typeConverter=TypeConverters.toFloat,
276
+ )
277
+ # Set optimization strategies that help on some NUMA systems (if available)
278
+ #
279
+ # Available Strategies:
280
+ #
281
+ # - DISABLED: No NUMA optimizations
282
+ # - DISTRIBUTE: Spread execution evenly over all
283
+ # - ISOLATE: Only spawn threads on CPUs on the node that execution started on
284
+ # - NUMA_CTL: Use the CPU map provided by numactl
285
+ # - MIRROR: Mirrors the model across NUMA nodes
286
+ numaStrategy = Param(
287
+ Params._dummy(),
288
+ "numaStrategy",
289
+ "Set optimization strategies that help on some NUMA systems (if available)",
290
+ typeConverter=TypeConverters.toString,
291
+ )
292
+ # Set the RoPE frequency scaling method, defaults to linear unless specified by the model.
293
+ #
294
+ # - UNSPECIFIED: Don't use any scaling
295
+ # - LINEAR: Linear scaling
296
+ # - YARN: YaRN RoPE scaling
297
+ ropeScalingType = Param(
298
+ Params._dummy(),
299
+ "ropeScalingType",
300
+ "Set the RoPE frequency scaling method, defaults to linear unless specified by the model",
301
+ typeConverter=TypeConverters.toString,
302
+ )
303
+ # Set the pooling type for embeddings, use model default if unspecified
304
+ #
305
+ # - 0 UNSPECIFIED: Don't use any pooling
306
+ # - 1 MEAN: Mean Pooling
307
+ # - 2 CLS: CLS Pooling
308
+ poolingType = Param(
309
+ Params._dummy(),
310
+ "poolingType",
311
+ "Set the pooling type for embeddings, use model default if unspecified",
312
+ typeConverter=TypeConverters.toString,
313
+ )
314
+ flashAttention = Param(
315
+ Params._dummy(),
316
+ "flashAttention",
317
+ "Whether to enable Flash Attention",
318
+ typeConverter=TypeConverters.toBoolean,
319
+ )
320
+ useMmap = Param(
321
+ Params._dummy(),
322
+ "useMmap",
323
+ "Whether to use memory-map model (faster load but may increase pageouts if not using mlock)",
324
+ typeConverter=TypeConverters.toBoolean,
325
+ )
326
+ useMlock = Param(
327
+ Params._dummy(),
328
+ "useMlock",
329
+ "Whether to force the system to keep model in RAM rather than swapping or compressing",
330
+ typeConverter=TypeConverters.toBoolean,
331
+ )
332
+ noKvOffload = Param(
333
+ Params._dummy(),
334
+ "noKvOffload",
335
+ "Whether to disable KV offload",
336
+ typeConverter=TypeConverters.toBoolean,
337
+ )
338
+
339
+ # -------- MODEL SETTERS --------
340
+ def setNThreads(self, nThreads: int):
341
+ """Set the number of threads to use during generation"""
342
+ return self._set(nThreads=nThreads)
343
+
344
+ def setNThreadsBatch(self, nThreadsBatch: int):
345
+ """Set the number of threads to use during batch and prompt processing"""
346
+ return self._set(nThreadsBatch=nThreadsBatch)
347
+
348
+ def setNCtx(self, nCtx: int):
349
+ """Set the size of the prompt context"""
350
+ return self._set(nCtx=nCtx)
351
+
352
+ def setNBatch(self, nBatch: int):
353
+ """Set the logical batch size for prompt processing (must be >=32 to use BLAS)"""
354
+ return self._set(nBatch=nBatch)
355
+
356
+ def setNUbatch(self, nUbatch: int):
357
+ """Set the physical batch size for prompt processing (must be >=32 to use BLAS)"""
358
+ return self._set(nUbatch=nUbatch)
359
+
360
+ def setNChunks(self, nChunks: int):
361
+ """Set the maximal number of chunks to process"""
362
+ return self._set(nChunks=nChunks)
363
+
364
+ def setNSequences(self, nSequences: int):
365
+ """Set the number of sequences to decode"""
366
+ return self._set(nSequences=nSequences)
367
+
368
+ def setNGpuLayers(self, nGpuLayers: int):
369
+ """Set the number of layers to store in VRAM (-1 - use default)"""
370
+ return self._set(nGpuLayers=nGpuLayers)
371
+
372
+ def setGpuSplitMode(self, gpuSplitMode: str):
373
+ """Set how to split the model across GPUs"""
374
+ return self._set(gpuSplitMode=gpuSplitMode)
375
+
376
+ def setMainGpu(self, mainGpu: int):
377
+ """Set the main GPU that is used for scratch and small tensors."""
378
+ return self._set(mainGpu=mainGpu)
379
+
380
+ def setTensorSplit(self, tensorSplit: List[float]):
381
+ """Set how split tensors should be distributed across GPUs"""
382
+ return self._set(tensorSplit=tensorSplit)
383
+
384
+ def setGrpAttnN(self, grpAttnN: int):
385
+ """Set the group-attention factor"""
386
+ return self._set(grpAttnN=grpAttnN)
387
+
388
+ def setGrpAttnW(self, grpAttnW: int):
389
+ """Set the group-attention width"""
390
+ return self._set(grpAttnW=grpAttnW)
391
+
392
+ def setRopeFreqBase(self, ropeFreqBase: float):
393
+ """Set the RoPE base frequency, used by NTK-aware scaling"""
394
+ return self._set(ropeFreqBase=ropeFreqBase)
395
+
396
+ def setRopeFreqScale(self, ropeFreqScale: float):
397
+ """Set the RoPE frequency scaling factor, expands context by a factor of 1/N"""
398
+ return self._set(ropeFreqScale=ropeFreqScale)
399
+
400
+ def setYarnExtFactor(self, yarnExtFactor: float):
401
+ """Set the YaRN extrapolation mix factor"""
402
+ return self._set(yarnExtFactor=yarnExtFactor)
403
+
404
+ def setYarnAttnFactor(self, yarnAttnFactor: float):
405
+ """Set the YaRN scale sqrt(t) or attention magnitude"""
406
+ return self._set(yarnAttnFactor=yarnAttnFactor)
407
+
408
+ def setYarnBetaFast(self, yarnBetaFast: float):
409
+ """Set the YaRN low correction dim or beta"""
410
+ return self._set(yarnBetaFast=yarnBetaFast)
411
+
412
+ def setYarnBetaSlow(self, yarnBetaSlow: float):
413
+ """Set the YaRN high correction dim or alpha"""
414
+ return self._set(yarnBetaSlow=yarnBetaSlow)
415
+
416
+ def setYarnOrigCtx(self, yarnOrigCtx: int):
417
+ """Set the YaRN original context size of model"""
418
+ return self._set(yarnOrigCtx=yarnOrigCtx)
419
+
420
+ def setDefragmentationThreshold(self, defragmentationThreshold: float):
421
+ """Set the KV cache defragmentation threshold"""
422
+ return self._set(defragmentationThreshold=defragmentationThreshold)
423
+
424
+ def setNumaStrategy(self, numaStrategy: str):
425
+ """Set optimization strategies that help on some NUMA systems (if available)"""
426
+ numaUpper = numaStrategy.upper()
427
+ numaStrategies = ["DISABLED", "DISTRIBUTE", "ISOLATE", "NUMA_CTL", "MIRROR"]
428
+ if numaUpper not in numaStrategies:
429
+ raise ValueError(
430
+ f"Invalid NUMA strategy: {numaUpper}. "
431
+ + f"Valid values are: {numaStrategies}"
432
+ )
433
+ return self._set(numaStrategy=numaStrategy)
434
+
435
+ def setRopeScalingType(self, ropeScalingType: str):
436
+ """Set the RoPE frequency scaling method, defaults to linear unless specified by the model"""
437
+ return self._set(ropeScalingType=ropeScalingType)
438
+
439
+ def setPoolingType(self, poolingType: str):
440
+ """Set the pooling type for embeddings, use model default if unspecified"""
441
+ poolingTypeUpper = poolingType.upper()
442
+ poolingTypes = ["NONE", "MEAN", "CLS", "LAST"]
443
+ if poolingTypeUpper not in poolingTypes:
444
+ raise ValueError(
445
+ f"Invalid pooling type: {poolingType}. "
446
+ + f"Valid values are: {poolingTypes}"
447
+ )
448
+ return self._set(poolingType=poolingType)
449
+
450
+ def setFlashAttention(self, flashAttention: bool):
451
+ """Whether to enable Flash Attention"""
452
+ return self._set(flashAttention=flashAttention)
453
+
454
+ def setUseMmap(self, useMmap: bool):
455
+ """Whether to use memory-map model (faster load but may increase pageouts if not using mlock)"""
456
+ return self._set(useMmap=useMmap)
457
+
458
+ def setUseMlock(self, useMlock: bool):
459
+ """Whether to force the system to keep model in RAM rather than swapping or compressing"""
460
+ return self._set(useMlock=useMlock)
461
+
462
+ def setNoKvOffload(self, noKvOffload: bool):
463
+ """Whether to disable KV offload"""
464
+ return self._set(noKvOffload=noKvOffload)
465
+
466
+ def setNParallel(self, nParallel: int):
467
+ """Sets the number of parallel processes for decoding. This is an alias for `setBatchSize`."""
468
+ return self.setBatchSize(nParallel)
469
+
470
+ def getMetadata(self):
471
+ """Gets the metadata of the model"""
472
+ return self._call_java("getMetadata")
473
+
474
+ @keyword_only
475
+ def __init__(
476
+ self,
477
+ classname="com.johnsnowlabs.nlp.embeddings.AutoGGUFEmbeddings",
478
+ java_model=None,
479
+ ):
480
+ super(AutoGGUFEmbeddings, self).__init__(
481
+ classname=classname, java_model=java_model
482
+ )
483
+ self._setDefault(
484
+ nCtx=4096,
485
+ nBatch=512,
486
+ poolingType="MEAN",
487
+ nGpuLayers=99,
488
+ )
489
+
490
+ @staticmethod
491
+ def loadSavedModel(folder, spark_session):
492
+ """Loads a locally saved model.
493
+
494
+ Parameters
495
+ ----------
496
+ folder : str
497
+ Folder of the saved model
498
+ spark_session : pyspark.sql.SparkSession
499
+ The current SparkSession
500
+
501
+ Returns
502
+ -------
503
+ AutoGGUFEmbeddings
504
+ The restored model
505
+ """
506
+ from sparknlp.internal import _AutoGGUFEmbeddingsLoader
507
+
508
+ jModel = _AutoGGUFEmbeddingsLoader(folder, spark_session._jsparkSession)._java_obj
509
+ return AutoGGUFEmbeddings(java_model=jModel)
510
+
511
+ @staticmethod
512
+ def pretrained(name="Qwen3_Embedding_0.6B_Q8_0_gguf", lang="en", remote_loc=None):
513
+ """Downloads and loads a pretrained model.
514
+
515
+ Parameters
516
+ ----------
517
+ name : str, optional
518
+ Name of the pretrained model, by default "Qwen3_Embedding_0.6B_Q8_0_gguf"
519
+ lang : str, optional
520
+ Language of the pretrained model, by default "en"
521
+ remote_loc : str, optional
522
+ Optional remote address of the resource, by default None. Will use
523
+ Spark NLPs repositories otherwise.
524
+
525
+ Returns
526
+ -------
527
+ AutoGGUFEmbeddings
528
+ The restored model
529
+ """
530
+ from sparknlp.pretrained import ResourceDownloader
531
+
532
+ return ResourceDownloader.downloadModel(
533
+ AutoGGUFEmbeddings, name, lang, remote_loc
534
+ )
535
+
536
+ def close(self):
537
+ """Closes the llama.cpp model backend freeing resources. The model is reloaded when used again.
538
+ """
539
+ self._java_obj.close()
@@ -20,7 +20,8 @@ class BertEmbeddings(AnnotatorModel,
20
20
  HasEmbeddingsProperties,
21
21
  HasCaseSensitiveProperties,
22
22
  HasStorageRef,
23
- HasBatchedAnnotate):
23
+ HasBatchedAnnotate,
24
+ HasMaxSentenceLengthLimit):
24
25
  """Token-level embeddings using BERT.
25
26
 
26
27
  BERT (Bidirectional Encoder Representations from Transformers) provides
@@ -38,10 +39,10 @@ class BertEmbeddings(AnnotatorModel,
38
39
  The default model is ``"small_bert_L2_768"``, if no name is provided.
39
40
 
40
41
  For available pretrained models please see the
41
- `Models Hub <https://nlp.johnsnowlabs.com/models?task=Embeddings>`__.
42
+ `Models Hub <https://sparknlp.org/models?task=Embeddings>`__.
42
43
 
43
- For extended examples of usage, see the `Spark NLP Workshop
44
- <https://github.com/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/blogposts/3.NER_with_BERT.ipynb>`__.
44
+ For extended examples of usage, see the `Examples
45
+ <https://github.com/JohnSnowLabs/spark-nlp/blob/master/examples/python/training/english/dl-ner/ner_bert.ipynb>`__.
45
46
  To see which models are compatible and how to import them see
46
47
  `Import Transformers into Spark NLP 🚀
47
48
  <https://github.com/JohnSnowLabs/spark-nlp/discussions/5669>`_.
@@ -134,11 +135,6 @@ class BertEmbeddings(AnnotatorModel,
134
135
 
135
136
  outputAnnotatorType = AnnotatorType.WORD_EMBEDDINGS
136
137
 
137
- maxSentenceLength = Param(Params._dummy(),
138
- "maxSentenceLength",
139
- "Max sentence length to process",
140
- typeConverter=TypeConverters.toInt)
141
-
142
138
  configProtoBytes = Param(Params._dummy(),
143
139
  "configProtoBytes",
144
140
  "ConfigProto from tensorflow, serialized into byte array. Get with config_proto.SerializeToString()",
@@ -154,16 +150,6 @@ class BertEmbeddings(AnnotatorModel,
154
150
  """
155
151
  return self._set(configProtoBytes=b)
156
152
 
157
- def setMaxSentenceLength(self, value):
158
- """Sets max sentence length to process.
159
-
160
- Parameters
161
- ----------
162
- value : int
163
- Max sentence length to process
164
- """
165
- return self._set(maxSentenceLength=value)
166
-
167
153
  @keyword_only
168
154
  def __init__(self, classname="com.johnsnowlabs.nlp.embeddings.BertEmbeddings", java_model=None):
169
155
  super(BertEmbeddings, self).__init__(
@@ -178,7 +164,7 @@ class BertEmbeddings(AnnotatorModel,
178
164
  )
179
165
 
180
166
  @staticmethod
181
- def loadSavedModel(folder, spark_session):
167
+ def loadSavedModel(folder, spark_session, use_openvino=False):
182
168
  """Loads a locally saved model.
183
169
 
184
170
  Parameters
@@ -187,6 +173,8 @@ class BertEmbeddings(AnnotatorModel,
187
173
  Folder of the saved model
188
174
  spark_session : pyspark.sql.SparkSession
189
175
  The current SparkSession
176
+ use_openvino: bool
177
+ Use OpenVINO backend
190
178
 
191
179
  Returns
192
180
  -------
@@ -194,7 +182,7 @@ class BertEmbeddings(AnnotatorModel,
194
182
  The restored model
195
183
  """
196
184
  from sparknlp.internal import _BertLoader
197
- jModel = _BertLoader(folder, spark_session._jsparkSession)._java_obj
185
+ jModel = _BertLoader(folder, spark_session._jsparkSession, use_openvino)._java_obj
198
186
  return BertEmbeddings(java_model=jModel)
199
187
 
200
188
  @staticmethod
@@ -218,4 +206,3 @@ class BertEmbeddings(AnnotatorModel,
218
206
  """
219
207
  from sparknlp.pretrained import ResourceDownloader
220
208
  return ResourceDownloader.downloadModel(BertEmbeddings, name, lang, remote_loc)
221
-