You can adapt SaT to a specific corpus using LoRA with as few as 10-100 segmented training sentences.
1. Setup Environment
Clone the repository and install the required dependencies, including the specific adapters version:
git clone https://github.com/segment-any-text/wtpsplit
cd wtpsplit
pip install -r requirements.txt
pip install adapters==0.2.1 --no-dependencies
2. Prepare Training Data
Create a .pth file containing your training data. The data must be structured as a nested dictionary. Important: Individual sentences must not contain newline characters (\n).
import torch
torch.save(
{
"language_code": {
"sentence": {
"dummy-dataset": {
"meta": {
"train_data": ["train sentence 1", "train sentence 2"],
},
"data": [
"test sentence 1",
"test sentence 2",
]
}
}
}
},
"dummy-dataset.pth"
)
3. Configure and Train
Create a configuration JSON file (e.g., configs/lora/lora_dummy_config.json) specifying the model_name_or_path, output_dir, and text_path (the path to your .pth file).
Run the training script:
python3 wtpsplit/train/train_lora.py configs/lora/lora_dummy_config.json
4. Inference with Adapted Model
Load the trained adapter using the lora_path argument in the SaT constructor:
sat_lora_adapted = SaT("model-used", lora_path="dummy_lora_path")
sat_lora_adapted.split("Some domains-specific or styled text")