Repository Analysis

FareedKhan-dev/train-llm-from-scratch

A straightforward method for training your LLM, from downloading data to generating text.

15.5 Moderate AI signal View on GitHub

Analysis Overview

This report presents the forensic synthetic code analysis of FareedKhan-dev/train-llm-from-scratch, a Python project with 8,315 GitHub stars. SynthScan v2.0 examined 11,000 lines of code across 127 source files, recording 135 pattern matches distributed across 13 syntactic categories. The overall adjusted score of 15.5 places this repository in the Moderate AI signal band.

The scanner applied 160+ deterministic lexical heuristics, multi-line block detectors, abstract syntax tree depth profilers, and a cross-file Jaccard similarity matrix to construct a statistically normalised synthetic code estimate. All matches are individually weighted by severity coefficient and contextual multiplier before summation, and the resulting headline score is temporally discounted to account for the repository's development history relative to the commercial emergence of large language model coding tooling (November 2022 onward).

15.5
Adjusted Score
15.5
Raw Score
100%
Time Factor
2026-06-24
Last Push
8.3K
Stars
Python
Language
11.0K
Lines of Code
127
Files
135
Pattern Hits
2026-07-14
Scan Date
0.02
HC Hit Rate

What These Metrics Mean

Adjusted Score
Primary synthetic code indicator. Raw score normalised per 1,000 lines of code and multiplied by the temporal discount factor. This is the definitive comparative metric — use it to rank repositories by AI authorship density.
Raw Score
The unmodified sum of all severity-weighted, context-multiplied pattern match scores before temporal discounting. Reflects the absolute signal strength independent of when the repository was last active.
Time Factor
The temporal discount multiplier (0–100%) applied to the raw score. Repositories last updated before ChatGPT's launch (Nov 2022) receive a 5% factor. Full signal is only assigned to repositories active in the post-adoption era (Jan 2024+).
Pattern Hits
Total count of individual pattern matches across all files and categories. A high hit count with a low score may indicate a very large codebase with isolated AI snippets; a low count with a high score indicates dense, concentrated AI signatures.
HC Hit Rate
High+Critical pattern hits per file, averaged across the repository. This orthogonal signal catches repositories where a few files are densely packed with high-severity AI tells — a strong indicator even when the normalised score appears moderate due to codebase size.
Lines of Code / Files
Total lines and files analysed. The scanner examines 94 file extensions. These denominators are used to normalise the score, enabling fair comparison between repositories of vastly different sizes.

Score History

This chart maps the temporal evolution of the adjusted synthetic code score across successive scan runs. An upward trajectory indicates ongoing incorporation of AI-generated code or expanding LLM-assisted scaffolding; a stable or declining trajectory may reflect active human refactoring, code removal, or the adoption of stricter authorship policies. The dashed secondary line (right axis) independently tracks total raw pattern hit count, which can diverge from the normalised score when codebase size changes significantly between scans.

Severity Breakdown

Classifies detected patterns by their diagnostic confidence and structural impact. CRITICAL patterns (coefficient 10) represent definitive synthetic signatures — hallucinated imports, explicit LLM attribution metadata — virtually never produced by human authors. HIGH (5) indicates strong structural tells such as cross-file repetition or cross-linguistic idioms. MEDIUM (2) covers recognisable conversational padding and AI-specific vocabulary. LOW (1) captures subtle indicators like tautological comments and generic boilerplate that require density to carry independent signal.

CRITICAL 0HIGH 3MEDIUM 12LOW 120

Directory Score Breakdown

This horizontal bar chart decomposes the repository's raw synthetic code score by top-level directory, allowing you to pinpoint precisely which modules or components carry the highest AI authorship density. Directories with disproportionately high scores relative to their size warrant targeted manual review: concentrated AI signatures often trace back to mass-generated configuration layers, auto-ported test suites, LLM-scaffolded boilerplate classes, or entire subsystems authored under heavy copilot assistance. Use this view to prioritise your human code-review effort.

Pattern Findings

The scanner identified 135 distinct pattern matches across 13 syntactic categories. Each entry below represents a discrete location in the source code where the engine recorded a statistically significant AI authorship indicator. Expand any category row to inspect the individual file paths, line numbers, code snippets, and the lexical context (CODE, COMMENT, or STRING) in which each match was detected.

Reading the findings table: The Severity column indicates the diagnostic confidence level (CRITICAL / HIGH / MEDIUM / LOW). The Context column identifies whether the match occurred inside executable code, an inline comment, or a string literal — comment-context matches receive a ×1.5 weight because LLMs systematically over-annotate. The ⚡ bolt icon marks clustered matches: three or more patterns within a 10-line window, each receiving an additional ×1.5 density multiplier as dense clusters constitute far stronger evidence of synthetic authorship than isolated hits.

