Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Update dataset handling, documentation change

davidmezzetti47146228e557
diff --git a/docs/pipelines/trainer.md b/docs/pipelines/trainer.md
index 03ac7ef7..6f8e635a 100644
--- a/docs/pipelines/trainer.md
+++ b/docs/pipelines/trainer.md
@@ -1,6 +1,6 @@
# HFTrainer
-Trains a new Hugging Face Transformer model using the Trainer API.
+Trains a new Hugging Face Transformer model using the Trainer framework.
Examples on how to use the trainer below.
@@ -19,7 +19,7 @@ model, tokenizer = trainer("bert-base-uncased", df)
# Hugging Face dataset
ds = load_dataset("glue", "sst2")
-model, tokenizer = trainer("bert-base-uncased", ds["train"])
+model, tokenizer = trainer("bert-base-uncased", ds["train"], columns=("sentence", "label"))
# List of dicts
dt = [{"text": "sentence 1", "label": 0}, {"text": "sentence 2", "label": 1}]]
@@ -30,5 +30,7 @@ model, tokenizer = trainer("bert-base-uncased", dt,
learning_rate=3e-5, num_train_epochs=5)
```
+All [TrainingArguments](https://huggingface.co/transformers/main_classes/trainer.html#transformers.TrainingArguments) are supported as function arguments to the trainer call.
+
::: txtai.pipeline.HFTrainer.__init__
::: txtai.pipeline.HFTrainer.__call__
diff --git a/src/python/txtai/pipeline/hftrainer.py b/src/python/txtai/pipeline/hftrainer.py
index 0cd075b2..c84e0206 100644
--- a/src/python/txtai/pipeline/hftrainer.py
+++ b/src/python/txtai/pipeline/hftrainer.py
@@ -17,7 +17,7 @@ from ..models import Models
class HFTrainer(Tensors):
"""
- Trains a new Hugging Face Transformer model using the Trainer API.
+ Trains a new Hugging Face Transformer model using the Trainer framework.
"""
def __call__(self, base, train, validation=None, columns=None, maxlength=None, **args):
@@ -166,7 +166,7 @@ class HFTrainer(Tensors):
if hasattr(data, "map"):
# Hugging Face dataset
tokens = data.map(lambda row: self.tokenize(row, columns, tokenizer, maxlength))
- labels = sorted(data.features[columns[-1]].names)
+ labels = sorted(data.unique(columns[-1]))
else:
# pandas DataFrame
if hasattr(data, "to_dict"):
diff --git a/test/python/testtrainer.py b/test/python/testtrainer.py
index 7779f4c0..6fb85507 100644
--- a/test/python/testtrainer.py
+++ b/test/python/testtrainer.py
@@ -88,11 +88,7 @@ class TestTrainer(unittest.TestCase):
def __init__(self, data):
self.data = data
-
- label = unittest.mock.Mock()
- label.names = [0, 1]
-
- self.features = {"label": label}
+ self.unique = lambda _: [0, 1]
def __len__(self):
return len(self.data)