Views
No views yet
1import pandas as pd
2
3data = pd.read_csv("synthetic_code_workflows_combined.csv")
4
5data = data[['instruction', 'workflow_code']].rename(
6 columns={'instruction': 'Instruction', 'workflow_code': 'Response'}
7)
8
9data = data.sample(frac=1, random_state=42)
10
11few_shot = data[:8]
12train_raw = data[8:300]
13val_raw = data[300:]| Metric | LoRA Adapted Model | Base Model - Llama-3.2-1B-Instruct | Llama-3.2-1B | Qwen2.5-1.5B-Instruct |
|---|---|---|---|---|
| Average Custom Text Match | 21.73 % | 19.04 % | 21.52 % | 22.08 % |
| Median Custom Text Match | 19.52 % | 16.65 % | 19.03 % | 19.44 % |
| GSM8K COT Strict Match | 27.75 % | 35.03 % | 5.69 % | 51.55 % |
| GSM8K COT Flexible Extract | 27.98 % | 35.18 % | 7.28 % | 61.79 % |
| HellaSwag Accuracy | 45.29 % | 45.08 % | 47.71 % | 50.82 % |
| HellaSwag Normalized Accuracy | 61.56 % | 60.72 % | 63.63 % | 68.18 % |
| HumanEval Passes | 25.00 % | 24.39 % | 17.07 % | 35.37 % |
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3tokenizer = AutoTokenizer.from_pretrained('SamKnisely/llama-lora-predictive-modeling')
4model = AutoModelForCausalLM.from_pretrained('SamKnisely/llama-lora-predictive-modeling', device_map="auto", torch_dtype=torch.bfloat16)1from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
2import torch
3
4pipe = pipeline(
5 "text-generation",
6 model=model,
7 tokenizer=tokenizer,
8 device_map="auto",
9 max_new_tokens = 1500,
10 torch_dtype=torch.bfloat16
11)1
2import pandas as pd
3from tqdm import tqdm
4
5def few_shot_prompt(instruction, df, n=8):
6 """
7 Builds a few-shot prompt using `n` demo examples from df (starting at index 2).
8 Adds a clear separator for the model to continue from.
9 """
10 # Build demonstrations
11 demos = []
12 for i in range(n):
13 demo_instr = data.iloc[i]['Instruction']
14 demo_resp = data.iloc[i]['Response']
15 demos.append(f"Instruction: {demo_instr}\nResponse: {demo_resp}")
16 demo_text = "\n\n".join(demos)
17
18 # Hide demos
19 hidden_context = f"[BEGIN HIDDEN CONTEXT]\n{demo_text}\n[END HIDDEN CONTEXT]\n\n"
20
21 # Build final prompt for the current instruction
22 prompt = (
23 hidden_context +
24 "Below is your instruction. Provide only your answer after '### Answer:' without including the hidden context above.\n\n"
25 f"Instruction: {instruction}\n### Answer:"
26 )
27 return prompt1instruction = "Train a classification model to predict building_stability in Construction based on material_used, building_age, structural_integrity, and weather_resistance."
2
3# Build prompt using 8-shot examples
4prompt = few_shot_prompt(instruction, few_shot, n=8)
5
6# Generate a response from the model pipeline
7result = pipe(prompt)
8generated_text = result[0]['generated_text']1# Post-process: Extract the answer after the marker
2if "### Answer:" in generated_text:
3 answer = generated_text.split("### Answer:")[-1].strip()
4else:
5 answer = generated_text.strip()
6
7print(answer)1import pandas as pd
2from sklearn.model_selection import train_test_split
3from sklearn.ensemble import RandomForestClassifier
4from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
5
6# Load data
7df = pd.read_csv("construction_data.csv")
8
9# Preprocessing
10X = df[['material_used', 'building_age','structural_integrity', 'weather_resistance']]
11y = df['building_stability']
12
13# Split data into training and testing sets
14X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
15
16# One-hot encoding for categorical variables
17X_train = pd.get_dummies(X_train, columns=['material_used'])
18X_test = pd.get_dummies(X_test, columns=['material_used'])
19
20# Align the training and testing data
21X_test = X_test.reindex(columns=X_train.columns, fill_value=0)
22
23# Initialize and train the model
24model = RandomForestClassifier()
25model.fit(X_train, y_train)
26
27# Make predictions on the test set
28y_pred = model.predict(X_test)
29
30# Evaluate the model
31accuracy = accuracy_score(y_test, y_pred)
32print("Model Accuracy:", accuracy)
33print("Classification Report:\n", classification_report(y_test, y_pred))
34print("Confusion Matrix:\n", confusion_matrix(y_test, y_pred))