Unused Imports74 hits · 74 pts
SeverityFileLineSnippetContext
LOWui/metrics.py3CODE
LOWui/theme.py3CODE
LOWui/stages.py7CODE
LOWui/jobs.py10CODE
LOWui/app.py7CODE
LOWui/docs_render.py11CODE
LOWui/stage_page.py7CODE
LOWui/config_forms.py9CODE
LOWui/pages/8_Evaluate.py3CODE
LOWui/pages/9_Chat.py3CODE
LOWui/pages/1_Data.py3CODE
LOWconfig/post_training_config.py15CODE
LOWconfig/post_training_config.py17CODE
LOWconfig/loader.py20CODE
LOWtests/test_post_training_smoke.py14CODE
LOWtests/test_checkpoint_resume.py8CODE
LOWtests/test_rl_math.py9CODE
LOWscripts/eval_post_training.py16CODE
LOWscripts/train_ppo.py13CODE
LOWscripts/train_ppo.py15CODE
LOWscripts/train_ppo.py23CODE
LOWscripts/prepare_preference_data.py14CODE
LOWscripts/train_sft.py13CODE
LOWscripts/train_sft.py15CODE
LOWscripts/train_dpo.py12CODE
LOWscripts/train_reward.py13CODE
LOWscripts/train_reward.py72CODE
LOWscripts/chat.py15CODE
LOWscripts/train_grpo.py14CODE
LOWscripts/train_grpo.py16CODE
LOWscripts/pretrain_base.py18CODE
LOWscripts/pretrain_base.py23CODE
LOWscripts/prepare_rl_prompts.py12CODE
LOWscripts/prepare_pretrain_data.py18CODE
LOWscripts/train_transformer.py1CODE
LOWscripts/prepare_sft_data.py17CODE
LOWdata_loader/sft_dataset.py9CODE
LOWdata_loader/prompt_dataset.py7CODE
LOWdata_loader/preference_dataset.py16CODE
LOWsrc/post_training/evaluation.py9CODE
LOWsrc/post_training/chat_template.py31CODE
LOWsrc/post_training/grpo.py10CODE
LOWsrc/post_training/distributed.py10CODE
LOWsrc/post_training/cli.py6CODE
LOWsrc/post_training/utils.py7CODE
LOWsrc/post_training/rollout.py22CODE
LOWsrc/post_training/value_head.py11CODE
LOWsrc/post_training/inference.py10CODE
LOWsrc/post_training/inference.py15CODE
LOWsrc/post_training/inference.py15CODE
LOWsrc/post_training/reward_model.py10CODE
LOWsrc/post_training/reward_model.py18CODE
LOWsrc/post_training/sft.py11CODE
LOWsrc/post_training/ppo.py17CODE
LOWsrc/post_training/optim.py9CODE
LOWsrc/post_training/dpo.py15CODE
LOWsrc/post_training/logging_utils.py10CODE
LOWsrc/post_training/reward_train.py12CODE
LOWsrc/post_training/rewards/verifiers.py12CODE
LOWsrc/post_training/rewards/parsing.py12CODE
14 more matches not shown…
Self-Referential Comments8 hits · 26 pts
SeverityFileLineSnippetContext
MEDIUMscripts/data_preprocess.py31 # Create an HDF5 file for outputCOMMENT
MEDIUMscripts/train_transformer.py320 # Create a batch iterator for evaluation.COMMENT
MEDIUMscripts/train_transformer.py515 # Define a window size for averaging recent losses in the training loop.COMMENT
MEDIUMscripts/train_transformer.py522 # Create a batch iterator for the training data.COMMENT
MEDIUMscripts/train_transformer.py536 # Create a progress bar to monitor training progress.COMMENT
MEDIUMscripts/data_download.py40 # Define the path for the validation fileCOMMENT
MEDIUMdata_loader/data_loader.py31 # Create an array of indices for examples and shuffle them for randomnessCOMMENT
MEDIUMdata_loader/data_loader.py66 # Create a dummy HDF5 fileCOMMENT
Hyper-Verbose Identifiers13 hits · 13 pts
SeverityFileLineSnippetContext
LOWtests/verify_data_and_eval.py39def verify_sft_mask_alignment():CODE
LOWtests/verify_data_and_eval.py82def verify_rl_prompts_and_gold():CODE
LOWtests/test_post_training_smoke.py28def test_forward_hidden_matches_forward():CODE
LOWtests/test_post_training_smoke.py38def test_compute_logprobs_matches_manual():CODE
LOWtests/test_post_training_smoke.py51def test_rollout_logprobs_consistent():CODE
LOWtests/test_post_training_smoke.py66def test_context_cap_enforced():CODE
LOWtests/test_post_training_smoke.py74def test_value_and_reward_heads():CODE
LOWtests/test_post_training_smoke.py92def test_frozen_copy_and_reductions():CODE
LOWtests/test_post_training_smoke.py104def test_chat_template_masking():CODE
LOWtests/test_checkpoint_resume.py41def test_checkpoint_round_trip_and_latest_resume():CODE
LOWtests/test_checkpoint_resume.py81def test_checkpoint_save_failure_does_not_leave_partial_file():CODE
LOWtests/test_rl_math.py27def test_gae_masks_outside_response():CODE
LOWscripts/train_transformer.py230def restore_training_checkpoint(CODE
Cross-Language Confusion3 hits · 12 pts
SeverityFileLineSnippetContext
HIGHui/config_forms.py34 # str / str|None / unknown -> text; empty string means "unset" (-> null) for optionalsCOMMENT
HIGHdata_loader/prompt_dataset.py3verifiable numeric answer, or null) and yields lists of sampled rows. Rows are shardedSTRING
HIGHsrc/post_training/ppo.py99 """Mean approximate KL(old || new) over response tokens (a PPO health metric)."""STRING
Excessive Try-Catch Wrapping9 hits · 12 pts
SeverityFileLineSnippetContext
LOWui/theme.py59 except Exception: # noqa: BLE001CODE
LOWscripts/data_preprocess.py72 except Exception as e:CODE
MEDIUMscripts/data_preprocess.py74 print(f"An error occurred while processing line in {filename}: {e}")CODE
MEDIUMscripts/data_preprocess.py98 print(f"Error: Training directory not found: {args.train_dir}")CODE
MEDIUMscripts/data_preprocess.py101 print(f"Error: Validation directory not found: {args.val_dir}")CODE
LOWscripts/prepare_preference_data.py83 except Exception as e: # noqa: BLE001CODE
LOWscripts/train_transformer.py224 except Exception:CODE
LOWscripts/prepare_sft_data.py85 except Exception as e: # noqa: BLE001CODE
LOWsrc/post_training/logging_utils.py42 except Exception as e: # noqa: BLE001 - logging must never crash trainingCODE
Structural Annotation Overuse7 hits · 10 pts
SeverityFileLineSnippetContext
LOWREADME.md160## Step 1: Preparing the DataCOMMENT
LOWREADME.md279## Step 2: The Model, Built From Small PiecesCOMMENT
LOWREADME.md427## Step 3: Pretraining the Base ModelCOMMENT
LOWREADME.md513## Step 4: Generating TextCOMMENT
LOWREADME.md537## Step 5: Post-Training, Turning a Base Model Into an AssistantCOMMENT
LOWREADME.md671## Step 6: EvaluationCOMMENT
LOWREADME.md690## Step 7: Talking to the ModelCOMMENT
Deep Nesting10 hits · 10 pts
SeverityFileLineSnippetContext
LOWui/metrics.py17CODE
LOWscripts/data_preprocess.py10CODE
LOWscripts/train_ppo.py55CODE
LOWscripts/train_sft.py50CODE
LOWscripts/train_dpo.py74CODE
LOWscripts/train_reward.py59CODE
LOWscripts/train_grpo.py43CODE
LOWscripts/pretrain_base.py56CODE
LOWscripts/prepare_pretrain_data.py76CODE
LOWscripts/train_transformer.py416CODE
Redundant / Tautological Comments4 hits · 6 pts
SeverityFileLineSnippetContext
LOWscripts/data_download.py25 with open(file_name, 'wb') as f: # Open file for writing in binary modeCODE
LOWscripts/data_download.py42 if not os.path.exists(val_file_path): # Check if the validation file already existsCODE
LOWscripts/data_download.py52 if not os.path.exists(file_path): # Check if the file already existsCODE
LOWdata_loader/data_loader.py40 # Check if the current batch exceeds the number of available examplesCOMMENT
Modern Structural Boilerplate3 hits · 3 pts
SeverityFileLineSnippetContext
LOWscripts/train_transformer.py167def set_optimizer_lr(optimizer: torch.optim.Optimizer, lr: float) -> None:CODE
LOWsrc/post_training/utils.py35def set_seed(seed: int) -> None:CODE
LOWsrc/post_training/rewards/__init__.py16__all__ = [CODE
Modern AI Meta-Vocabulary1 hit · 2 pts
SeverityFileLineSnippetContext
MEDIUMREADME.md520 idx_cond = idx[:, -self.context_length:] # never look back further than the context windowCODE
Over-Commented Block1 hit · 1 pts
SeverityFileLineSnippetContext
LOWscripts/render_diagrams.sh1#!/usr/bin/env bashCOMMENT
Fake / Example Data1 hit · 1 pts
SeverityFileLineSnippetContext
LOWdata_loader/data_loader.py68 dummy_data_path = "dummy_data.h5"CODE
AI Structural Patterns1 hit · 1 pts
SeverityFileLineSnippetContext
LOWsrc/models/attention.py58CODE