Documentation
¶
Index ¶
- Variables
- func CUDAAvailable() bool
- func CUDADeviceCount() int
- func ClearError()
- func Ct2ClearError()
- func Ct2CudaAvailable() bool
- func Ct2CudaDeviceCount() int32
- func Ct2FloatsFree(arr *Ct2floatarray)
- func Ct2GenerationResultFree(result *Ct2generationresult)
- func Ct2GeneratorFree(generator Ct2generator)
- func Ct2GeneratorGenerate(generator Ct2generator, prompt uintptr, promptLength uint64, ...) int32
- func Ct2GeneratorGenerateBatch(generator Ct2generator, prompts string, promptLengths uintptr, ...) int32
- func Ct2GetLastError() string
- func Ct2StorageFree(storage Ct2storageview)
- func Ct2StorageGetShape(storage Ct2storageview, shape uintptr, ndims uintptr) int32
- func Ct2StorageSize(storage Ct2storageview) int64
- func Ct2StorageToFloat(storage Ct2storageview, buffer uintptr) int32
- func Ct2StringsFree(arr *Ct2stringarray)
- func Ct2TranslationResultFree(result *Ct2translationresult)
- func Ct2TranslatorFree(translator Ct2translator)
- func Ct2TranslatorTranslate(translator Ct2translator, source uintptr, sourceLength uint64, ...) int32
- func Ct2TranslatorTranslateBatch(translator Ct2translator, sources string, sourceLengths uintptr, ...) int32
- func Ct2Version() string
- func Ct2WhisperDetectLanguage(whisper Ct2whisper, features Ct2storageview, languages *Ct2stringarray, ...) int32
- func Ct2WhisperFree(whisper Ct2whisper)
- func Ct2WhisperGenerate(whisper Ct2whisper, features Ct2storageview, prompts uintptr, ...) int32
- func Ct2WhisperIsMultilingual(whisper Ct2whisper) bool
- func Ct2WhisperNMels(whisper Ct2whisper) uint64
- func Ct2WhisperNumLanguages(whisper Ct2whisper) uint64
- func Ct2WhisperResultFree(result *Ct2whisperresult)
- func GetLastError() string
- func Load(path string) error
- func Version() string
- type ComputeType
- type Ct2computetype
- type Ct2device
- type Ct2floatarray
- type Ct2generationoptions
- type Ct2generationresult
- type Ct2generator
- type Ct2modelconfig
- type Ct2storageview
- type Ct2stringarray
- type Ct2translationoptions
- type Ct2translationresult
- type Ct2translator
- type Ct2whisper
- type Ct2whisperoptions
- type Ct2whisperresult
- type Device
- type GenerationOptions
- type GenerationResult
- type Generator
- type ModelConfig
- type StorageView
- type TranslationOptions
- type TranslationResult
- type Translator
- type Whisper
- type WhisperOptions
- type WhisperResult
Constants ¶
This section is empty.
Variables ¶
var FFITypeCt2floatarray = ffi.NewType( &ffi.TypePointer, &ffi.TypeUint64, )
var FFITypeCt2generationoptions = ffi.NewType( &ffi.TypeUint64, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeUint64, &ffi.TypeUint8, &ffi.TypeUint64, &ffi.TypeUint64, &ffi.TypeUint64, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeUint64, &ffi.TypeUint8, &ffi.TypeUint8, )
var FFITypeCt2generationresult = ffi.NewType( &ffi.TypePointer, &ffi.TypePointer, &ffi.TypeUint64, &ffi.TypePointer, &ffi.TypeUint64, )
var FFITypeCt2modelconfig = ffi.NewType( &ffi.TypePointer, &ffi.TypePointer, &ffi.TypeSint32, &ffi.TypeUint64, &ffi.TypeUint64, )
var FFITypeCt2stringarray = ffi.NewType( &ffi.TypePointer, &ffi.TypeUint64, )
var FFITypeCt2translationoptions = ffi.NewType( &ffi.TypeUint64, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeUint64, &ffi.TypeUint8, &ffi.TypeUint64, &ffi.TypeUint64, &ffi.TypeUint64, &ffi.TypeUint64, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeUint8, &ffi.TypeUint64, &ffi.TypeUint8, &ffi.TypeUint8, &ffi.TypeUint8, )
var FFITypeCt2translationresult = ffi.NewType( &ffi.TypePointer, &ffi.TypePointer, &ffi.TypeUint64, &ffi.TypePointer, &ffi.TypeUint64, )
var FFITypeCt2whisperoptions = ffi.NewType( &ffi.TypeUint64, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeFloat, &ffi.TypeUint64, &ffi.TypeUint64, &ffi.TypeUint64, &ffi.TypeFloat, &ffi.TypeUint64, &ffi.TypeUint8, &ffi.TypeUint8, &ffi.TypeUint64, &ffi.TypeUint8, )
var FFITypeCt2whisperresult = ffi.NewType( &ffi.TypePointer, &ffi.TypeUint64, &ffi.TypePointer, &ffi.TypeUint64, &ffi.TypeFloat, )
Functions ¶
func CUDADeviceCount ¶
func CUDADeviceCount() int
CUDADeviceCount returns the number of CUDA devices.
func Ct2ClearError ¶
func Ct2ClearError()
func Ct2CudaAvailable ¶
func Ct2CudaAvailable() bool
func Ct2CudaDeviceCount ¶
func Ct2CudaDeviceCount() int32
func Ct2FloatsFree ¶
func Ct2FloatsFree(arr *Ct2floatarray)
func Ct2GenerationResultFree ¶
func Ct2GenerationResultFree(result *Ct2generationresult)
func Ct2GeneratorFree ¶
func Ct2GeneratorFree(generator Ct2generator)
func Ct2GeneratorGenerate ¶
func Ct2GeneratorGenerate(generator Ct2generator, prompt uintptr, promptLength uint64, options Ct2generationoptions, resultOut *Ct2generationresult) int32
func Ct2GeneratorGenerateBatch ¶
func Ct2GeneratorGenerateBatch(generator Ct2generator, prompts string, promptLengths uintptr, numPrompts uint64, options Ct2generationoptions, results *Ct2generationresult) int32
func Ct2GetLastError ¶
func Ct2GetLastError() string
func Ct2StorageFree ¶
func Ct2StorageFree(storage Ct2storageview)
func Ct2StorageGetShape ¶
func Ct2StorageGetShape(storage Ct2storageview, shape uintptr, ndims uintptr) int32
func Ct2StorageSize ¶
func Ct2StorageSize(storage Ct2storageview) int64
func Ct2StorageToFloat ¶
func Ct2StorageToFloat(storage Ct2storageview, buffer uintptr) int32
func Ct2StringsFree ¶
func Ct2StringsFree(arr *Ct2stringarray)
func Ct2TranslationResultFree ¶
func Ct2TranslationResultFree(result *Ct2translationresult)
func Ct2TranslatorFree ¶
func Ct2TranslatorFree(translator Ct2translator)
func Ct2TranslatorTranslate ¶
func Ct2TranslatorTranslate(translator Ct2translator, source uintptr, sourceLength uint64, options Ct2translationoptions, resultOut *Ct2translationresult) int32
func Ct2TranslatorTranslateBatch ¶
func Ct2TranslatorTranslateBatch(translator Ct2translator, sources string, sourceLengths uintptr, numSources uint64, options Ct2translationoptions, results *Ct2translationresult) int32
func Ct2Version ¶
func Ct2Version() string
func Ct2WhisperDetectLanguage ¶
func Ct2WhisperDetectLanguage(whisper Ct2whisper, features Ct2storageview, languages *Ct2stringarray, probabilities *Ct2floatarray) int32
func Ct2WhisperFree ¶
func Ct2WhisperFree(whisper Ct2whisper)
func Ct2WhisperGenerate ¶
func Ct2WhisperGenerate(whisper Ct2whisper, features Ct2storageview, prompts uintptr, numPrompts uint64, options Ct2whisperoptions, resultOut *Ct2whisperresult) int32
func Ct2WhisperIsMultilingual ¶
func Ct2WhisperIsMultilingual(whisper Ct2whisper) bool
func Ct2WhisperNMels ¶
func Ct2WhisperNMels(whisper Ct2whisper) uint64
func Ct2WhisperNumLanguages ¶
func Ct2WhisperNumLanguages(whisper Ct2whisper) uint64
func Ct2WhisperResultFree ¶
func Ct2WhisperResultFree(result *Ct2whisperresult)
Types ¶
type ComputeType ¶
type ComputeType int
ComputeType represents the compute precision.
const ( ComputeDefault ComputeType = 0 ComputeAuto ComputeType = 1 ComputeFloat32 ComputeType = 2 ComputeInt8 ComputeType = 3 ComputeInt8Float32 ComputeType = 4 ComputeInt8Float16 ComputeType = 5 ComputeInt16 ComputeType = 7 ComputeFloat16 ComputeType = 8 ComputeBFloat16 ComputeType = 9 )
type Ct2computetype ¶
type Ct2computetype int32
const ( Ct2ComputeDefault Ct2computetype = 0 Ct2ComputeAuto Ct2computetype = 1 Ct2ComputeFloat32 Ct2computetype = 2 Ct2ComputeInt8 Ct2computetype = 3 Ct2ComputeInt8Float32 Ct2computetype = 4 Ct2ComputeInt8Float16 Ct2computetype = 5 Ct2ComputeInt8Bfloat16 Ct2computetype = 6 Ct2ComputeInt16 Ct2computetype = 7 Ct2ComputeFloat16 Ct2computetype = 8 Ct2ComputeBfloat16 Ct2computetype = 9 )
type Ct2floatarray ¶
type Ct2generationoptions ¶
type Ct2generationoptions struct {
BeamSize uint64
Patience float32
LengthPenalty float32
RepetitionPenalty float32
NoRepeatNgramSize uint64
DisableUnk bool
MaxLength uint64
MinLength uint64
SamplingTopk uint64
SamplingTopp float32
SamplingTemperature float32
NumHypotheses uint64
ReturnScores bool
IncludePromptInResult bool
}
func Ct2GenerationOptionsDefault ¶
func Ct2GenerationOptionsDefault() Ct2generationoptions
type Ct2generationresult ¶
type Ct2generator ¶
type Ct2generator uintptr
func Ct2GeneratorCreate ¶
func Ct2GeneratorCreate(modelPath string, config Ct2modelconfig) Ct2generator
type Ct2modelconfig ¶
type Ct2modelconfig struct {
Device Ct2device
ComputeType Ct2computetype
DeviceIndex int32
NumThreads uint64
NumReplicas uint64
}
func Ct2ModelConfigDefault ¶
func Ct2ModelConfigDefault() Ct2modelconfig
type Ct2storageview ¶
type Ct2storageview uintptr
func Ct2StorageCreateFloat ¶
func Ct2StorageCreateFloat(data uintptr, shape uintptr, ndims uint64, device Ct2device) Ct2storageview
func Ct2WhisperEncode ¶
func Ct2WhisperEncode(whisper Ct2whisper, features Ct2storageview, toCpu bool) Ct2storageview
type Ct2stringarray ¶
type Ct2translationoptions ¶
type Ct2translationoptions struct {
BeamSize uint64
Patience float32
LengthPenalty float32
CoveragePenalty float32
RepetitionPenalty float32
NoRepeatNgramSize uint64
DisableUnk bool
MaxInputLength uint64
MaxDecodingLength uint64
MinDecodingLength uint64
SamplingTopk uint64
SamplingTopp float32
SamplingTemperature float32
UseVmap bool
NumHypotheses uint64
ReturnScores bool
ReturnAttention bool
ReplaceUnknowns bool
}
func Ct2TranslationOptionsDefault ¶
func Ct2TranslationOptionsDefault() Ct2translationoptions
type Ct2translationresult ¶
type Ct2translator ¶
type Ct2translator uintptr
func Ct2TranslatorCreate ¶
func Ct2TranslatorCreate(modelPath string, config Ct2modelconfig) Ct2translator
type Ct2whisper ¶
type Ct2whisper uintptr
func Ct2WhisperCreate ¶
func Ct2WhisperCreate(modelPath string, config Ct2modelconfig) Ct2whisper
type Ct2whisperoptions ¶
type Ct2whisperoptions struct {
BeamSize uint64
Patience float32
LengthPenalty float32
RepetitionPenalty float32
NoRepeatNgramSize uint64
MaxLength uint64
SamplingTopk uint64
SamplingTemperature float32
NumHypotheses uint64
ReturnScores bool
ReturnNoSpeechProb bool
MaxInitialTimestampIndex uint64
SuppressBlank bool
}
func Ct2WhisperOptionsDefault ¶
func Ct2WhisperOptionsDefault() Ct2whisperoptions
type Ct2whisperresult ¶
type GenerationOptions ¶
type GenerationOptions struct {
BeamSize int
Patience float32
LengthPenalty float32
RepetitionPenalty float32
NoRepeatNgramSize int
DisableUnk bool
MaxLength int
MinLength int
SamplingTopK int
SamplingTopP float32
SamplingTemp float32
NumHypotheses int
ReturnScores bool
IncludePromptInResult bool
}
GenerationOptions holds options for text generation.
func DefaultGenerationOptions ¶
func DefaultGenerationOptions() GenerationOptions
DefaultGenerationOptions returns sensible defaults.
type GenerationResult ¶
GenerationResult holds the result of text generation.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator wraps a CTranslate2 generator (language model).
func NewGenerator ¶
func NewGenerator(modelPath string, config ModelConfig) (*Generator, error)
NewGenerator loads a generator model from the given path.
func (*Generator) Generate ¶
func (g *Generator) Generate(prompt []string, opts GenerationOptions) (*GenerationResult, error)
Generate generates text continuation from a prompt.
type ModelConfig ¶
type ModelConfig struct {
Device Device
ComputeType ComputeType
DeviceIndex int
NumThreads int
NumReplicas int
}
ModelConfig holds configuration for loading models.
func DefaultModelConfig ¶
func DefaultModelConfig() ModelConfig
DefaultModelConfig returns sensible default configuration.
type StorageView ¶
type StorageView struct {
// contains filtered or unexported fields
}
StorageView wraps a CTranslate2 storage view (tensor).
func NewStorageViewFloat ¶
func NewStorageViewFloat(data []float32, shape []int64, device Device) (*StorageView, error)
NewStorageViewFloat creates a storage view from float data.
func (*StorageView) Shape ¶
func (s *StorageView) Shape() ([]int64, error)
Shape returns the shape of the storage view.
func (*StorageView) Size ¶
func (s *StorageView) Size() int64
Size returns the total number of elements.
func (*StorageView) ToFloat ¶
func (s *StorageView) ToFloat() ([]float32, error)
ToFloat copies the data to a float slice.
type TranslationOptions ¶
type TranslationOptions struct {
BeamSize int
Patience float32
LengthPenalty float32
CoveragePenalty float32
RepetitionPenalty float32
NoRepeatNgramSize int
DisableUnk bool
MaxInputLength int
MaxDecodingLength int
MinDecodingLength int
SamplingTopK int
SamplingTopP float32
SamplingTemp float32
UseVMap bool
NumHypotheses int
ReturnScores bool
ReturnAttention bool
ReplaceUnknowns bool
}
TranslationOptions holds options for translation.
func DefaultTranslationOptions ¶
func DefaultTranslationOptions() TranslationOptions
DefaultTranslationOptions returns sensible defaults.
type TranslationResult ¶
TranslationResult holds the result of translation.
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator wraps a CTranslate2 translator model.
func NewTranslator ¶
func NewTranslator(modelPath string, config ModelConfig) (*Translator, error)
NewTranslator loads a translator model from the given path.
func (*Translator) Translate ¶
func (t *Translator) Translate(tokens []string, opts TranslationOptions) (*TranslationResult, error)
Translate translates a single sequence of tokens.
type Whisper ¶
type Whisper struct {
// contains filtered or unexported fields
}
Whisper wraps a CTranslate2 Whisper model.
func NewWhisper ¶
func NewWhisper(modelPath string, config ModelConfig) (*Whisper, error)
NewWhisper loads a Whisper model from the given path.
func (*Whisper) Generate ¶
func (w *Whisper) Generate(features *StorageView, prompts []string, opts WhisperOptions) (*WhisperResult, error)
Generate transcribes audio features.
func (*Whisper) IsMultilingual ¶
IsMultilingual returns whether the model supports multiple languages.
func (*Whisper) NumLanguages ¶
NumLanguages returns the number of supported languages.
type WhisperOptions ¶
type WhisperOptions struct {
BeamSize int
Patience float32
LengthPenalty float32
RepetitionPenalty float32
NoRepeatNgramSize int
MaxLength int
SamplingTopK int
SamplingTemperature float32
NumHypotheses int
ReturnScores bool
ReturnNoSpeechProb bool
MaxInitialTimestampIndex int
SuppressBlank bool
}
WhisperOptions holds generation options for Whisper.
func DefaultWhisperOptions ¶
func DefaultWhisperOptions() WhisperOptions
DefaultWhisperOptions returns sensible default options.
type WhisperResult ¶
WhisperResult holds the result of Whisper transcription.