inif.converters.text
The fastest path from “I have some strings” to “I have an InifDocument”. Handles plain strings and chat-style message lists; chat detection is per-element. See the text converter guide for options and conventions.
Entry points
from_texts
Converts one or more inputs into Sample objects in an InifDocument.
def from_texts(
texts: list[str] | list[list[dict[str, str]]],
tokenizer: Any,
sample_ids: list[str] | None = None,
min_sequence_length: int = 5,
deduplicate: bool = True,
tag_chat_roles: bool = False,
) -> InifDocumenttextslist[str] | list[list[dict[str, str]]]-
Either a list of plain strings, or a list of chat message lists (
list[dict[str, str]]with"role"/"content"keys) — detected per-element. Chat inputs are tokenized viatokenizer.apply_chat_template; plain strings viatokenizer.encode. tokenizerAny-
A HuggingFace tokenizer, or a model identifier string (e.g.
"openai/gpt-oss-20b") that will be loaded viaAutoTokenizer.from_pretrained. sample_idslist[str] | None-
Optional list of sample IDs (defaults to “sample_0”, …).
min_sequence_lengthint-
Minimum length for common sequence detection.
deduplicatebool-
Whether to run sequence deduplication. Default: True.
tag_chat_rolesbool-
Whether to tag chat-input tokens with roles after dedup. No-op for plain-string inputs.
from_text_files
Each file becomes one Sample. Finds common sequences across samples.
def from_text_files(
paths: list[str | Path],
tokenizer: Any,
min_sequence_length: int = 5,
deduplicate: bool = True,
) -> InifDocumentpathslist[str | Path]-
List of file paths to process.
tokenizerAny-
A HuggingFace tokenizer, or a model identifier string (e.g.
"openai/gpt-oss-20b") that will be loaded viaAutoTokenizer.from_pretrained. min_sequence_lengthint-
Minimum length for common sequence detection.
deduplicatebool-
Whether to run sequence deduplication.