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.
- com/johnsnowlabs/ml/__init__.py +0 -0
- com/johnsnowlabs/ml/ai/__init__.py +10 -0
- spark_nlp-6.2.1.dist-info/METADATA +362 -0
- spark_nlp-6.2.1.dist-info/RECORD +292 -0
- {spark_nlp-4.2.6.dist-info → spark_nlp-6.2.1.dist-info}/WHEEL +1 -1
- sparknlp/__init__.py +81 -28
- sparknlp/annotation.py +3 -2
- sparknlp/annotator/__init__.py +6 -0
- sparknlp/annotator/audio/__init__.py +2 -0
- sparknlp/annotator/audio/hubert_for_ctc.py +188 -0
- sparknlp/annotator/audio/wav2vec2_for_ctc.py +14 -14
- sparknlp/annotator/audio/whisper_for_ctc.py +251 -0
- sparknlp/{base → annotator}/chunk2_doc.py +4 -7
- sparknlp/annotator/chunker.py +1 -2
- sparknlp/annotator/classifier_dl/__init__.py +17 -0
- sparknlp/annotator/classifier_dl/albert_for_multiple_choice.py +161 -0
- sparknlp/annotator/classifier_dl/albert_for_question_answering.py +3 -15
- sparknlp/annotator/classifier_dl/albert_for_sequence_classification.py +4 -18
- sparknlp/annotator/classifier_dl/albert_for_token_classification.py +3 -17
- sparknlp/annotator/classifier_dl/albert_for_zero_shot_classification.py +211 -0
- sparknlp/annotator/classifier_dl/bart_for_zero_shot_classification.py +225 -0
- sparknlp/annotator/classifier_dl/bert_for_multiple_choice.py +161 -0
- sparknlp/annotator/classifier_dl/bert_for_question_answering.py +6 -20
- sparknlp/annotator/classifier_dl/bert_for_sequence_classification.py +3 -17
- sparknlp/annotator/classifier_dl/bert_for_token_classification.py +3 -17
- sparknlp/annotator/classifier_dl/bert_for_zero_shot_classification.py +212 -0
- sparknlp/annotator/classifier_dl/camembert_for_question_answering.py +168 -0
- sparknlp/annotator/classifier_dl/camembert_for_sequence_classification.py +5 -19
- sparknlp/annotator/classifier_dl/camembert_for_token_classification.py +5 -19
- sparknlp/annotator/classifier_dl/camembert_for_zero_shot_classification.py +202 -0
- sparknlp/annotator/classifier_dl/classifier_dl.py +4 -4
- sparknlp/annotator/classifier_dl/deberta_for_question_answering.py +3 -17
- sparknlp/annotator/classifier_dl/deberta_for_sequence_classification.py +4 -19
- sparknlp/annotator/classifier_dl/deberta_for_token_classification.py +5 -21
- sparknlp/annotator/classifier_dl/deberta_for_zero_shot_classification.py +193 -0
- sparknlp/annotator/classifier_dl/distil_bert_for_question_answering.py +3 -17
- sparknlp/annotator/classifier_dl/distil_bert_for_sequence_classification.py +4 -18
- sparknlp/annotator/classifier_dl/distil_bert_for_token_classification.py +3 -17
- sparknlp/annotator/classifier_dl/distil_bert_for_zero_shot_classification.py +211 -0
- sparknlp/annotator/classifier_dl/distilbert_for_multiple_choice.py +161 -0
- sparknlp/annotator/classifier_dl/longformer_for_question_answering.py +3 -17
- sparknlp/annotator/classifier_dl/longformer_for_sequence_classification.py +4 -18
- sparknlp/annotator/classifier_dl/longformer_for_token_classification.py +3 -17
- sparknlp/annotator/classifier_dl/mpnet_for_question_answering.py +148 -0
- sparknlp/annotator/classifier_dl/mpnet_for_sequence_classification.py +188 -0
- sparknlp/annotator/classifier_dl/mpnet_for_token_classification.py +173 -0
- sparknlp/annotator/classifier_dl/multi_classifier_dl.py +3 -3
- sparknlp/annotator/classifier_dl/roberta_for_multiple_choice.py +161 -0
- sparknlp/annotator/classifier_dl/roberta_for_question_answering.py +3 -17
- sparknlp/annotator/classifier_dl/roberta_for_sequence_classification.py +4 -18
- sparknlp/annotator/classifier_dl/roberta_for_token_classification.py +1 -1
- sparknlp/annotator/classifier_dl/roberta_for_zero_shot_classification.py +225 -0
- sparknlp/annotator/classifier_dl/sentiment_dl.py +4 -4
- sparknlp/annotator/classifier_dl/tapas_for_question_answering.py +2 -2
- sparknlp/annotator/classifier_dl/xlm_roberta_for_multiple_choice.py +149 -0
- sparknlp/annotator/classifier_dl/xlm_roberta_for_question_answering.py +3 -17
- sparknlp/annotator/classifier_dl/xlm_roberta_for_sequence_classification.py +4 -18
- sparknlp/annotator/classifier_dl/xlm_roberta_for_token_classification.py +6 -20
- sparknlp/annotator/classifier_dl/xlm_roberta_for_zero_shot_classification.py +225 -0
- sparknlp/annotator/classifier_dl/xlnet_for_sequence_classification.py +4 -18
- sparknlp/annotator/classifier_dl/xlnet_for_token_classification.py +3 -17
- sparknlp/annotator/cleaners/__init__.py +15 -0
- sparknlp/annotator/cleaners/cleaner.py +202 -0
- sparknlp/annotator/cleaners/extractor.py +191 -0
- sparknlp/annotator/coref/spanbert_coref.py +4 -18
- sparknlp/annotator/cv/__init__.py +15 -0
- sparknlp/annotator/cv/blip_for_question_answering.py +172 -0
- sparknlp/annotator/cv/clip_for_zero_shot_classification.py +193 -0
- sparknlp/annotator/cv/convnext_for_image_classification.py +269 -0
- sparknlp/annotator/cv/florence2_transformer.py +180 -0
- sparknlp/annotator/cv/gemma3_for_multimodal.py +346 -0
- sparknlp/annotator/cv/internvl_for_multimodal.py +280 -0
- sparknlp/annotator/cv/janus_for_multimodal.py +351 -0
- sparknlp/annotator/cv/llava_for_multimodal.py +328 -0
- sparknlp/annotator/cv/mllama_for_multimodal.py +340 -0
- sparknlp/annotator/cv/paligemma_for_multimodal.py +308 -0
- sparknlp/annotator/cv/phi3_vision_for_multimodal.py +328 -0
- sparknlp/annotator/cv/qwen2vl_transformer.py +332 -0
- sparknlp/annotator/cv/smolvlm_transformer.py +426 -0
- sparknlp/annotator/cv/swin_for_image_classification.py +242 -0
- sparknlp/annotator/cv/vision_encoder_decoder_for_image_captioning.py +240 -0
- sparknlp/annotator/cv/vit_for_image_classification.py +36 -4
- sparknlp/annotator/dataframe_optimizer.py +216 -0
- sparknlp/annotator/date2_chunk.py +88 -0
- sparknlp/annotator/dependency/dependency_parser.py +2 -3
- sparknlp/annotator/dependency/typed_dependency_parser.py +3 -4
- sparknlp/annotator/document_character_text_splitter.py +228 -0
- sparknlp/annotator/document_normalizer.py +37 -1
- sparknlp/annotator/document_token_splitter.py +175 -0
- sparknlp/annotator/document_token_splitter_test.py +85 -0
- sparknlp/annotator/embeddings/__init__.py +11 -0
- sparknlp/annotator/embeddings/albert_embeddings.py +4 -18
- sparknlp/annotator/embeddings/auto_gguf_embeddings.py +539 -0
- sparknlp/annotator/embeddings/bert_embeddings.py +9 -22
- sparknlp/annotator/embeddings/bert_sentence_embeddings.py +12 -24
- sparknlp/annotator/embeddings/bge_embeddings.py +199 -0
- sparknlp/annotator/embeddings/camembert_embeddings.py +4 -20
- sparknlp/annotator/embeddings/chunk_embeddings.py +1 -2
- sparknlp/annotator/embeddings/deberta_embeddings.py +2 -16
- sparknlp/annotator/embeddings/distil_bert_embeddings.py +5 -19
- sparknlp/annotator/embeddings/doc2vec.py +7 -1
- sparknlp/annotator/embeddings/e5_embeddings.py +195 -0
- sparknlp/annotator/embeddings/e5v_embeddings.py +138 -0
- sparknlp/annotator/embeddings/elmo_embeddings.py +2 -2
- sparknlp/annotator/embeddings/instructor_embeddings.py +204 -0
- sparknlp/annotator/embeddings/longformer_embeddings.py +3 -17
- sparknlp/annotator/embeddings/minilm_embeddings.py +189 -0
- sparknlp/annotator/embeddings/mpnet_embeddings.py +192 -0
- sparknlp/annotator/embeddings/mxbai_embeddings.py +184 -0
- sparknlp/annotator/embeddings/nomic_embeddings.py +181 -0
- sparknlp/annotator/embeddings/roberta_embeddings.py +9 -21
- sparknlp/annotator/embeddings/roberta_sentence_embeddings.py +7 -21
- sparknlp/annotator/embeddings/sentence_embeddings.py +2 -3
- sparknlp/annotator/embeddings/snowflake_embeddings.py +202 -0
- sparknlp/annotator/embeddings/uae_embeddings.py +211 -0
- sparknlp/annotator/embeddings/universal_sentence_encoder.py +3 -3
- sparknlp/annotator/embeddings/word2vec.py +7 -1
- sparknlp/annotator/embeddings/word_embeddings.py +4 -5
- sparknlp/annotator/embeddings/xlm_roberta_embeddings.py +9 -21
- sparknlp/annotator/embeddings/xlm_roberta_sentence_embeddings.py +7 -21
- sparknlp/annotator/embeddings/xlnet_embeddings.py +4 -18
- sparknlp/annotator/er/entity_ruler.py +37 -23
- sparknlp/annotator/keyword_extraction/yake_keyword_extraction.py +2 -3
- sparknlp/annotator/ld_dl/language_detector_dl.py +2 -2
- sparknlp/annotator/lemmatizer.py +3 -4
- sparknlp/annotator/matcher/date_matcher.py +35 -3
- sparknlp/annotator/matcher/multi_date_matcher.py +1 -2
- sparknlp/annotator/matcher/regex_matcher.py +3 -3
- sparknlp/annotator/matcher/text_matcher.py +2 -3
- sparknlp/annotator/n_gram_generator.py +1 -2
- sparknlp/annotator/ner/__init__.py +3 -1
- sparknlp/annotator/ner/ner_converter.py +18 -0
- sparknlp/annotator/ner/ner_crf.py +4 -5
- sparknlp/annotator/ner/ner_dl.py +10 -5
- sparknlp/annotator/ner/ner_dl_graph_checker.py +293 -0
- sparknlp/annotator/ner/ner_overwriter.py +2 -2
- sparknlp/annotator/ner/zero_shot_ner_model.py +173 -0
- sparknlp/annotator/normalizer.py +2 -2
- sparknlp/annotator/openai/__init__.py +16 -0
- sparknlp/annotator/openai/openai_completion.py +349 -0
- sparknlp/annotator/openai/openai_embeddings.py +106 -0
- sparknlp/annotator/pos/perceptron.py +6 -7
- sparknlp/annotator/sentence/sentence_detector.py +2 -2
- sparknlp/annotator/sentence/sentence_detector_dl.py +3 -3
- sparknlp/annotator/sentiment/sentiment_detector.py +4 -5
- sparknlp/annotator/sentiment/vivekn_sentiment.py +4 -5
- sparknlp/annotator/seq2seq/__init__.py +17 -0
- sparknlp/annotator/seq2seq/auto_gguf_model.py +304 -0
- sparknlp/annotator/seq2seq/auto_gguf_reranker.py +334 -0
- sparknlp/annotator/seq2seq/auto_gguf_vision_model.py +336 -0
- sparknlp/annotator/seq2seq/bart_transformer.py +420 -0
- sparknlp/annotator/seq2seq/cohere_transformer.py +357 -0
- sparknlp/annotator/seq2seq/cpm_transformer.py +321 -0
- sparknlp/annotator/seq2seq/gpt2_transformer.py +1 -1
- sparknlp/annotator/seq2seq/llama2_transformer.py +343 -0
- sparknlp/annotator/seq2seq/llama3_transformer.py +381 -0
- sparknlp/annotator/seq2seq/m2m100_transformer.py +392 -0
- sparknlp/annotator/seq2seq/marian_transformer.py +124 -3
- sparknlp/annotator/seq2seq/mistral_transformer.py +348 -0
- sparknlp/annotator/seq2seq/nllb_transformer.py +420 -0
- sparknlp/annotator/seq2seq/olmo_transformer.py +326 -0
- sparknlp/annotator/seq2seq/phi2_transformer.py +326 -0
- sparknlp/annotator/seq2seq/phi3_transformer.py +330 -0
- sparknlp/annotator/seq2seq/phi4_transformer.py +387 -0
- sparknlp/annotator/seq2seq/qwen_transformer.py +340 -0
- sparknlp/annotator/seq2seq/starcoder_transformer.py +335 -0
- sparknlp/annotator/seq2seq/t5_transformer.py +54 -4
- sparknlp/annotator/similarity/__init__.py +0 -0
- sparknlp/annotator/similarity/document_similarity_ranker.py +379 -0
- sparknlp/annotator/spell_check/context_spell_checker.py +116 -17
- sparknlp/annotator/spell_check/norvig_sweeting.py +3 -6
- sparknlp/annotator/spell_check/symmetric_delete.py +1 -1
- sparknlp/annotator/stemmer.py +2 -3
- sparknlp/annotator/stop_words_cleaner.py +3 -4
- sparknlp/annotator/tf_ner_dl_graph_builder.py +1 -1
- sparknlp/annotator/token/__init__.py +0 -1
- sparknlp/annotator/token/recursive_tokenizer.py +2 -3
- sparknlp/annotator/token/tokenizer.py +2 -3
- sparknlp/annotator/ws/word_segmenter.py +35 -10
- sparknlp/base/__init__.py +2 -3
- sparknlp/base/doc2_chunk.py +0 -3
- sparknlp/base/document_assembler.py +5 -5
- sparknlp/base/embeddings_finisher.py +14 -2
- sparknlp/base/finisher.py +15 -4
- sparknlp/base/gguf_ranking_finisher.py +234 -0
- sparknlp/base/image_assembler.py +69 -0
- sparknlp/base/light_pipeline.py +53 -21
- sparknlp/base/multi_document_assembler.py +9 -13
- sparknlp/base/prompt_assembler.py +207 -0
- sparknlp/base/token_assembler.py +1 -2
- sparknlp/common/__init__.py +2 -0
- sparknlp/common/annotator_type.py +1 -0
- sparknlp/common/completion_post_processing.py +37 -0
- sparknlp/common/match_strategy.py +33 -0
- sparknlp/common/properties.py +914 -9
- sparknlp/internal/__init__.py +841 -116
- sparknlp/internal/annotator_java_ml.py +1 -1
- sparknlp/internal/annotator_transformer.py +3 -0
- sparknlp/logging/comet.py +2 -2
- sparknlp/partition/__init__.py +16 -0
- sparknlp/partition/partition.py +244 -0
- sparknlp/partition/partition_properties.py +902 -0
- sparknlp/partition/partition_transformer.py +200 -0
- sparknlp/pretrained/pretrained_pipeline.py +1 -1
- sparknlp/pretrained/resource_downloader.py +126 -2
- sparknlp/reader/__init__.py +15 -0
- sparknlp/reader/enums.py +19 -0
- sparknlp/reader/pdf_to_text.py +190 -0
- sparknlp/reader/reader2doc.py +124 -0
- sparknlp/reader/reader2image.py +136 -0
- sparknlp/reader/reader2table.py +44 -0
- sparknlp/reader/reader_assembler.py +159 -0
- sparknlp/reader/sparknlp_reader.py +461 -0
- sparknlp/training/__init__.py +1 -0
- sparknlp/training/conll.py +8 -2
- sparknlp/training/spacy_to_annotation.py +57 -0
- sparknlp/util.py +26 -0
- spark_nlp-4.2.6.dist-info/METADATA +0 -1256
- spark_nlp-4.2.6.dist-info/RECORD +0 -196
- {spark_nlp-4.2.6.dist-info → spark_nlp-6.2.1.dist-info}/top_level.txt +0 -0
- /sparknlp/annotator/{token/token2_chunk.py → token2_chunk.py} +0 -0
|
@@ -0,0 +1,336 @@
|
|
|
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 the AutoGGUFVisionModel."""
|
|
15
|
+
from sparknlp.common import *
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AutoGGUFVisionModel(AnnotatorModel, HasBatchedAnnotate, HasLlamaCppProperties, CompletionPostProcessing):
|
|
19
|
+
"""Multimodal annotator that uses the llama.cpp library to generate text completions with large
|
|
20
|
+
language models. It supports ingesting images for captioning.
|
|
21
|
+
|
|
22
|
+
At the moment only CLIP based models are supported.
|
|
23
|
+
|
|
24
|
+
For settable parameters, and their explanations, see HasLlamaCppInferenceProperties,
|
|
25
|
+
HasLlamaCppModelProperties and refer to the llama.cpp documentation of
|
|
26
|
+
`server.cpp <https://github.com/ggerganov/llama.cpp/tree/7d5e8777ae1d21af99d4f95be10db4870720da91/examples/server>`__
|
|
27
|
+
for more information.
|
|
28
|
+
|
|
29
|
+
If the parameters are not set, the annotator will default to use the parameters provided by
|
|
30
|
+
the model.
|
|
31
|
+
|
|
32
|
+
This annotator expects a column of annotator type AnnotationImage for the image and
|
|
33
|
+
Annotation for the caption. Note that the image bytes in the image annotation need to be
|
|
34
|
+
raw image bytes without preprocessing. We provide the helper function
|
|
35
|
+
ImageAssembler.loadImagesAsBytes to load the image bytes from a directory.
|
|
36
|
+
|
|
37
|
+
Pretrained models can be loaded with ``pretrained`` of the companion object:
|
|
38
|
+
|
|
39
|
+
.. code-block:: python
|
|
40
|
+
|
|
41
|
+
autoGGUFVisionModel = AutoGGUFVisionModel.pretrained() \\
|
|
42
|
+
.setInputCols(["image", "document"]) \\
|
|
43
|
+
.setOutputCol("completions")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
The default model is ``"Qwen2.5_VL_3B_Instruct_Q4_K_M_gguf"``, if no name is provided.
|
|
47
|
+
|
|
48
|
+
For available pretrained models please see the `Models Hub <https://sparknlp.org/models>`__.
|
|
49
|
+
|
|
50
|
+
For extended examples of usage, see the
|
|
51
|
+
`AutoGGUFVisionModelTest <https://github.com/JohnSnowLabs/spark-nlp/tree/master/src/test/scala/com/johnsnowlabs/nlp/annotators/seq2seq/AutoGGUFVisionModelTest.scala>`__
|
|
52
|
+
and the
|
|
53
|
+
`example notebook <https://github.com/JohnSnowLabs/spark-nlp/tree/master/examples/python/llama.cpp/llama.cpp_in_Spark_NLP_AutoGGUFVisionModel.ipynb>`__.
|
|
54
|
+
|
|
55
|
+
====================== ======================
|
|
56
|
+
Input Annotation types Output Annotation type
|
|
57
|
+
====================== ======================
|
|
58
|
+
``IMAGE, DOCUMENT`` ``DOCUMENT``
|
|
59
|
+
====================== ======================
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
nThreads
|
|
64
|
+
Set the number of threads to use during generation
|
|
65
|
+
nThreadsDraft
|
|
66
|
+
Set the number of threads to use during draft generation
|
|
67
|
+
nThreadsBatch
|
|
68
|
+
Set the number of threads to use during batch and prompt processing
|
|
69
|
+
nThreadsBatchDraft
|
|
70
|
+
Set the number of threads to use during batch and prompt processing
|
|
71
|
+
nCtx
|
|
72
|
+
Set the size of the prompt context
|
|
73
|
+
nBatch
|
|
74
|
+
Set the logical batch size for prompt processing (must be >=32 to use BLAS)
|
|
75
|
+
nUbatch
|
|
76
|
+
Set the physical batch size for prompt processing (must be >=32 to use BLAS)
|
|
77
|
+
nDraft
|
|
78
|
+
Set the number of tokens to draft for speculative decoding
|
|
79
|
+
nChunks
|
|
80
|
+
Set the maximal number of chunks to process
|
|
81
|
+
nSequences
|
|
82
|
+
Set the number of sequences to decode
|
|
83
|
+
pSplit
|
|
84
|
+
Set the speculative decoding split probability
|
|
85
|
+
nGpuLayers
|
|
86
|
+
Set the number of layers to store in VRAM (-1 - use default)
|
|
87
|
+
nGpuLayersDraft
|
|
88
|
+
Set the number of layers to store in VRAM for the draft model (-1 - use default)
|
|
89
|
+
gpuSplitMode
|
|
90
|
+
Set how to split the model across GPUs
|
|
91
|
+
mainGpu
|
|
92
|
+
Set the main GPU that is used for scratch and small tensors.
|
|
93
|
+
tensorSplit
|
|
94
|
+
Set how split tensors should be distributed across GPUs
|
|
95
|
+
grpAttnN
|
|
96
|
+
Set the group-attention factor
|
|
97
|
+
grpAttnW
|
|
98
|
+
Set the group-attention width
|
|
99
|
+
ropeFreqBase
|
|
100
|
+
Set the RoPE base frequency, used by NTK-aware scaling
|
|
101
|
+
ropeFreqScale
|
|
102
|
+
Set the RoPE frequency scaling factor, expands context by a factor of 1/N
|
|
103
|
+
yarnExtFactor
|
|
104
|
+
Set the YaRN extrapolation mix factor
|
|
105
|
+
yarnAttnFactor
|
|
106
|
+
Set the YaRN scale sqrt(t) or attention magnitude
|
|
107
|
+
yarnBetaFast
|
|
108
|
+
Set the YaRN low correction dim or beta
|
|
109
|
+
yarnBetaSlow
|
|
110
|
+
Set the YaRN high correction dim or alpha
|
|
111
|
+
yarnOrigCtx
|
|
112
|
+
Set the YaRN original context size of model
|
|
113
|
+
defragmentationThreshold
|
|
114
|
+
Set the KV cache defragmentation threshold
|
|
115
|
+
numaStrategy
|
|
116
|
+
Set optimization strategies that help on some NUMA systems (if available)
|
|
117
|
+
ropeScalingType
|
|
118
|
+
Set the RoPE frequency scaling method, defaults to linear unless specified by the model
|
|
119
|
+
modelDraft
|
|
120
|
+
Set the draft model for speculative decoding
|
|
121
|
+
modelAlias
|
|
122
|
+
Set a model alias
|
|
123
|
+
lookupCacheStaticFilePath
|
|
124
|
+
Set path to static lookup cache to use for lookup decoding (not updated by generation)
|
|
125
|
+
lookupCacheDynamicFilePath
|
|
126
|
+
Set path to dynamic lookup cache to use for lookup decoding (updated by generation)
|
|
127
|
+
flashAttention
|
|
128
|
+
Whether to enable Flash Attention
|
|
129
|
+
inputPrefixBos
|
|
130
|
+
Whether to add prefix BOS to user inputs, preceding the `--in-prefix` string
|
|
131
|
+
useMmap
|
|
132
|
+
Whether to use memory-map model (faster load but may increase pageouts if not using mlock)
|
|
133
|
+
useMlock
|
|
134
|
+
Whether to force the system to keep model in RAM rather than swapping or compressing
|
|
135
|
+
noKvOffload
|
|
136
|
+
Whether to disable KV offload
|
|
137
|
+
systemPrompt
|
|
138
|
+
Set a system prompt to use
|
|
139
|
+
chatTemplate
|
|
140
|
+
The chat template to use
|
|
141
|
+
inputPrefix
|
|
142
|
+
Set the prompt to start generation with
|
|
143
|
+
inputSuffix
|
|
144
|
+
Set a suffix for infilling
|
|
145
|
+
cachePrompt
|
|
146
|
+
Whether to remember the prompt to avoid reprocessing it
|
|
147
|
+
nPredict
|
|
148
|
+
Set the number of tokens to predict
|
|
149
|
+
topK
|
|
150
|
+
Set top-k sampling
|
|
151
|
+
topP
|
|
152
|
+
Set top-p sampling
|
|
153
|
+
minP
|
|
154
|
+
Set min-p sampling
|
|
155
|
+
tfsZ
|
|
156
|
+
Set tail free sampling, parameter z
|
|
157
|
+
typicalP
|
|
158
|
+
Set locally typical sampling, parameter p
|
|
159
|
+
temperature
|
|
160
|
+
Set the temperature
|
|
161
|
+
dynatempRange
|
|
162
|
+
Set the dynamic temperature range
|
|
163
|
+
dynatempExponent
|
|
164
|
+
Set the dynamic temperature exponent
|
|
165
|
+
repeatLastN
|
|
166
|
+
Set the last n tokens to consider for penalties
|
|
167
|
+
repeatPenalty
|
|
168
|
+
Set the penalty of repeated sequences of tokens
|
|
169
|
+
frequencyPenalty
|
|
170
|
+
Set the repetition alpha frequency penalty
|
|
171
|
+
presencePenalty
|
|
172
|
+
Set the repetition alpha presence penalty
|
|
173
|
+
miroStat
|
|
174
|
+
Set MiroStat sampling strategies.
|
|
175
|
+
mirostatTau
|
|
176
|
+
Set the MiroStat target entropy, parameter tau
|
|
177
|
+
mirostatEta
|
|
178
|
+
Set the MiroStat learning rate, parameter eta
|
|
179
|
+
penalizeNl
|
|
180
|
+
Whether to penalize newline tokens
|
|
181
|
+
nKeep
|
|
182
|
+
Set the number of tokens to keep from the initial prompt
|
|
183
|
+
seed
|
|
184
|
+
Set the RNG seed
|
|
185
|
+
nProbs
|
|
186
|
+
Set the amount top tokens probabilities to output if greater than 0.
|
|
187
|
+
minKeep
|
|
188
|
+
Set the amount of tokens the samplers should return at least (0 = disabled)
|
|
189
|
+
grammar
|
|
190
|
+
Set BNF-like grammar to constrain generations
|
|
191
|
+
penaltyPrompt
|
|
192
|
+
Override which part of the prompt is penalized for repetition.
|
|
193
|
+
ignoreEos
|
|
194
|
+
Set whether to ignore end of stream token and continue generating (implies --logit-bias 2-inf)
|
|
195
|
+
disableTokenIds
|
|
196
|
+
Set the token ids to disable in the completion
|
|
197
|
+
stopStrings
|
|
198
|
+
Set strings upon seeing which token generation is stopped
|
|
199
|
+
samplers
|
|
200
|
+
Set which samplers to use for token generation in the given order
|
|
201
|
+
useChatTemplate
|
|
202
|
+
Set whether or not generate should apply a chat template
|
|
203
|
+
|
|
204
|
+
Notes
|
|
205
|
+
-----
|
|
206
|
+
To use GPU inference with this annotator, make sure to use the Spark NLP GPU package and set
|
|
207
|
+
the number of GPU layers with the `setNGpuLayers` method.
|
|
208
|
+
|
|
209
|
+
When using larger models, we recommend adjusting GPU usage with `setNCtx` and `setNGpuLayers`
|
|
210
|
+
according to your hardware to avoid out-of-memory errors.
|
|
211
|
+
|
|
212
|
+
Examples
|
|
213
|
+
>>> import sparknlp
|
|
214
|
+
>>> from sparknlp.base import *
|
|
215
|
+
>>> from sparknlp.annotator import *
|
|
216
|
+
>>> from pyspark.ml import Pipeline
|
|
217
|
+
>>> from pyspark.sql.functions import lit
|
|
218
|
+
>>> documentAssembler = DocumentAssembler() \\
|
|
219
|
+
... .setInputCol("caption") \\
|
|
220
|
+
... .setOutputCol("caption_document")
|
|
221
|
+
>>> imageAssembler = ImageAssembler() \\
|
|
222
|
+
... .setInputCol("image") \\
|
|
223
|
+
... .setOutputCol("image_assembler")
|
|
224
|
+
>>> imagesPath = "src/test/resources/image/"
|
|
225
|
+
>>> data = ImageAssembler \\
|
|
226
|
+
... .loadImagesAsBytes(spark, imagesPath) \\
|
|
227
|
+
... .withColumn("caption", lit("Caption this image.")) # Add a caption to each image.
|
|
228
|
+
>>> nPredict = 40
|
|
229
|
+
>>> model = AutoGGUFVisionModel.pretrained() \\
|
|
230
|
+
... .setInputCols(["caption_document", "image_assembler"]) \\
|
|
231
|
+
... .setOutputCol("completions") \\
|
|
232
|
+
... .setBatchSize(4) \\
|
|
233
|
+
... .setNGpuLayers(99) \\
|
|
234
|
+
... .setNCtx(4096) \\
|
|
235
|
+
... .setMinKeep(0) \\
|
|
236
|
+
... .setMinP(0.05) \\
|
|
237
|
+
... .setNPredict(nPredict) \\
|
|
238
|
+
... .setNProbs(0) \\
|
|
239
|
+
... .setPenalizeNl(False) \\
|
|
240
|
+
... .setRepeatLastN(256) \\
|
|
241
|
+
... .setRepeatPenalty(1.18) \\
|
|
242
|
+
... .setStopStrings(["</s>", "Llama:", "User:"]) \\
|
|
243
|
+
... .setTemperature(0.05) \\
|
|
244
|
+
... .setTfsZ(1) \\
|
|
245
|
+
... .setTypicalP(1) \\
|
|
246
|
+
... .setTopK(40) \\
|
|
247
|
+
... .setTopP(0.95)
|
|
248
|
+
>>> pipeline = Pipeline().setStages([documentAssembler, imageAssembler, model])
|
|
249
|
+
>>> pipeline.fit(data).transform(data) \\
|
|
250
|
+
... .selectExpr("reverse(split(image.origin, '/'))[0] as image_name", "completions.result") \\
|
|
251
|
+
... .show(truncate = False)
|
|
252
|
+
+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
253
|
+
|image_name |result |
|
|
254
|
+
+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
255
|
+
|palace.JPEG |[ The image depicts a large, ornate room with high ceilings and beautifully decorated walls. There are several chairs placed throughout the space, some of which have cushions] |
|
|
256
|
+
|egyptian_cat.jpeg|[ The image features two cats lying on a pink surface, possibly a bed or sofa. One cat is positioned towards the left side of the scene and appears to be sleeping while holding] |
|
|
257
|
+
|hippopotamus.JPEG|[ A large brown hippo is swimming in a body of water, possibly an aquarium. The hippo appears to be enjoying its time in the water and seems relaxed as it floats] |
|
|
258
|
+
|hen.JPEG |[ The image features a large chicken standing next to several baby chickens. In total, there are five birds in the scene: one adult and four young ones. They appear to be gathered together] |
|
|
259
|
+
|ostrich.JPEG |[ The image features a large, long-necked bird standing in the grass. It appears to be an ostrich or similar species with its head held high and looking around. In addition to] |
|
|
260
|
+
|junco.JPEG |[ A small bird with a black head and white chest is standing on the snow. It appears to be looking at something, possibly food or another animal in its vicinity. The scene takes place out] |
|
|
261
|
+
|bluetick.jpg |[ A dog with a red collar is sitting on the floor, looking at something. The dog appears to be staring into the distance or focusing its attention on an object in front of it.] |
|
|
262
|
+
|chihuahua.jpg |[ A small brown dog wearing a sweater is sitting on the floor. The dog appears to be looking at something, possibly its owner or another animal in the room. It seems comfortable and relaxed]|
|
|
263
|
+
|tractor.JPEG |[ A man is sitting in the driver's seat of a green tractor, which has yellow wheels and tires. The tractor appears to be parked on top of an empty field with] |
|
|
264
|
+
|ox.JPEG |[ A large bull with horns is standing in a grassy field.] |
|
|
265
|
+
+-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------
|
|
266
|
+
"""
|
|
267
|
+
|
|
268
|
+
name = "AutoGGUFVisionModel"
|
|
269
|
+
inputAnnotatorTypes = [AnnotatorType.IMAGE, AnnotatorType.DOCUMENT]
|
|
270
|
+
outputAnnotatorType = AnnotatorType.DOCUMENT
|
|
271
|
+
|
|
272
|
+
@keyword_only
|
|
273
|
+
def __init__(self, classname="com.johnsnowlabs.nlp.annotators.seq2seq.AutoGGUFVisionModel", java_model=None):
|
|
274
|
+
super(AutoGGUFVisionModel, self).__init__(
|
|
275
|
+
classname=classname,
|
|
276
|
+
java_model=java_model
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
self._setDefault(
|
|
280
|
+
useChatTemplate=True,
|
|
281
|
+
nCtx=4096,
|
|
282
|
+
nBatch=512,
|
|
283
|
+
nPredict=100,
|
|
284
|
+
nGpuLayers=99,
|
|
285
|
+
systemPrompt="You are a helpful assistant.",
|
|
286
|
+
batchSize=2,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
@staticmethod
|
|
290
|
+
def loadSavedModel(modelPath, mmprojPath, spark_session):
|
|
291
|
+
"""Loads a locally saved modelPath.
|
|
292
|
+
|
|
293
|
+
Parameters
|
|
294
|
+
----------
|
|
295
|
+
modelPath : str
|
|
296
|
+
Path to the modelPath file
|
|
297
|
+
mmprojPath : str
|
|
298
|
+
Path to the mmprojPath file
|
|
299
|
+
spark_session : pyspark.sql.SparkSession
|
|
300
|
+
The current SparkSession
|
|
301
|
+
|
|
302
|
+
Returns
|
|
303
|
+
-------
|
|
304
|
+
AutoGGUFVisionModel
|
|
305
|
+
The restored modelPath
|
|
306
|
+
"""
|
|
307
|
+
from sparknlp.internal import _AutoGGUFVisionLoader
|
|
308
|
+
jModel = _AutoGGUFVisionLoader(modelPath, mmprojPath, spark_session._jsparkSession)._java_obj
|
|
309
|
+
return AutoGGUFVisionModel(java_model=jModel)
|
|
310
|
+
|
|
311
|
+
@staticmethod
|
|
312
|
+
def pretrained(name="Qwen2.5_VL_3B_Instruct_Q4_K_M_gguf", lang="en", remote_loc=None):
|
|
313
|
+
"""Downloads and loads a pretrained model.
|
|
314
|
+
|
|
315
|
+
Parameters
|
|
316
|
+
----------
|
|
317
|
+
name : str, optional
|
|
318
|
+
Name of the pretrained model, by default "Qwen2.5_VL_3B_Instruct_Q4_K_M_gguf"
|
|
319
|
+
lang : str, optional
|
|
320
|
+
Language of the pretrained model, by default "en"
|
|
321
|
+
remote_loc : str, optional
|
|
322
|
+
Optional remote address of the resource, by default None. Will use
|
|
323
|
+
Spark NLPs repositories otherwise.
|
|
324
|
+
|
|
325
|
+
Returns
|
|
326
|
+
-------
|
|
327
|
+
AutoGGUFVisionModel
|
|
328
|
+
The restored model
|
|
329
|
+
"""
|
|
330
|
+
from sparknlp.pretrained import ResourceDownloader
|
|
331
|
+
return ResourceDownloader.downloadModel(AutoGGUFVisionModel, name, lang, remote_loc)
|
|
332
|
+
|
|
333
|
+
def close(self):
|
|
334
|
+
"""Closes the llama.cpp model backend freeing resources. The model is reloaded when used again.
|
|
335
|
+
"""
|
|
336
|
+
self._java_obj.close()
|