sparknlp.common.properties#
Contains classes for Annotator properties.
Module Contents#
Classes#
Components that take parameters. This also provides an internal |
|
- class HasCaseSensitiveProperties[source]#
- class HasClsTokenProperties[source]#
- class HasClassifierActivationProperties[source]#
-
- setActivation(value)[source]#
Sets whether to calculate logits via Softmax or Sigmoid. Default is Softmax
- Parameters:
- valuestr
Whether to calculate logits via Softmax or Sigmoid. Default is Softmax
- getActivation()[source]#
Gets whether to calculate logits via Softmax or Sigmoid. Default is Softmax
- Returns:
- str
Whether to calculate logits via Softmax or Sigmoid. Default is Softmax
- setMultilabel(value)[source]#
- Set whether or not the result should be multi-class (the sum of all probabilities is 1.0) or
multi-label (each label has a probability between 0.0 to 1.0). Default is False i.e. multi-class
- Parameters:
- valuebool
Whether or not the result should be multi-class (the sum of all probabilities is 1.0) or multi-label (each label has a probability between 0.0 to 1.0). Default is False i.e. multi-class
- getMultilabel()[source]#
- Gets whether or not the result should be multi-class (the sum of all probabilities is 1.0) or
multi-label (each label has a probability between 0.0 to 1.0). Default is False i.e. multi-class
- Parameters:
- valuebool
Whether or not the result should be multi-class (the sum of all probabilities is 1.0) or multi-label (each label has a probability between 0.0 to 1.0). Default is False i.e. multi-class
- setThreshold(value)[source]#
- Set the threshold to determine which logits are considered to be positive or negative.
(Default: 0.5). The value should be between 0.0 and 1.0. Changing the threshold value will affect the resulting labels and can be used to adjust the balance between precision and recall in the classification process.
- Parameters:
- valuefloat
The threshold to determine which logits are considered to be positive or negative. (Default: 0.5). The value should be between 0.0 and 1.0. Changing the threshold value will affect the resulting labels and can be used to adjust the balance between precision and recall in the classification process.
- class HasEmbeddingsProperties[source]#
Components that take parameters. This also provides an internal param map to store parameter values attached to the instance.
New in version 1.3.0.
- class HasEnableCachingProperties[source]#
- class HasImageFeatureProperties[source]#
-
- setDoNormalize(value)[source]#
- Parameters:
- valueBoolean
Whether to normalize the input with mean and standard deviation
- setFeatureExtractorType(value)[source]#
- Parameters:
- valuestr
Name of model’s architecture for feature extraction
- setImageStd(value)[source]#
- Parameters:
- valueList[float]
The sequence of standard deviations for each channel, to be used when normalizing images
- setImageMean(value)[source]#
- Parameters:
- valueList[float]
The sequence of means for each channel, to be used when normalizing images
- class HasRescaleFactor[source]#
- class HasAudioFeatureProperties[source]#
- class HasEngine[source]#
-
- classmethod pretrainedEngine(name: str = 'default', lang: str = 'en', remote_loc: str = None, engine='onnx')[source]#
Downloads and loads a pretrained model.
- Parameters:
- namestr, optional
The name of the pretrained model, by default “default”
- langstr, optional
The language of the pretrained model, by default “en”
- remote_locstr, optional
Remote location of the model, by default None
- enginestr, optional
The Deep Learning engine used for this model, by default “onnx”
- Returns:
- AnnotatorModel
Pretrained model
- class HasMaxSentenceLengthLimit[source]#
-
- setMaxSentenceLength(value)[source]#
Sets max sentence length to process.
Note that a maximum limit exists depending on the model. If you are working with long single sequences, consider splitting up the input first with another annotator e.g. SentenceDetector.
- Parameters:
- valueint
Max sentence length to process
- class HasGeneratorProperties[source]#
-
- setTask(value)[source]#
Sets the transformer’s task, e.g.
summarize:.- Parameters:
- valuestr
The transformer’s task
- setMinOutputLength(value)[source]#
Sets minimum length of the sequence to be generated.
- Parameters:
- valueint
Minimum length of the sequence to be generated
- setMaxOutputLength(value)[source]#
Sets maximum length of output text.
- Parameters:
- valueint
Maximum length of output text
- setDoSample(value)[source]#
Sets whether or not to use sampling, use greedy decoding otherwise.
- Parameters:
- valuebool
Whether or not to use sampling; use greedy decoding otherwise
- setTemperature(value)[source]#
Sets the value used to module the next token probabilities.
- Parameters:
- valuefloat
The value used to module the next token probabilities
- setTopK(value)[source]#
Sets the number of highest probability vocabulary tokens to keep for top-k-filtering.
- Parameters:
- valueint
Number of highest probability vocabulary tokens to keep
- setTopP(value)[source]#
Sets the top cumulative probability for vocabulary tokens.
If set to float < 1, only the most probable tokens with probabilities that add up to
topPor higher are kept for generation.- Parameters:
- valuefloat
Cumulative probability for vocabulary tokens
- setRepetitionPenalty(value)[source]#
Sets the parameter for repetition penalty. 1.0 means no penalty.
- Parameters:
- valuefloat
The repetition penalty
References
See Ctrl: A Conditional Transformer Language Model For Controllable Generation for more details.
- setNoRepeatNgramSize(value)[source]#
Sets size of n-grams that can only occur once.
If set to int > 0, all ngrams of that size can only occur once.
- Parameters:
- valueint
N-gram size can only occur once
- class HasLlamaCppProperties[source]#
-
- setNThreadsBatch(nThreadsBatch: int)[source]#
Set the number of threads to use during batch and prompt processing
- setNBatch(nBatch: int)[source]#
Set the logical batch size for prompt processing (must be >=32 to use BLAS)
- setNUbatch(nUbatch: int)[source]#
Set the physical batch size for prompt processing (must be >=32 to use BLAS)
- setNGpuLayers(nGpuLayers: int)[source]#
Set the number of layers to store in VRAM (-1 - use default)
- setNGpuLayersDraft(nGpuLayersDraft: int)[source]#
Set the number of layers to store in VRAM for the draft model (-1 - use default)
- setRopeFreqBase(ropeFreqBase: float)[source]#
Set the RoPE base frequency, used by NTK-aware scaling
- setRopeFreqScale(ropeFreqScale: float)[source]#
Set the RoPE frequency scaling factor, expands context by a factor of 1/N
- setDefragmentationThreshold(defragmentationThreshold: float)[source]#
Set the KV cache defragmentation threshold
- setNumaStrategy(numaStrategy: str)[source]#
Set optimization strategies that help on some NUMA systems (if available)
Possible values:
DISABLED: No NUMA optimizations
DISTRIBUTE: spread execution evenly over all
ISOLATE: only spawn threads on CPUs on the node that execution started on
NUMA_CTL: use the CPU map provided by numactl
MIRROR: Mirrors the model across NUMA nodes
- setRopeScalingType(ropeScalingType: str)[source]#
Set the RoPE frequency scaling method, defaults to linear unless specified by the model.
Possible values:
NONE: Don’t use any scaling
LINEAR: Linear scaling
YARN: YaRN RoPE scaling
- setPoolingType(poolingType: str)[source]#
Set the pooling type for embeddings, use model default if unspecified
Possible values:
MEAN: Mean Pooling
CLS: CLS Pooling
LAST: Last token pooling
RANK: For reranked models
- setUseMmap(useMmap: bool)[source]#
Whether to use memory-map model (faster load but may increase pageouts if not using mlock)
- setUseMlock(useMlock: bool)[source]#
Whether to force the system to keep model in RAM rather than swapping or compressing
- setDynamicTemperatureRange(dynamicTemperatureRange: float)[source]#
Set the dynamic temperature range
- setDynamicTemperatureExponent(dynamicTemperatureExponent: float)[source]#
Set the dynamic temperature exponent
- setNProbs(nProbs: int)[source]#
Set the amount top tokens probabilities to output if greater than 0.
- setMinKeep(minKeep: int)[source]#
Set the amount of tokens the samplers should return at least (0 = disabled)
- setPenaltyPrompt(penaltyPrompt: str)[source]#
Override which part of the prompt is penalized for repetition.
- setIgnoreEos(ignoreEos: bool)[source]#
Set whether to ignore end of stream token and continue generating (implies –logit-bias 2-inf)
- setDisableTokenIds(disableTokenIds: List[int])[source]#
Set the token ids to disable in the completion
- setStopStrings(stopStrings: List[str])[source]#
Set strings upon seeing which token generation is stopped
- setSamplers(samplers: List[str])[source]#
Set which samplers to use for token generation in the given order
- setUseChatTemplate(useChatTemplate: bool)[source]#
Set whether generate should apply a chat template
- setNParallel(nParallel: int)[source]#
Sets the number of parallel processes for decoding. This is an alias for setBatchSize.