Packages

package seq2seq

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. class MedicalEncoderDecoder extends AnnotatorModel[MedicalEncoderDecoder] with HasCaseSensitiveProperties with HasBatchedAnnotate[MedicalEncoderDecoder] with ParamsAndFeaturesWritable with WriteTensorflowModel with WriteOnnxModel with HasEngine with WriteSentencePieceModel with CheckLicense
  2. class MedicalLLM extends AutoGGUFModel with CheckLicense
  3. class MedicalSummarizer extends MedicalEncoderDecoder
  4. class MedicalTextGenerator extends AnnotatorModel[MedicalQuestionAnswering] with GPTGenerationParams with HasCaseSensitiveProperties with HasBatchedAnnotate[MedicalQuestionAnswering] with ParamsAndFeaturesWritable with WriteTensorflowModel with WriteOnnxModel with WriteSentencePieceModel with HasEngine with CheckLicense
  5. class MedicalVisionLLM extends AutoGGUFVisionModel with CheckLicense

    Multimodal annotator to generate text completions with large language models.

    Multimodal annotator to generate text completions with large language models. It supports ingesting images for captioning.

    At the moment only CLIP based models are supported.

    If the parameters are not set, the annotator will default to use the parameters provided by the model.

    This annotator expects a column of annotator type AnnotationImage for the image and Annotation for the caption. Note that the image bytes in the image annotation need to be raw image bytes without preprocessing. We provide the helper function ImageAssembler.loadImagesAsBytes to load the image bytes from a directory.

    Pretrained models can be loaded with pretrained of the companion object:

    val medicalVisionLLM = MedicalVisionLLM.pretrained()
      .setInputCols("image', "document")
      .setOutputCol("completions")

    Note

    To use GPU inference with this annotator, make sure to use the Spark NLP GPU package and set the number of GPU layers with the setNGpuLayers method.

    When using larger models, we recommend adjusting GPU usage with setNCtx and setNGpuLayers according to your hardware to avoid out-of-memory errors.

    Example

    import com.johnsnowlabs.nlp.ImageAssembler
    import com.johnsnowlabs.nlp.annotator._
    import com.johnsnowlabs.nlp.jsl.annotator._
    import com.johnsnowlabs.nlp.base._
    import org.apache.spark.ml.Pipeline
    import org.apache.spark.sql.DataFrame
    import org.apache.spark.sql.functions.lit
    
    val documentAssembler = new DocumentAssembler()
      .setInputCol("caption")
      .setOutputCol("caption_document")
    
    val imageAssembler = new ImageAssembler()
      .setInputCol("image")
      .setOutputCol("image_assembler")
    
    val imagesPath = "IMAGES_PATH"
    val data: DataFrame = ImageAssembler
      .loadImagesAsBytes(spark, imagesPath)
      .withColumn("caption", lit("Caption this image.")) // Add a caption to each image.
    
    val model = MedicalVisionLLM.pretrained()
      .setInputCols("caption_document", "image_assembler")
      .setOutputCol("completions")
      .setBatchSize(4)
      .setNGpuLayers(99)
      .setNCtx(4096)
      .setMinKeep(0)
      .setMinP(0.05f)
      .setNPredict(40)
      .setNProbs(0)
      .setPenalizeNl(false)
      .setRepeatLastN(256)
      .setRepeatPenalty(1.18f)
      .setStopStrings(Array("</s>", "Llama:", "User:"))
      .setTemperature(0.05f)
      .setTfsZ(1)
      .setTypicalP(1)
      .setTopK(40)
      .setTopP(0.95f)
    
    val pipeline = new Pipeline().setStages(Array(documentAssembler, imageAssembler, model))
    pipeline
      .fit(data)
      .transform(data)
      .selectExpr("reverse(split(image.origin, '/'))[0] as image_name", "completions.result")
      .show(truncate = false)
    +-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |image_name       |result                                                                                                                                                                                        |
    +-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |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]               |
    |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]             |
    |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]                            |
    |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] |
    |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]              |
    |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]  |
    |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.]              |
    |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]|
    |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]                                |
    |ox.JPEG          |[ A large bull with horns is standing in a grassy field.]                                                                                                                                     |
    +-----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  6. trait ReadMedicalEncoderDecoderModel[T <: MedicalEncoderDecoder] extends ReadTensorflowModel with ReadSentencePieceModel with InternalReadOnnxModel with ParamsAndFeaturesReadable[T]
  7. trait ReadMedicalLLM extends CheckLicense
  8. trait ReadMedicalMedicalTextGenerator extends ReadTensorflowModel with ReadSentencePieceModel with InternalReadOnnxModel
  9. trait ReadMedicalText2SQLModel extends ReadTensorflowModel with ReadSentencePieceModel with InternalReadOnnxModel
  10. trait ReadMedicalVisionLLM extends AnyRef
  11. trait ReadablePretrainedMedicalLLM extends ParamsAndFeaturesFallbackReadable[MedicalLLM] with HasPretrained[MedicalLLM]
  12. trait ReadablePretrainedMedicalSummarizerModel extends ParamsAndFeaturesReadable[MedicalSummarizer] with HasPretrained[MedicalSummarizer]
  13. trait ReadablePretrainedMedicalTextGenerator extends ParamsAndFeaturesReadable[MedicalTextGenerator] with HasPretrained[MedicalTextGenerator]
  14. trait ReadablePretrainedMedicalVisionLLM extends ParamsAndFeaturesFallbackReadable[MedicalVisionLLM] with HasPretrained[MedicalVisionLLM]
  15. trait ReadablePretrainedText2SQLModel extends ParamsAndFeaturesReadable[Text2SQL] with HasPretrained[Text2SQL]
  16. class Text2SQL extends MedicalTextGenerator

Value Members

  1. object MedicalEncoderDecoder extends ReadMedicalEncoderDecoderModel[MedicalEncoderDecoder] with Serializable
  2. object MedicalLLM extends ReadablePretrainedMedicalLLM with ReadMedicalLLM with Serializable

    This is the companion object of MedicalLLM.

    This is the companion object of MedicalLLM. Please refer to that class for the documentation.

  3. object MedicalSummarizer extends ReadablePretrainedMedicalSummarizerModel with ReadMedicalEncoderDecoderModel[MedicalSummarizer] with ReadSentencePieceModel with Serializable

    This is the companion object of MedicalSummarizer.

    This is the companion object of MedicalSummarizer. Please refer to that class for the documentation.

  4. object MedicalTextGenerator extends ReadablePretrainedMedicalTextGenerator with ReadMedicalMedicalTextGenerator with Serializable
  5. object MedicalVisionLLM extends ReadablePretrainedMedicalVisionLLM with ReadMedicalVisionLLM with Serializable

    This is the companion object of MedicalVisionLLM.

    This is the companion object of MedicalVisionLLM. Please refer to that class for the documentation.

  6. object ModelTypes
  7. object Text2SQL extends ReadablePretrainedText2SQLModel with ReadMedicalText2SQLModel with Serializable

Ungrouped