lmflow.utils.data_utils#
The program includes several functions: setting a random seed, loading data from a JSON file, batching data, and extracting answers from generated text.
Classes#
Structured vLLM inference result with its original input. |
|
Structured reward-model inference result with its original input. |
Functions#
|
Set the random seed for random, numpy, torch, torch.cuda. |
|
Load data with file name. |
|
Convert examples to a dataloader. |
|
Returns the first and last specified number of characters from a file |
|
Get the type values from the first and last n lines of a large json dataset. |
|
Check if the dataset instances key matches the instance_key. |
|
Extract answers from generated text. |
|
Module Contents#
- lmflow.utils.data_utils.set_random_seed(seed: int)[source]#
Set the random seed for random, numpy, torch, torch.cuda.
- Parameters:
seed (int) – The default seed.
- lmflow.utils.data_utils.load_data(file_name: str)[source]#
Load data with file name.
- Parameters:
file_name (str) – The dataset file name.
- Returns:
inputs (list) – The input texts of the dataset.
outputs (list) – The output texts file datasets.
length (int) – The length of the dataset.
- lmflow.utils.data_utils.batchlize(examples: list, batch_size: int, random_shuffle: bool)[source]#
Convert examples to a dataloader.
- Parameters:
examples (list) – Data list.
batch_size (int) – Number of examples in each batch.
random_shuffle (bool) – If true, the dataloader shuffle the training data.
- Returns:
Dataloader with batch generator.
- Return type:
list
- lmflow.utils.data_utils.preview_file(file_path: str, chars: int = 100)[source]#
Returns the first and last specified number of characters from a file without loading the entire file into memory, working with any file type.
- Parameters:
file_path (str) – Path to the file to be previewed
chars (int, optional) – Number of characters to show from start and end. Defaults to 100.
- Returns:
(first_chars, last_chars) - The first and last characters from the file
- Return type:
tuple
- lmflow.utils.data_utils.get_dataset_type_fast(file_path: str, max_chars: int = 100) str | None[source]#
Get the type values from the first and last n lines of a large json dataset.
- lmflow.utils.data_utils.check_dataset_instances_key_fast(file_path: str, instances_key: str, max_lines: int = 100) bool[source]#
Check if the dataset instances key matches the instance_key.
- lmflow.utils.data_utils.answer_extraction(response, answer_type=None)[source]#
Extract answers from generated text.
- Parameters:
response (str) – plain string response.
answer_type (str, optional) – Type of answer to extract.
- Returns:
Decoded answer (such as A, B, C, D, E for multiple-choice QA).
- Return type:
str