mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
9.6 KiB
9.6 KiB
In [ ]:
%%capture
!pip install git+https://github.com/neuml/txtai#egg=txtai[pipeline-train] datasetsIn [9]:
from txtai import LLM
llm = LLM("Qwen/Qwen3-0.6B")In [11]:
llm("""
Translate the following request into a linux command. Only print the command.
Find number of logged in users
""", maxlength=1024)Out [11]:
'ps -e'
In [1]:
from datasets import load_dataset
from transformers import AutoTokenizer
# LLM path
path = "Qwen/Qwen3-0.6B"
tokenizer = AutoTokenizer.from_pretrained(path)
# Load the training dataset
dataset = load_dataset("mecha-org/linux-command-dataset", split="train")
def prompt(row):
text = tokenizer.apply_chat_template([
{"role": "system", "content": "Translate the following request into a linux command. Only print the command."},
{"role": "user", "content": row["input"]},
{"role": "assistant", "content": row["output"]}
], tokenize=False, enable_thinking=False)
return {"text": text}
# Map to training prompts
train = dataset.map(prompt, remove_columns=["input", "output"])In [2]:
from txtai.pipeline import HFTrainer
# Load the training pipeline
trainer = HFTrainer()
# Train the model
# Set output_dir to save, trained in memory for this example
model = trainer(
"Qwen/Qwen3-0.6B",
train,
task="language-generation",
maxlength=512,
bf16=True,
per_device_train_batch_size=4,
num_train_epochs=1,
logging_steps=50,
)
[210/210 01:12, Epoch 1/1]
| Step | Training Loss |
|---|---|
| 50 | 0.625300 |
| 100 | 0.490200 |
| 150 | 0.403300 |
| 200 | 0.391800 |
In [ ]:
from txtai import LLM
llm = LLM(model)
llm([
{"role": "system", "content": "Translate the following request into a linux command. Only print the command."},
{"role": "user", "content": "Find number of logged in users"}
])'who | wc -l'
In [14]:
llm([
{"role": "system", "content": "Translate the following request into a linux command. Only print the command."},
{"role": "user", "content": "List the files in my home directory"}
])Out [14]:
'ls ~/'
In [16]:
llm([
{"role": "system", "content": "Translate the following request into a linux command. Only print the command."},
{"role": "user", "content": "Zip the data directory with all it's contents"}
])Out [16]:
'zip -r data.zip data'
In [20]:
llm("Calculate the total amount of disk space used for my home directory. Only print the total.")Out [20]:
'du -sh ~'