Jaiccc commited on
Commit
7e81101
·
verified ·
1 Parent(s): d6c7fa1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +63 -71
README.md CHANGED
@@ -1,71 +1,63 @@
1
- ---
2
- license: mit
3
- task_categories:
4
- - text-classification
5
- - question-answering
6
- tags:
7
- - agent
8
- size_categories:
9
- - 1K<n<10K
10
- ---
11
- # Model Card: Streaming Terminal Log Boundary Predictor (Phi-4 LoRA)
12
-
13
- ## 🤖 Model Details
14
- * **Base Model:** `unsloth/Phi-4-unsloth-bnb-4bit` (14B Parameters)
15
- * **Architecture:** LoRA Adapters (PEFT)
16
- * **Task:** Binary Classification (Terminal Event Boundary Detection)
17
- * **Quantization:** 4-bit (bitsandbytes)
18
- * **Language:** English / Bash / Terminal XML
19
-
20
- ## 🎯 Intended Use
21
- This model is designed to parse continuous, timestamped terminal logs formatted in XML and determine if a specific line represents a "Boundary."
22
- * **New Event:** The start of a new phase (e.g., a new user prompt appearing, or a transition from downloading to extracting).
23
- * **Old Event:** A continuation of an ongoing process or a user keystroke (e.g., pressing Enter).
24
-
25
- This is particularly useful for segmenting long, automated build logs (like `apt-get` installations or mirror syncs) into readable, distinct chronological events.
26
-
27
- ## 🗂Training Data
28
- The model was fine-tuned on the **[Jaiccc/model0_boundary_predict_streaming](https://huggingface.co/datasets/Jaiccc/model0_boundary_predict_streaming)** dataset.
29
-
30
- The data utilizes a **sliding-window context of 15 chunks**:
31
- * 14 chunks of historical context.
32
- * 1 Target chunk to classify.
33
- * Heavily imbalanced data was downsampled to a 2:1 (Old:New) ratio to prevent majority-class guessing.
34
-
35
- ## 💻 How to Use (Inference)
36
- Because this is a private repository, you must authenticate using your Hugging Face token. This model uses PEFT/LoRA, meaning it is highly memory-efficient.
37
-
38
- ```python
39
- import re
40
- from unsloth import FastLanguageModel
41
- from google.colab import userdata
42
-
43
- # 1. Retrieve your secure token
44
- hf_token = userdata.get('HF_TOKEN') # Or os.getenv("HF_TOKEN")
45
-
46
- # 2. Load the Fine-Tuned Model
47
- model, tokenizer = FastLanguageModel.from_pretrained(
48
- model_name = "Jaiccc/model_0_streaming_timestamp",
49
- max_seq_length = 4096,
50
- load_in_4bit = True,
51
- token = hf_token,
52
- )
53
- FastLanguageModel.for_inference(model)
54
-
55
- # 3. Format your prompt (ChatML)
56
- instruction = "Your task is to analyze terminal XML logs and determine whether the timestamp in the TARGET LINE belongs to a 'new event' or an 'old event'."
57
- input_data = "### CONTEXT (Previous Events):\n<system_output timestamp=\"10.01\">demo@server:~$ apt update</system_output>\n\n### TARGET LINE:\n<user_input timestamp=\"12.40\">s</user_input>"
58
-
59
- prompt = f"<|im_start|>user<|im_sep|>{instruction}\n\n{input_data}<|im_end|><|im_start|>assistant<|im_sep|>"
60
- inputs = tokenizer(prompt, return_tensors="pt").input_ids.to("cuda")
61
-
62
- # 4. Generate Prediction
63
- outputs = model.generate(input_ids=inputs, max_new_tokens=64, use_cache=True, temperature=0.1)
64
- raw_output = tokenizer.batch_decode(outputs, clean_up_tokenization_spaces=True)[0]
65
-
66
- # 5. Extract Result
67
- m = re.search(r'<\|im_start\|>assistant<\|im_sep\|>(.*?)<\|im_end\|>', raw_output, re.S)
68
- result = m.group(1).strip() if m else raw_output.split("assistant")[-1].strip()
69
-
70
- print(result)
71
- # Expected Output: "12.40, old event"
 
1
+ # Dataset Card: Terminal Log Boundary Prediction (Streaming)
2
+
3
+ ## 📋 Dataset Summary
4
+ This dataset is designed to train Large Language Models (LLMs) to detect phase transitions, or "boundaries," within continuous, timestamped terminal XML logs.
5
+
6
+ Instead of reading a massive log file all at once, the dataset is structured using a **sliding-window approach**. The model is fed a short history of terminal events and must determine if the **very last line** (the Target Line) represents the start of a new phase/event or just the continuation of an ongoing process.
7
+
8
+ ## 🗂️ Dataset Structure
9
+ The dataset is provided in `JSONL` format, mapped specifically for conversational instruction-tuning (like ChatML). Each row contains three fields:
10
+
11
+ * **`instruction`**: The static system prompt that explicitly defines what makes a "new event" (e.g., shell prompts returning, phase transitions in automated scripts) versus an "old event" (e.g., a user pressing the Enter key, continuous downloading).
12
+ * **`input`**: The sliding-window terminal data. It is separated into two blocks:
13
+ * `### CONTEXT (Previous Events):` Up to 14 historical XML chunks to help the model understand the current state of the terminal.
14
+ * `### TARGET LINE (Extract and Classify THIS Timestamp):` The 15th chunk containing the specific timestamp the model needs to evaluate.
15
+ * **`label / output`**: The ground-truth prediction formatted strictly as `{timestamp}, {class} event`.
16
+
17
+ ### Example Data Row
18
+ ```json
19
+ {
20
+ "instruction": "Your task is to analyze terminal XML logs and determine whether the timestamp in the TARGET LINE belongs to a \"new event\" or an \"old event\"...",
21
+ "input": "### CONTEXT (Previous Events):\n<system_output timestamp=\"10.01\">demo@server:~$ apt update</system_output>\n<system_output timestamp=\"10.05\">Reading package lists...</system_output>\n\n### TARGET LINE:\n<user_input timestamp=\"12.40\">s</user_input>",
22
+ "output": "12.40, old event"
23
+ }
24
+ 🎯 The Model's Goal
25
+ The primary objective of the model is binary classification of sequential data. By looking at the historical context (e.g., "The terminal has been downloading packages for the last 14 steps"), the model must predict if the timestamp in the Target Line breaks that pattern and establishes a new boundary (e.g., "The download finished and the shell prompt returned").
26
+
27
+ Rules of Truncation
28
+ Raw terminal logs (like apt-get installations) can easily overflow an LLM's context window. To prevent this, the data engineering pipeline applies a strict Two-Phase Truncation rule:
29
+
30
+ Phase 1: Intra-Chunk Truncation (Line Limit)
31
+ If a single <system_output> block contains more than 15 lines of text, it is sliced. The first 5 lines and the last 5 lines are preserved, and the middle is replaced with a marker: ... [TRUNCATED X LINES] .... Note that <user_input> tags are never truncated to preserve human-interaction signals.
32
+
33
+ Phase 2: Window-Level Compression (Context Limit)
34
+ If the entire 14-chunk context window exceeds 25 total lines, the window is compressed:
35
+
36
+ The 5 oldest chunks and the 5 most recent chunks are kept fully intact.
37
+
38
+ For the chunks in the middle, the text is completely stripped out, leaving only the XML tags (e.g., <system_output timestamp="X">... [TRUNCATED TO SAVE SPACE] ...</system_output>).
39
+ This preserves the chronological timeline and sequence of events without bloating the token count.
40
+
41
+ ⚖️ Data Sampling & Balancing
42
+ In a typical terminal log, over 95% of the lines are "Old Events" (continuous output or typing), which would lead the model to simply guess the majority class. To force actual learning, this dataset uses Negative Downsampling:
43
+
44
+ New Events (Positives): 100% of detected boundaries are kept.
45
+
46
+ Old Events (Negatives): Downsampled so that there is exactly a 2:1 ratio (Two old events for every one new event).
47
+
48
+ Hard Negative Mining
49
+ When selecting which "Old Events" to keep for the 2:1 ratio, the algorithm prioritizes Hard Negatives. Specifically, it targets <user_input> tags that contain a newline character (\n). This teaches the model the difficult lesson that a user pressing "Enter" is often just a completion of an input phase, not necessarily a new logical event.
50
+
51
+ 💻 How to Load the Dataset
52
+ You can load this dataset directly in Python using the Hugging Face datasets library:
53
+
54
+ Python
55
+ from datasets import load_dataset
56
+
57
+ # Load the dataset
58
+ dataset = load_dataset("Jaiccc/model0_boundary_predict_streaming", split="train")
59
+
60
+ # Optional: Split into training and validation
61
+ split = dataset.train_test_split(test_size=0.1, seed=42)
62
+ train_dataset = split["train"]
63
+ eval_dataset = split["test"]