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,346 @@
|
|
|
1
|
+
# Copyright 2017-2024 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
|
+
|
|
15
|
+
from sparknlp.common import *
|
|
16
|
+
|
|
17
|
+
class Gemma3ForMultiModal(AnnotatorModel,
|
|
18
|
+
HasBatchedAnnotateImage,
|
|
19
|
+
HasImageFeatureProperties,
|
|
20
|
+
HasEngine,
|
|
21
|
+
HasGeneratorProperties):
|
|
22
|
+
"""Gemma3ForMultiModal can load Gemma 3 Vision models for visual question answering.
|
|
23
|
+
The model consists of a vision encoder, a text encoder, a text decoder and a model merger.
|
|
24
|
+
The vision encoder will encode the input image, the text encoder will encode the input text,
|
|
25
|
+
the model merger will merge the image and text embeddings, and the text decoder will output the answer.
|
|
26
|
+
|
|
27
|
+
Gemma 3 is a family of lightweight, state-of-the-art open models from Google, built from the same
|
|
28
|
+
research and technology used to create the Gemini models. It features:
|
|
29
|
+
- Large 128K context window
|
|
30
|
+
- Multilingual support in over 140 languages
|
|
31
|
+
- Multimodal capabilities handling both text and image inputs
|
|
32
|
+
- Optimized for deployment on limited resources (laptops, desktops, cloud)
|
|
33
|
+
|
|
34
|
+
Pretrained models can be loaded with :meth:`.pretrained` of the companion
|
|
35
|
+
object:
|
|
36
|
+
|
|
37
|
+
>>> visualQA = Gemma3ForMultiModal.pretrained() \
|
|
38
|
+
... .setInputCols(["image_assembler"]) \
|
|
39
|
+
... .setOutputCol("answer")
|
|
40
|
+
|
|
41
|
+
The default model is ``"gemma3_4b_it_int4"``, if no name is
|
|
42
|
+
provided.
|
|
43
|
+
|
|
44
|
+
For available pretrained models please see the `Models Hub
|
|
45
|
+
<https://sparknlp.org/models?task=Question+Answering>`__.
|
|
46
|
+
|
|
47
|
+
====================== ======================
|
|
48
|
+
Input Annotation types Output Annotation type
|
|
49
|
+
====================== ======================
|
|
50
|
+
``IMAGE`` ``DOCUMENT``
|
|
51
|
+
====================== ======================
|
|
52
|
+
|
|
53
|
+
Parameters
|
|
54
|
+
----------
|
|
55
|
+
batchSize
|
|
56
|
+
Batch size. Large values allows faster processing but requires more
|
|
57
|
+
memory, by default 1
|
|
58
|
+
minOutputLength
|
|
59
|
+
Minimum length of the sequence to be generated, by default 0
|
|
60
|
+
maxOutputLength
|
|
61
|
+
Maximum length of output text, by default 20
|
|
62
|
+
doSample
|
|
63
|
+
Whether or not to use sampling; use greedy decoding otherwise, by default False
|
|
64
|
+
temperature
|
|
65
|
+
The value used to module the next token probabilities, by default 0.6
|
|
66
|
+
topK
|
|
67
|
+
The number of highest probability vocabulary tokens to keep for top-k-filtering, by default -1
|
|
68
|
+
topP
|
|
69
|
+
If set to float < 1, only the most probable tokens with probabilities that add up to ``top_p`` or higher are kept for generation, by default 0.9
|
|
70
|
+
repetitionPenalty
|
|
71
|
+
The parameter for repetition penalty. 1.0 means no penalty, by default 1.0
|
|
72
|
+
noRepeatNgramSize
|
|
73
|
+
If set to int > 0, all ngrams of that size can only occur once, by default 3
|
|
74
|
+
beamSize
|
|
75
|
+
The Number of beams for beam search, by default 1
|
|
76
|
+
maxInputLength
|
|
77
|
+
Maximum length of input text, by default 4096
|
|
78
|
+
|
|
79
|
+
Examples
|
|
80
|
+
--------
|
|
81
|
+
>>> import sparknlp
|
|
82
|
+
>>> from sparknlp.base import *
|
|
83
|
+
>>> from sparknlp.annotator import *
|
|
84
|
+
>>> from pyspark.ml import Pipeline
|
|
85
|
+
>>> from pyspark.sql.functions import lit
|
|
86
|
+
>>> imageDF = spark.read.format("image").load(images_path)
|
|
87
|
+
>>> testDF = imageDF.withColumn("text", lit("<bos><start_of_turn>user\\nYou are a helpful assistant.\\n\\n<start_of_image>Describe this image in detail.<end_of_turn>\\n<start_of_turn>model\\n"))
|
|
88
|
+
>>> imageAssembler = ImageAssembler() \\
|
|
89
|
+
... .setInputCol("image") \\
|
|
90
|
+
... .setOutputCol("image_assembler")
|
|
91
|
+
>>> visualQA = Gemma3ForMultiModal.pretrained() \\
|
|
92
|
+
... .setInputCols("image_assembler") \\
|
|
93
|
+
... .setOutputCol("answer")
|
|
94
|
+
>>> pipeline = Pipeline().setStages([
|
|
95
|
+
... imageAssembler,
|
|
96
|
+
... visualQA
|
|
97
|
+
... ])
|
|
98
|
+
>>> result = pipeline.fit(testDF).transform(testDF)
|
|
99
|
+
>>> result.select("image_assembler.origin", "answer.result").show(truncate=False)
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
name = "Gemma3ForMultiModal"
|
|
103
|
+
|
|
104
|
+
inputAnnotatorTypes = [AnnotatorType.IMAGE]
|
|
105
|
+
|
|
106
|
+
outputAnnotatorType = AnnotatorType.DOCUMENT
|
|
107
|
+
|
|
108
|
+
configProtoBytes = Param(Params._dummy(),
|
|
109
|
+
"configProtoBytes",
|
|
110
|
+
"ConfigProto from tensorflow, serialized into byte array. Get with "
|
|
111
|
+
"config_proto.SerializeToString()",
|
|
112
|
+
TypeConverters.toListInt)
|
|
113
|
+
|
|
114
|
+
minOutputLength = Param(Params._dummy(), "minOutputLength", "Minimum length of the sequence to be generated",
|
|
115
|
+
typeConverter=TypeConverters.toInt)
|
|
116
|
+
|
|
117
|
+
maxOutputLength = Param(Params._dummy(), "maxOutputLength", "Maximum length of output text",
|
|
118
|
+
typeConverter=TypeConverters.toInt)
|
|
119
|
+
|
|
120
|
+
doSample = Param(Params._dummy(), "doSample", "Whether or not to use sampling; use greedy decoding otherwise",
|
|
121
|
+
typeConverter=TypeConverters.toBoolean)
|
|
122
|
+
|
|
123
|
+
temperature = Param(Params._dummy(), "temperature", "The value used to module the next token probabilities",
|
|
124
|
+
typeConverter=TypeConverters.toFloat)
|
|
125
|
+
|
|
126
|
+
topK = Param(Params._dummy(), "topK",
|
|
127
|
+
"The number of highest probability vocabulary tokens to keep for top-k-filtering",
|
|
128
|
+
typeConverter=TypeConverters.toInt)
|
|
129
|
+
|
|
130
|
+
topP = Param(Params._dummy(), "topP",
|
|
131
|
+
"If set to float < 1, only the most probable tokens with probabilities that add up to ``top_p`` or higher are kept for generation",
|
|
132
|
+
typeConverter=TypeConverters.toFloat)
|
|
133
|
+
|
|
134
|
+
repetitionPenalty = Param(Params._dummy(), "repetitionPenalty",
|
|
135
|
+
"The parameter for repetition penalty. 1.0 means no penalty. See `this paper <https://arxiv.org/pdf/1909.05858.pdf>`__ for more details",
|
|
136
|
+
typeConverter=TypeConverters.toFloat)
|
|
137
|
+
|
|
138
|
+
noRepeatNgramSize = Param(Params._dummy(), "noRepeatNgramSize",
|
|
139
|
+
"If set to int > 0, all ngrams of that size can only occur once",
|
|
140
|
+
typeConverter=TypeConverters.toInt)
|
|
141
|
+
|
|
142
|
+
ignoreTokenIds = Param(Params._dummy(), "ignoreTokenIds",
|
|
143
|
+
"A list of token ids which are ignored in the decoder's output",
|
|
144
|
+
typeConverter=TypeConverters.toListInt)
|
|
145
|
+
beamSize = Param(Params._dummy(), "beamSize",
|
|
146
|
+
"The Number of beams for beam search.",
|
|
147
|
+
typeConverter=TypeConverters.toInt)
|
|
148
|
+
|
|
149
|
+
maxInputLength = Param(Params._dummy(), "maxInputLength", "Maximum length of input text",
|
|
150
|
+
typeConverter=TypeConverters.toInt)
|
|
151
|
+
|
|
152
|
+
def setMaxSentenceSize(self, value):
|
|
153
|
+
"""Sets Maximum sentence length that the annotator will process, by
|
|
154
|
+
default 50.
|
|
155
|
+
|
|
156
|
+
Parameters
|
|
157
|
+
----------
|
|
158
|
+
value : int
|
|
159
|
+
Maximum sentence length that the annotator will process
|
|
160
|
+
"""
|
|
161
|
+
return self._set(maxSentenceLength=value)
|
|
162
|
+
|
|
163
|
+
def setIgnoreTokenIds(self, value):
|
|
164
|
+
"""A list of token ids which are ignored in the decoder's output.
|
|
165
|
+
|
|
166
|
+
Parameters
|
|
167
|
+
----------
|
|
168
|
+
value : List[int]
|
|
169
|
+
The words to be filtered out
|
|
170
|
+
"""
|
|
171
|
+
return self._set(ignoreTokenIds=value)
|
|
172
|
+
|
|
173
|
+
def setConfigProtoBytes(self, b):
|
|
174
|
+
"""Sets configProto from tensorflow, serialized into byte array.
|
|
175
|
+
|
|
176
|
+
Parameters
|
|
177
|
+
----------
|
|
178
|
+
b : List[int]
|
|
179
|
+
ConfigProto from tensorflow, serialized into byte array
|
|
180
|
+
"""
|
|
181
|
+
return self._set(configProtoBytes=b)
|
|
182
|
+
|
|
183
|
+
def setMinOutputLength(self, value):
|
|
184
|
+
"""Sets minimum length of the sequence to be generated.
|
|
185
|
+
|
|
186
|
+
Parameters
|
|
187
|
+
----------
|
|
188
|
+
value : int
|
|
189
|
+
Minimum length of the sequence to be generated
|
|
190
|
+
"""
|
|
191
|
+
return self._set(minOutputLength=value)
|
|
192
|
+
|
|
193
|
+
def setMaxOutputLength(self, value):
|
|
194
|
+
"""Sets maximum length of output text.
|
|
195
|
+
|
|
196
|
+
Parameters
|
|
197
|
+
----------
|
|
198
|
+
value : int
|
|
199
|
+
Maximum length of output text
|
|
200
|
+
"""
|
|
201
|
+
return self._set(maxOutputLength=value)
|
|
202
|
+
|
|
203
|
+
def setDoSample(self, value):
|
|
204
|
+
"""Sets whether or not to use sampling, use greedy decoding otherwise.
|
|
205
|
+
|
|
206
|
+
Parameters
|
|
207
|
+
----------
|
|
208
|
+
value : bool
|
|
209
|
+
Whether or not to use sampling; use greedy decoding otherwise
|
|
210
|
+
"""
|
|
211
|
+
return self._set(doSample=value)
|
|
212
|
+
|
|
213
|
+
def setTemperature(self, value):
|
|
214
|
+
"""Sets the value used to module the next token probabilities.
|
|
215
|
+
|
|
216
|
+
Parameters
|
|
217
|
+
----------
|
|
218
|
+
value : float
|
|
219
|
+
The value used to module the next token probabilities
|
|
220
|
+
"""
|
|
221
|
+
return self._set(temperature=value)
|
|
222
|
+
|
|
223
|
+
def setTopK(self, value):
|
|
224
|
+
"""Sets the number of highest probability vocabulary tokens to keep for
|
|
225
|
+
top-k-filtering.
|
|
226
|
+
|
|
227
|
+
Parameters
|
|
228
|
+
----------
|
|
229
|
+
value : int
|
|
230
|
+
Number of highest probability vocabulary tokens to keep
|
|
231
|
+
"""
|
|
232
|
+
return self._set(topK=value)
|
|
233
|
+
|
|
234
|
+
def setTopP(self, value):
|
|
235
|
+
"""Sets the top cumulative probability for vocabulary tokens.
|
|
236
|
+
|
|
237
|
+
If set to float < 1, only the most probable tokens with probabilities
|
|
238
|
+
that add up to ``topP`` or higher are kept for generation.
|
|
239
|
+
|
|
240
|
+
Parameters
|
|
241
|
+
----------
|
|
242
|
+
value : float
|
|
243
|
+
Cumulative probability for vocabulary tokens
|
|
244
|
+
"""
|
|
245
|
+
return self._set(topP=value)
|
|
246
|
+
|
|
247
|
+
def setRepetitionPenalty(self, value):
|
|
248
|
+
"""Sets the parameter for repetition penalty. 1.0 means no penalty.
|
|
249
|
+
|
|
250
|
+
Parameters
|
|
251
|
+
----------
|
|
252
|
+
value : float
|
|
253
|
+
The repetition penalty
|
|
254
|
+
|
|
255
|
+
References
|
|
256
|
+
----------
|
|
257
|
+
See `Ctrl: A Conditional Transformer Language Model For Controllable
|
|
258
|
+
Generation <https://arxiv.org/pdf/1909.05858.pdf>`__ for more details.
|
|
259
|
+
"""
|
|
260
|
+
return self._set(repetitionPenalty=value)
|
|
261
|
+
|
|
262
|
+
def setNoRepeatNgramSize(self, value):
|
|
263
|
+
"""Sets size of n-grams that can only occur once.
|
|
264
|
+
|
|
265
|
+
If set to int > 0, all ngrams of that size can only occur once.
|
|
266
|
+
|
|
267
|
+
Parameters
|
|
268
|
+
----------
|
|
269
|
+
value : int
|
|
270
|
+
N-gram size can only occur once
|
|
271
|
+
"""
|
|
272
|
+
return self._set(noRepeatNgramSize=value)
|
|
273
|
+
|
|
274
|
+
def setBeamSize(self, value):
|
|
275
|
+
"""Sets the number of beam size for beam search, by default `4`.
|
|
276
|
+
|
|
277
|
+
Parameters
|
|
278
|
+
----------
|
|
279
|
+
value : int
|
|
280
|
+
Number of beam size for beam search
|
|
281
|
+
"""
|
|
282
|
+
return self._set(beamSize=value)
|
|
283
|
+
|
|
284
|
+
@keyword_only
|
|
285
|
+
def __init__(self, classname="com.johnsnowlabs.nlp.annotators.cv.Gemma3ForMultiModal",
|
|
286
|
+
java_model=None):
|
|
287
|
+
super(Gemma3ForMultiModal, self).__init__(
|
|
288
|
+
classname=classname,
|
|
289
|
+
java_model=java_model
|
|
290
|
+
)
|
|
291
|
+
self._setDefault(
|
|
292
|
+
batchSize=1,
|
|
293
|
+
minOutputLength=0,
|
|
294
|
+
maxOutputLength=20,
|
|
295
|
+
doSample=False,
|
|
296
|
+
temperature=0.6,
|
|
297
|
+
topK=-1,
|
|
298
|
+
topP=0.9,
|
|
299
|
+
repetitionPenalty=1.0,
|
|
300
|
+
noRepeatNgramSize=3,
|
|
301
|
+
ignoreTokenIds=[],
|
|
302
|
+
beamSize=1,
|
|
303
|
+
maxInputLength=4096,
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
@staticmethod
|
|
307
|
+
def loadSavedModel(folder, spark_session, use_openvino=False):
|
|
308
|
+
"""Loads a locally saved model.
|
|
309
|
+
|
|
310
|
+
Parameters
|
|
311
|
+
----------
|
|
312
|
+
folder : str
|
|
313
|
+
Folder of the saved model
|
|
314
|
+
spark_session : pyspark.sql.SparkSession
|
|
315
|
+
The current SparkSession
|
|
316
|
+
|
|
317
|
+
Returns
|
|
318
|
+
-------
|
|
319
|
+
Gemma3ForMultiModal
|
|
320
|
+
The restored model
|
|
321
|
+
"""
|
|
322
|
+
from sparknlp.internal import _Gemma3ForMultiModalLoader
|
|
323
|
+
jModel = _Gemma3ForMultiModalLoader(folder, spark_session._jsparkSession, use_openvino)._java_obj
|
|
324
|
+
return Gemma3ForMultiModal(java_model=jModel)
|
|
325
|
+
|
|
326
|
+
@staticmethod
|
|
327
|
+
def pretrained(name="gemma3_4b_it_int4", lang="en", remote_loc=None):
|
|
328
|
+
"""Downloads and loads a pretrained model.
|
|
329
|
+
|
|
330
|
+
Parameters
|
|
331
|
+
----------
|
|
332
|
+
name : str, optional
|
|
333
|
+
Name of the pretrained model, by default "gemma3_4b_it_int4"
|
|
334
|
+
lang : str, optional
|
|
335
|
+
Language of the pretrained model, by default "en"
|
|
336
|
+
remote_loc : str, optional
|
|
337
|
+
Optional remote address of the resource, by default None. Will use
|
|
338
|
+
Spark NLPs repositories otherwise.
|
|
339
|
+
|
|
340
|
+
Returns
|
|
341
|
+
-------
|
|
342
|
+
Gemma3ForMultiModal
|
|
343
|
+
The restored model
|
|
344
|
+
"""
|
|
345
|
+
from sparknlp.pretrained import ResourceDownloader
|
|
346
|
+
return ResourceDownloader.downloadModel(Gemma3ForMultiModal, name, lang, remote_loc)
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
from sparknlp.common import *
|
|
2
|
+
|
|
3
|
+
class InternVLForMultiModal(AnnotatorModel,
|
|
4
|
+
HasBatchedAnnotateImage,
|
|
5
|
+
HasImageFeatureProperties,
|
|
6
|
+
HasEngine,
|
|
7
|
+
HasGeneratorProperties):
|
|
8
|
+
"""
|
|
9
|
+
InternVLForMultiModal can load InternVL Vision models for visual question answering.
|
|
10
|
+
The model consists of a vision encoder, a text encoder, a text decoder and a model merger.
|
|
11
|
+
The vision encoder will encode the input image, the text encoder will encode the input text,
|
|
12
|
+
the model merger will merge the image and text embeddings, and the text decoder will output the answer.
|
|
13
|
+
|
|
14
|
+
InternVL 2.5 is an advanced multimodal large language model (MLLM) series that builds upon InternVL 2.0,
|
|
15
|
+
maintaining its core model architecture while introducing significant enhancements in training and testing
|
|
16
|
+
strategies as well as data quality. Key features include:
|
|
17
|
+
- Large context window support
|
|
18
|
+
- Multilingual support
|
|
19
|
+
- Multimodal capabilities handling both text and image inputs
|
|
20
|
+
- Optimized for deployment with int4 quantization
|
|
21
|
+
|
|
22
|
+
Pretrained models can be loaded with :meth:`.pretrained` of the companion object:
|
|
23
|
+
>>> visualQA = InternVLForMultiModal.pretrained() \\
|
|
24
|
+
... .setInputCols("image_assembler") \\
|
|
25
|
+
... .setOutputCol("answer")
|
|
26
|
+
|
|
27
|
+
The default model is `"internvl2_5_1b_int4"`, if no name is provided.
|
|
28
|
+
For available pretrained models, refer to the `Models Hub
|
|
29
|
+
<https://sparknlp.org/models?task=Question+Answering>`__.
|
|
30
|
+
|
|
31
|
+
====================== ======================
|
|
32
|
+
Input Annotation types Output Annotation type
|
|
33
|
+
====================== ======================
|
|
34
|
+
``IMAGE`` ``DOCUMENT``
|
|
35
|
+
====================== ======================
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
batchSize : int, optional
|
|
40
|
+
Batch size. Larger values allow faster processing but require more memory,
|
|
41
|
+
by default 1.
|
|
42
|
+
maxSentenceLength : int, optional
|
|
43
|
+
Maximum sentence length to process, by default 4096.
|
|
44
|
+
|
|
45
|
+
Examples
|
|
46
|
+
--------
|
|
47
|
+
>>> import sparknlp
|
|
48
|
+
>>> from sparknlp.base import *
|
|
49
|
+
>>> from sparknlp.annotator import *
|
|
50
|
+
>>> from pyspark.ml import Pipeline
|
|
51
|
+
>>> from pyspark.sql.functions import lit
|
|
52
|
+
>>> image_df = spark.read.format("image").load(path=images_path)
|
|
53
|
+
>>> test_df = image_df.withColumn(
|
|
54
|
+
... "text",
|
|
55
|
+
... lit("<|im_start|><image>\\nDescribe this image in detail.<|im_end|><|im_start|>assistant\\n")
|
|
56
|
+
... )
|
|
57
|
+
>>> imageAssembler = ImageAssembler() \\
|
|
58
|
+
... .setInputCol("image") \\
|
|
59
|
+
... .setOutputCol("image_assembler")
|
|
60
|
+
>>> visualQA = InternVLForMultiModal.pretrained() \\
|
|
61
|
+
... .setInputCols("image_assembler") \\
|
|
62
|
+
... .setOutputCol("answer")
|
|
63
|
+
>>> pipeline = Pipeline().setStages([
|
|
64
|
+
... imageAssembler,
|
|
65
|
+
... visualQA
|
|
66
|
+
... ])
|
|
67
|
+
|
|
68
|
+
>>> result = pipeline.fit(test_df).transform(test_df)
|
|
69
|
+
>>> result.select("image_assembler.origin", "answer.result").show(truncate=False)
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
name = "InternVLForMultiModal"
|
|
73
|
+
|
|
74
|
+
inputAnnotatorTypes = [AnnotatorType.IMAGE]
|
|
75
|
+
|
|
76
|
+
outputAnnotatorType = AnnotatorType.DOCUMENT
|
|
77
|
+
|
|
78
|
+
minOutputLength = Param(Params._dummy(), "minOutputLength", "Minimum length of the sequence to be generated",
|
|
79
|
+
typeConverter=TypeConverters.toInt)
|
|
80
|
+
|
|
81
|
+
maxOutputLength = Param(Params._dummy(), "maxOutputLength", "Maximum length of output text",
|
|
82
|
+
typeConverter=TypeConverters.toInt)
|
|
83
|
+
|
|
84
|
+
doSample = Param(Params._dummy(), "doSample", "Whether or not to use sampling; use greedy decoding otherwise",
|
|
85
|
+
typeConverter=TypeConverters.toBoolean)
|
|
86
|
+
|
|
87
|
+
temperature = Param(Params._dummy(), "temperature", "The value used to module the next token probabilities",
|
|
88
|
+
typeConverter=TypeConverters.toFloat)
|
|
89
|
+
|
|
90
|
+
topK = Param(Params._dummy(), "topK",
|
|
91
|
+
"The number of highest probability vocabulary tokens to keep for top-k-filtering",
|
|
92
|
+
typeConverter=TypeConverters.toInt)
|
|
93
|
+
|
|
94
|
+
topP = Param(Params._dummy(), "topP",
|
|
95
|
+
"If set to float < 1, only the most probable tokens with probabilities that add up to ``top_p`` or higher are kept for generation",
|
|
96
|
+
typeConverter=TypeConverters.toFloat)
|
|
97
|
+
|
|
98
|
+
repetitionPenalty = Param(Params._dummy(), "repetitionPenalty",
|
|
99
|
+
"The parameter for repetition penalty. 1.0 means no penalty. See `this paper <https://arxiv.org/pdf/1909.05858.pdf>`__ for more details",
|
|
100
|
+
typeConverter=TypeConverters.toFloat)
|
|
101
|
+
|
|
102
|
+
noRepeatNgramSize = Param(Params._dummy(), "noRepeatNgramSize",
|
|
103
|
+
"If set to int > 0, all ngrams of that size can only occur once",
|
|
104
|
+
typeConverter=TypeConverters.toInt)
|
|
105
|
+
|
|
106
|
+
ignoreTokenIds = Param(Params._dummy(), "ignoreTokenIds",
|
|
107
|
+
"A list of token ids which are ignored in the decoder's output",
|
|
108
|
+
typeConverter=TypeConverters.toListInt)
|
|
109
|
+
|
|
110
|
+
beamSize = Param(Params._dummy(), "beamSize",
|
|
111
|
+
"The Number of beams for beam search.",
|
|
112
|
+
typeConverter=TypeConverters.toInt)
|
|
113
|
+
|
|
114
|
+
def setMaxSentenceSize(self, value):
|
|
115
|
+
"""Sets Maximum sentence length that the annotator will process, by
|
|
116
|
+
default 4096.
|
|
117
|
+
Parameters
|
|
118
|
+
----------
|
|
119
|
+
value : int
|
|
120
|
+
Maximum sentence length that the annotator will process
|
|
121
|
+
"""
|
|
122
|
+
return self._set(maxSentenceLength=value)
|
|
123
|
+
|
|
124
|
+
def setIgnoreTokenIds(self, value):
|
|
125
|
+
"""A list of token ids which are ignored in the decoder's output.
|
|
126
|
+
Parameters
|
|
127
|
+
----------
|
|
128
|
+
value : List[int]
|
|
129
|
+
The words to be filtered out
|
|
130
|
+
"""
|
|
131
|
+
return self._set(ignoreTokenIds=value)
|
|
132
|
+
|
|
133
|
+
def setMinOutputLength(self, value):
|
|
134
|
+
"""Sets minimum length of the sequence to be generated.
|
|
135
|
+
Parameters
|
|
136
|
+
----------
|
|
137
|
+
value : int
|
|
138
|
+
Minimum length of the sequence to be generated
|
|
139
|
+
"""
|
|
140
|
+
return self._set(minOutputLength=value)
|
|
141
|
+
|
|
142
|
+
def setMaxOutputLength(self, value):
|
|
143
|
+
"""Sets maximum length of output text.
|
|
144
|
+
Parameters
|
|
145
|
+
----------
|
|
146
|
+
value : int
|
|
147
|
+
Maximum length of output text
|
|
148
|
+
"""
|
|
149
|
+
return self._set(maxOutputLength=value)
|
|
150
|
+
|
|
151
|
+
def setDoSample(self, value):
|
|
152
|
+
"""Sets whether or not to use sampling, use greedy decoding otherwise.
|
|
153
|
+
Parameters
|
|
154
|
+
----------
|
|
155
|
+
value : bool
|
|
156
|
+
Whether or not to use sampling; use greedy decoding otherwise
|
|
157
|
+
"""
|
|
158
|
+
return self._set(doSample=value)
|
|
159
|
+
|
|
160
|
+
def setTemperature(self, value):
|
|
161
|
+
"""Sets the value used to module the next token probabilities.
|
|
162
|
+
Parameters
|
|
163
|
+
----------
|
|
164
|
+
value : float
|
|
165
|
+
The value used to module the next token probabilities
|
|
166
|
+
"""
|
|
167
|
+
return self._set(temperature=value)
|
|
168
|
+
|
|
169
|
+
def setTopK(self, value):
|
|
170
|
+
"""Sets the number of highest probability vocabulary tokens to keep for
|
|
171
|
+
top-k-filtering.
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
value : int
|
|
175
|
+
Number of highest probability vocabulary tokens to keep
|
|
176
|
+
"""
|
|
177
|
+
return self._set(topK=value)
|
|
178
|
+
|
|
179
|
+
def setTopP(self, value):
|
|
180
|
+
"""Sets the top cumulative probability for vocabulary tokens.
|
|
181
|
+
If set to float < 1, only the most probable tokens with probabilities
|
|
182
|
+
that add up to ``topP`` or higher are kept for generation.
|
|
183
|
+
Parameters
|
|
184
|
+
----------
|
|
185
|
+
value : float
|
|
186
|
+
Cumulative probability for vocabulary tokens
|
|
187
|
+
"""
|
|
188
|
+
return self._set(topP=value)
|
|
189
|
+
|
|
190
|
+
def setRepetitionPenalty(self, value):
|
|
191
|
+
"""Sets the parameter for repetition penalty. 1.0 means no penalty.
|
|
192
|
+
Parameters
|
|
193
|
+
----------
|
|
194
|
+
value : float
|
|
195
|
+
The repetition penalty
|
|
196
|
+
References
|
|
197
|
+
----------
|
|
198
|
+
See `Ctrl: A Conditional Transformer Language Model For Controllable
|
|
199
|
+
Generation <https://arxiv.org/pdf/1909.05858.pdf>`__ for more details.
|
|
200
|
+
"""
|
|
201
|
+
return self._set(repetitionPenalty=value)
|
|
202
|
+
|
|
203
|
+
def setNoRepeatNgramSize(self, value):
|
|
204
|
+
"""Sets size of n-grams that can only occur once.
|
|
205
|
+
If set to int > 0, all ngrams of that size can only occur once.
|
|
206
|
+
Parameters
|
|
207
|
+
----------
|
|
208
|
+
value : int
|
|
209
|
+
N-gram size can only occur once
|
|
210
|
+
"""
|
|
211
|
+
return self._set(noRepeatNgramSize=value)
|
|
212
|
+
|
|
213
|
+
def setBeamSize(self, value):
|
|
214
|
+
"""Sets the number of beam size for beam search, by default `1`.
|
|
215
|
+
Parameters
|
|
216
|
+
----------
|
|
217
|
+
value : int
|
|
218
|
+
Number of beam size for beam search
|
|
219
|
+
"""
|
|
220
|
+
return self._set(beamSize=value)
|
|
221
|
+
|
|
222
|
+
@keyword_only
|
|
223
|
+
def __init__(self, classname="com.johnsnowlabs.nlp.annotators.cv.InternVLForMultiModal",
|
|
224
|
+
java_model=None):
|
|
225
|
+
super(InternVLForMultiModal, self).__init__(
|
|
226
|
+
classname=classname,
|
|
227
|
+
java_model=java_model
|
|
228
|
+
)
|
|
229
|
+
self._setDefault(
|
|
230
|
+
batchSize=1,
|
|
231
|
+
minOutputLength=0,
|
|
232
|
+
maxOutputLength=20,
|
|
233
|
+
doSample=False,
|
|
234
|
+
temperature=0.6,
|
|
235
|
+
topK=-1,
|
|
236
|
+
topP=0.9,
|
|
237
|
+
repetitionPenalty=1.0,
|
|
238
|
+
noRepeatNgramSize=3,
|
|
239
|
+
ignoreTokenIds=[],
|
|
240
|
+
beamSize=1
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
@staticmethod
|
|
244
|
+
def loadSavedModel(folder, spark_session, use_openvino=False):
|
|
245
|
+
"""Loads a locally saved model.
|
|
246
|
+
Parameters
|
|
247
|
+
----------
|
|
248
|
+
folder : str
|
|
249
|
+
Folder of the saved model
|
|
250
|
+
spark_session : pyspark.sql.SparkSession
|
|
251
|
+
The current SparkSession
|
|
252
|
+
Returns
|
|
253
|
+
-------
|
|
254
|
+
InternVLForMultiModal
|
|
255
|
+
The restored model
|
|
256
|
+
"""
|
|
257
|
+
from sparknlp.internal import _InternVLForMultiModalLoader
|
|
258
|
+
jModel = _InternVLForMultiModalLoader(folder, spark_session._jsparkSession, use_openvino)._java_obj
|
|
259
|
+
return InternVLForMultiModal(java_model=jModel)
|
|
260
|
+
|
|
261
|
+
@staticmethod
|
|
262
|
+
def pretrained(name="internvl2_5_1b_int4", lang="en", remote_loc=None):
|
|
263
|
+
"""Downloads and loads a pretrained model.
|
|
264
|
+
Parameters
|
|
265
|
+
----------
|
|
266
|
+
name : str, optional
|
|
267
|
+
Name of the pretrained model, by default
|
|
268
|
+
"internvl2_5_1b_int4"
|
|
269
|
+
lang : str, optional
|
|
270
|
+
Language of the pretrained model, by default "en"
|
|
271
|
+
remote_loc : str, optional
|
|
272
|
+
Optional remote address of the resource, by default None. Will use
|
|
273
|
+
Spark NLPs repositories otherwise.
|
|
274
|
+
Returns
|
|
275
|
+
-------
|
|
276
|
+
InternVLForMultiModal
|
|
277
|
+
The restored model
|
|
278
|
+
"""
|
|
279
|
+
from sparknlp.pretrained import ResourceDownloader
|
|
280
|
+
return ResourceDownloader.downloadModel(InternVLForMultiModal, name, lang, remote_loc)
|