Implementation:Run llama Llama index LabelledTextDataset
Overview
This module defines data structures for simple text classification datasets in LlamaIndex. It provides LabelledSimpleDataset for storing labelled text examples with associated class labels, along with corresponding prediction and example classes. The dataset uses an LLM as its predictor type, unlike the RAG dataset which uses a query engine.
Source file: llama-index-core/llama_index/core/llama_dataset/simple.py (141 lines)
Class Hierarchy
BaseLlamaExamplePrediction └── SimpleExamplePrediction BaseLlamaDataExample └── LabelledSimpleDataExample BaseLlamaPredictionDataset └── SimplePredictionDataset BaseLlamaDataset[LLM] └── LabelledSimpleDataset
SimpleExamplePrediction
class SimpleExamplePrediction(BaseLlamaExamplePrediction):
Stores the predicted output for a single text classification example.
| Field | Type | Default | Description |
|---|---|---|---|
label |
str |
"" |
The predicted label that can be compared to a reference ground-truth label |
The class_name property returns "SimpleExamplePrediction".
SimplePredictionDataset
class SimplePredictionDataset(BaseLlamaPredictionDataset):
A collection of SimpleExamplePrediction instances.
to_pandas
def to_pandas(self) -> Any:
Converts predictions to a pandas DataFrame with a single column:
label-- the predicted labels
Validates that all predictions match the _prediction_type using assertions. Raises ImportError if pandas is not installed.
The class_name property returns "SimplePredictionDataset".
LabelledSimpleDataExample
class LabelledSimpleDataExample(BaseLlamaDataExample):
Represents a single labelled text classification example.
| Field | Type | Default | Description |
|---|---|---|---|
reference_label |
str |
"" |
The ground-truth class label |
text |
str |
"" |
The text body of the example |
text_by |
Optional[CreatedBy] |
None |
Indicates what generated the text (human or AI with model name) |
The class_name property returns "LabelledSimpleDataExample".
LabelledSimpleDataset
class LabelledSimpleDataset(BaseLlamaDataset[LLM]):
The primary dataset class for text classification, parameterized with LLM as the predictor type.
to_pandas
def to_pandas(self) -> Any:
Converts the dataset to a pandas DataFrame with columns:
reference_label-- ground-truth labelstext-- text contenttext_by-- creation attribution (stringified)
Validates that all examples match _example_type, raising ValueError if not.
_construct_prediction_dataset
def _construct_prediction_dataset(
self, predictions: Sequence[SimpleExamplePrediction]
) -> SimplePredictionDataset:
Factory method that wraps a sequence of predictions into a SimplePredictionDataset.
_apredict_example
async def _apredict_example(
self,
predictor: LLM,
example: BaseLlamaDataExample,
sleep_time_in_seconds: int,
) -> BaseLlamaExamplePrediction:
Raises NotImplementedError. This async prediction method has not yet been implemented.
_predict_example
def _predict_example(
self,
predictor: LLM,
example: BaseLlamaDataExample,
sleep_time_in_seconds: int = 0,
) -> BaseLlamaExamplePrediction:
Raises NotImplementedError. This synchronous prediction method has not yet been implemented.
Dependencies
llama_index.core.llama_dataset.base-- providesBaseLlamaDataExample,BaseLlamaDataset,CreatedBy,BaseLlamaExamplePrediction,BaseLlamaPredictionDatasetllama_index.core.llms.LLM-- used as the predictor type parameterllama_index.core.bridge.pydantic.Field-- Pydantic field descriptors