langdash.models package#
Submodules#
langdash.models.ctransformers module#
Classes:
|
ctransformers model. |
|
Session for ctransformers model. |
- class langdash.models.ctransformers.CTransformersModel(model_path: str | None = None, **model_kwargs)[source]#
Bases:
LLM[CTransformersSession]ctransformers model.
Classes:
alias of
CTransformersSessionMethods:
session(**kwargs)Create a new session for the given model.
- Session#
alias of
CTransformersSessionMethods:clone_state()Clone the current state of the language model.
flush_token(*a, **k)Flushes the previous token into the language model if healing is enabled.
get_vocab()Returns a mapping of token strings to their respective ids.
next_token_logits()Returns the logits for next token.
next_token_probs()Returns the probabilities for next token.
set_state(state)Set the state of the language model.
tokenize(text[, add_special_tokens])Tokenize the given text into a list of tokens.
tokenize_special(text)Tokenize the given text as a special token.
Attributes:
context_lengthReturns the context length of the model, or zero for models that don't support one.
- session(**kwargs)[source]#
Create a new session for the given model.
- Parameters:
default_infer_args (InferArgs) – Default arguments for the inference.
token_healing (bool) – Whether to enable token healing. Defaults to True.
event_handlers (Optional[LLMGenerationSessionEvents]) – Event handlers for prompt events. Defaults to None.
- Returns:
A new session object.
- class langdash.models.ctransformers.CTransformersSession(*args, **kwargs)[source]#
Bases:
TensorBasedInferWithSessionMixin,LLMGenerationSessionForRawText[CTransformersModel,LLMState]Session for ctransformers model.
Methods:
Clone the current state of the language model.
flush_token(*a, **k)Flushes the previous token into the language model if healing is enabled.
Returns a mapping of token strings to their respective ids.
Returns the logits for next token.
Returns the probabilities for next token.
set_state(state)Set the state of the language model.
tokenize(text[, add_special_tokens])Tokenize the given text into a list of tokens.
tokenize_special(text)Tokenize the given text as a special token.
Attributes:
Returns the context length of the model, or zero for models that don't support one.
- clone_state() ctransformers.llm.LLMState | None[source]#
Clone the current state of the language model.
- Returns:
The current state as an object.
- property context_length: int#
Returns the context length of the model, or zero for models that don’t support one.
- flush_token(*a, **k)[source]#
Flushes the previous token into the language model if healing is enabled.
Warning
Unexpected behavior might occur if the previous token is a “boundary” token, like the space ‘ ‘ token.
- set_state(state: ctransformers.llm.LLMState | None)[source]#
Set the state of the language model.
- Parameters:
state (Optional[T_LLMState]) – The state of the language model, or None to clear the state.
langdash.models.llama_cpp module#
Classes:
|
llama.cpp model. |
|
Session for llama.cpp model. |
- class langdash.models.llama_cpp.LlamaCppModel(model_path: str | None = None, **model_kwargs)[source]#
Bases:
LLM[LlamaCppSession]llama.cpp model.
Creates a template for the Llama language model (using the llama.cpp library).
Classes:
alias of
LlamaCppSessionMethods:
session(**kwargs)Create a new session for the given model.
- Session#
alias of
LlamaCppSessionMethods:clone_state()Clone the current state of the language model.
flush_token(*a, **k)Flushes the previous token into the language model if healing is enabled.
get_vocab()Returns a mapping of token strings to their respective ids.
next_token_logits()Returns the logits for next token.
next_token_probs()Returns the probabilities for next token.
set_state(state)Set the state of the language model.
tokenize(text[, add_special_tokens])Tokenize the given text into a list of tokens.
tokenize_special(text)Tokenize the given text as a special token.
Attributes:
context_lengthReturns the context length of the model, or zero for models that don't support one.
- session(**kwargs)[source]#
Create a new session for the given model.
- Parameters:
default_infer_args (InferArgs) – Default arguments for the inference.
token_healing (bool) – Whether to enable token healing. Defaults to True.
event_handlers (Optional[LLMGenerationSessionEvents]) – Event handlers for prompt events. Defaults to None.
- Returns:
A new session object.
- class langdash.models.llama_cpp.LlamaCppSession(*args, **kwargs)[source]#
Bases:
TensorBasedInferWithSessionMixin,LLMGenerationSessionForRawText[LlamaCppModel,LlamaState]Session for llama.cpp model.
Methods:
Clone the current state of the language model.
flush_token(*a, **k)Flushes the previous token into the language model if healing is enabled.
Returns a mapping of token strings to their respective ids.
Returns the logits for next token.
Returns the probabilities for next token.
set_state(state)Set the state of the language model.
tokenize(text[, add_special_tokens])Tokenize the given text into a list of tokens.
tokenize_special(text)Tokenize the given text as a special token.
Attributes:
Returns the context length of the model, or zero for models that don't support one.
- clone_state() llama_cpp.LlamaState | None[source]#
Clone the current state of the language model.
- Returns:
The current state as an object.
- property context_length: int#
Returns the context length of the model, or zero for models that don’t support one.
- flush_token(*a, **k)[source]#
Flushes the previous token into the language model if healing is enabled.
Warning
Unexpected behavior might occur if the previous token is a “boundary” token, like the space ‘ ‘ token.
- set_state(state: llama_cpp.LlamaState | None)[source]#
Set the state of the language model.
- Parameters:
state (Optional[T_LLMState]) – The state of the language model, or None to clear the state.
langdash.models.rwkv_cpp module#
langdash.models.sentence_transformers module#
Classes:
|
sentence_transformers embedding model. |
|
Session for sentence_transformers embedding model. |
- class langdash.models.sentence_transformers.SentenceTransformersModel(model_name: str)[source]#
Bases:
EmbeddingLLM[SentenceTransformersSession]sentence_transformers embedding model.
Classes:
alias of
SentenceTransformersSession- Session#
alias of
SentenceTransformersSessionMethods:embed(documents)Infer the embedding of a list of text.
Attributes:
embedding_sizeReturns the embedding size of the model.
- class langdash.models.sentence_transformers.SentenceTransformersSession(*args, **kwargs)[source]#
Bases:
LLMEmbeddingSession[SentenceTransformersModel]Session for sentence_transformers embedding model.
Methods:
embed(documents)Infer the embedding of a list of text.
Attributes:
Returns the embedding size of the model.
- embed(documents: List[str]) torch.Tensor[source]#
Infer the embedding of a list of text.
- Parameters:
documents (List[str]) – The text to be embedded.
- Returns:
The embedding vector of the list of text.
- property embedding_size: int#
Returns the embedding size of the model.
langdash.models.transformers module#
Classes:
|
transformers model. |
|
Session for transformers model. |
|
- class langdash.models.transformers.TransformersModel(model: str | transformers.PreTrainedModel, tokenizer: str | transformers.PreTrainedTokenizer | None = None, **model_kwargs)[source]#
Bases:
LLM[TransformersSession]transformers model.
Creates a template for a language model powered by the transformers library.
- Parameters:
model (Union[str, transformers.PreTrainedModel]) – The name of the model, or the model class itself.
tokenizer (Optional[Union[str, transformers.PreTrainedTokenizer]]) – The name of the tokenizer, or the tokenizer class itself. Defaults to None. If not set, the name of the model will be used to load the tokenizer.
Classes:
alias of
TransformersSession- Session#
alias of
TransformersSessionMethods:clone_state()Clone the current state of the language model.
get_vocab()Returns a mapping of token strings to their respective ids.
next_token_logits()Returns the logits for next token.
next_token_probs()Returns the probabilities for next token.
set_state(state)Set the state of the language model.
tokenize(text[, add_special_tokens])Tokenize the given text into a list of tokens.
Attributes:
context_lengthReturns the context length of the model, or zero for models that don't support one.
- class langdash.models.transformers.TransformersSession(*args, **kwargs)[source]#
Bases:
TensorBasedInferMixin,LLMGenerationSessionForRawText[TransformersModel,TransformersState]Session for transformers model.
Methods:
Clone the current state of the language model.
Returns a mapping of token strings to their respective ids.
Returns the logits for next token.
Returns the probabilities for next token.
set_state(state)Set the state of the language model.
tokenize(text[, add_special_tokens])Tokenize the given text into a list of tokens.
Attributes:
Returns the context length of the model, or zero for models that don't support one.
- clone_state() TransformersState | None[source]#
Clone the current state of the language model.
- Returns:
The current state as an object.
- property context_length: int#
Returns the context length of the model, or zero for models that don’t support one.
- set_state(state: TransformersState | None)[source]#
Set the state of the language model.
- Parameters:
state (Optional[T_LLMState]) – The state of the language model, or None to clear the state.