|
| 1 | +--- |
| 2 | +layout: model |
| 3 | +title: LLaVA v1.5 7B Q4 GGUF |
| 4 | +author: John Snow Labs |
| 5 | +name: llava_v1.5_7b_Q4_0_gguf |
| 6 | +date: 2025-01-18 |
| 7 | +tags: [gguf, llamacpp, llava, en, quantized, open_source] |
| 8 | +task: Image Captioning |
| 9 | +language: en |
| 10 | +edition: Spark NLP 6.0.0 |
| 11 | +spark_version: 3.0 |
| 12 | +supported: true |
| 13 | +engine: llamacpp |
| 14 | +annotator: AutoGGUFVisionModel |
| 15 | +article_header: |
| 16 | + type: cover |
| 17 | +use_language_switcher: "Python-Scala-Java" |
| 18 | +--- |
| 19 | + |
| 20 | +## Description |
| 21 | + |
| 22 | +LLaVA is an open-source chatbot trained by fine-tuning LLaMA/Vicuna on GPT-generated multimodal instruction-following data. It is an auto-regressive language model, based on the transformer architecture. |
| 23 | + |
| 24 | +Originally from https://huggingface.co/Mozilla/llava-v1.5-7b-llamafile |
| 25 | + |
| 26 | +## Predicted Entities |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +{:.btn-box} |
| 31 | +<button class="button button-orange" disabled>Live Demo</button> |
| 32 | +<button class="button button-orange" disabled>Open in Colab</button> |
| 33 | +[Download](https://s3.amazonaws.com/auxdata.johnsnowlabs.com/public/models/llava_v1.5_7b_Q4_0_gguf_en_6.0.0_3.0_1737207768652.zip){:.button.button-orange.button-orange-trans.arr.button-icon} |
| 34 | +[Copy S3 URI](s3://auxdata.johnsnowlabs.com/public/models/llava_v1.5_7b_Q4_0_gguf_en_6.0.0_3.0_1737207768652.zip){:.button.button-orange.button-orange-trans.button-icon.button-copy-s3} |
| 35 | + |
| 36 | +## How to use |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +<div class="tabs-box" markdown="1"> |
| 41 | +{% include programmingLanguageSelectScalaPythonNLU.html %} |
| 42 | +```python |
| 43 | +import sparknlp |
| 44 | +from sparknlp.base import * |
| 45 | +from sparknlp.annotator import * |
| 46 | +from pyspark.ml import Pipeline |
| 47 | +from pyspark.sql.functions import lit |
| 48 | + |
| 49 | +documentAssembler = DocumentAssembler() \ |
| 50 | + .setInputCol("caption") \ |
| 51 | + .setOutputCol("caption_document") |
| 52 | +imageAssembler = ImageAssembler() \ |
| 53 | + .setInputCol("image") \ |
| 54 | + .setOutputCol("image_assembler") |
| 55 | + |
| 56 | +imagesPath = "src/test/resources/image/" |
| 57 | +data = ImageAssembler \ |
| 58 | + .loadImagesAsBytes(spark, imagesPath) \ |
| 59 | + .withColumn("caption", lit("Caption this image.")) # Add a caption to each image. |
| 60 | + |
| 61 | +nPredict = 40 |
| 62 | +model = AutoGGUFVisionModel.pretrained() \ |
| 63 | + .setInputCols(["caption_document", "image_assembler"]) \ |
| 64 | + .setOutputCol("completions") \ |
| 65 | + .setBatchSize(4) \ |
| 66 | + .setNGpuLayers(99) \ |
| 67 | + .setNCtx(4096) \ |
| 68 | + .setMinKeep(0) \ |
| 69 | + .setMinP(0.05) \ |
| 70 | + .setNPredict(nPredict) \ |
| 71 | + .setNProbs(0) \ |
| 72 | + .setPenalizeNl(False) \ |
| 73 | + .setRepeatLastN(256) \ |
| 74 | + .setRepeatPenalty(1.18) \ |
| 75 | + .setStopStrings(["</s>", "Llama:", "User:"]) \ |
| 76 | + .setTemperature(0.05) \ |
| 77 | + .setTfsZ(1) \ |
| 78 | + .setTypicalP(1) \ |
| 79 | + .setTopK(40) \ |
| 80 | + .setTopP(0.95) |
| 81 | + |
| 82 | +pipeline = Pipeline().setStages([documentAssembler, imageAssembler, model]) |
| 83 | +pipeline.fit(data).transform(data) \ |
| 84 | + .selectExpr("reverse(split(image.origin, '/'))[0] as image_name", "completions.result") \ |
| 85 | + .show(truncate = False) |
| 86 | + |
| 87 | + |
| 88 | +``` |
| 89 | +```scala |
| 90 | +import com.johnsnowlabs.nlp.ImageAssembler |
| 91 | +import com.johnsnowlabs.nlp.annotator._ |
| 92 | +import com.johnsnowlabs.nlp.base._ |
| 93 | +import org.apache.spark.ml.Pipeline |
| 94 | +import org.apache.spark.sql.DataFrame |
| 95 | +import org.apache.spark.sql.functions.lit |
| 96 | + |
| 97 | +val documentAssembler = new DocumentAssembler() |
| 98 | + .setInputCol("caption") |
| 99 | + .setOutputCol("caption_document") |
| 100 | + |
| 101 | +val imageAssembler = new ImageAssembler() |
| 102 | + .setInputCol("image") |
| 103 | + .setOutputCol("image_assembler") |
| 104 | + |
| 105 | +val imagesPath = "src/test/resources/image/" |
| 106 | +val data: DataFrame = ImageAssembler |
| 107 | + .loadImagesAsBytes(ResourceHelper.spark, imagesPath) |
| 108 | + .withColumn("caption", lit("Caption this image.")) // Add a caption to each image. |
| 109 | + |
| 110 | +val nPredict = 40 |
| 111 | +val model = AutoGGUFVisionModel.pretrained() |
| 112 | + .setInputCols("caption_document", "image_assembler") |
| 113 | + .setOutputCol("completions") |
| 114 | + .setBatchSize(4) |
| 115 | + .setNGpuLayers(99) |
| 116 | + .setNCtx(4096) |
| 117 | + .setMinKeep(0) |
| 118 | + .setMinP(0.05f) |
| 119 | + .setNPredict(nPredict) |
| 120 | + .setNProbs(0) |
| 121 | + .setPenalizeNl(false) |
| 122 | + .setRepeatLastN(256) |
| 123 | + .setRepeatPenalty(1.18f) |
| 124 | + .setStopStrings(Array("</s>", "Llama:", "User:")) |
| 125 | + .setTemperature(0.05f) |
| 126 | + .setTfsZ(1) |
| 127 | + .setTypicalP(1) |
| 128 | + .setTopK(40) |
| 129 | + .setTopP(0.95f) |
| 130 | + |
| 131 | +val pipeline = new Pipeline().setStages(Array(documentAssembler, imageAssembler, model)) |
| 132 | +pipeline |
| 133 | + .fit(data) |
| 134 | + .transform(data) |
| 135 | + .selectExpr("reverse(split(image.origin, '/'))[0] as image_name", "completions.result") |
| 136 | + .show(truncate = false) |
| 137 | + |
| 138 | +``` |
| 139 | +</div> |
| 140 | + |
| 141 | +## Results |
| 142 | + |
| 143 | +```bash |
| 144 | ++-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 145 | +|image_name |result | |
| 146 | ++-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 147 | +|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] | |
| 148 | +|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] | |
| 149 | +|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] | |
| 150 | +|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] | |
| 151 | +|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] | |
| 152 | +|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] | |
| 153 | +|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.] | |
| 154 | +|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]| |
| 155 | +|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] | |
| 156 | +|ox.JPEG |[ A large bull with horns is standing in a grassy field.] | |
| 157 | ++-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ |
| 158 | +``` |
| 159 | +
|
| 160 | +{:.model-param} |
| 161 | +## Model Information |
| 162 | +
|
| 163 | +{:.table-model} |
| 164 | +|---|---| |
| 165 | +|Model Name:|llava_v1.5_7b_Q4_0_gguf| |
| 166 | +|Compatibility:|Spark NLP 6.0.0+| |
| 167 | +|License:|Open Source| |
| 168 | +|Edition:|Official| |
| 169 | +|Input Labels:|[caption_document, image_assembler]| |
| 170 | +|Output Labels:|[completions]| |
| 171 | +|Language:|en| |
| 172 | +|Size:|4.2 GB| |
0 commit comments