Commit ·
2e15698
verified ·
0
Parent(s):
chore: scaffold qmd-web project
Browse filesVite + React + TypeScript setup with @huggingface/transformers v4.
Includes 3 sample eval docs from QMD repo.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- .gitignore +24 -0
- README.md +73 -0
- eslint.config.js +23 -0
- index.html +13 -0
- package-lock.json +0 -0
- package.json +31 -0
- public/eval-docs/api-design-principles.md +73 -0
- public/eval-docs/distributed-systems-overview.md +92 -0
- public/eval-docs/machine-learning-primer.md +125 -0
- src/App.tsx +10 -0
- src/main.tsx +9 -0
- tsconfig.app.json +28 -0
- tsconfig.json +7 -0
- tsconfig.node.json +26 -0
- vite.config.ts +7 -0
.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Logs
|
| 2 |
+
logs
|
| 3 |
+
*.log
|
| 4 |
+
npm-debug.log*
|
| 5 |
+
yarn-debug.log*
|
| 6 |
+
yarn-error.log*
|
| 7 |
+
pnpm-debug.log*
|
| 8 |
+
lerna-debug.log*
|
| 9 |
+
|
| 10 |
+
node_modules
|
| 11 |
+
dist
|
| 12 |
+
dist-ssr
|
| 13 |
+
*.local
|
| 14 |
+
|
| 15 |
+
# Editor directories and files
|
| 16 |
+
.vscode/*
|
| 17 |
+
!.vscode/extensions.json
|
| 18 |
+
.idea
|
| 19 |
+
.DS_Store
|
| 20 |
+
*.suo
|
| 21 |
+
*.ntvs*
|
| 22 |
+
*.njsproj
|
| 23 |
+
*.sln
|
| 24 |
+
*.sw?
|
README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# React + TypeScript + Vite
|
| 2 |
+
|
| 3 |
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
| 4 |
+
|
| 5 |
+
Currently, two official plugins are available:
|
| 6 |
+
|
| 7 |
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
| 8 |
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
| 9 |
+
|
| 10 |
+
## React Compiler
|
| 11 |
+
|
| 12 |
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
| 13 |
+
|
| 14 |
+
## Expanding the ESLint configuration
|
| 15 |
+
|
| 16 |
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
| 17 |
+
|
| 18 |
+
```js
|
| 19 |
+
export default defineConfig([
|
| 20 |
+
globalIgnores(['dist']),
|
| 21 |
+
{
|
| 22 |
+
files: ['**/*.{ts,tsx}'],
|
| 23 |
+
extends: [
|
| 24 |
+
// Other configs...
|
| 25 |
+
|
| 26 |
+
// Remove tseslint.configs.recommended and replace with this
|
| 27 |
+
tseslint.configs.recommendedTypeChecked,
|
| 28 |
+
// Alternatively, use this for stricter rules
|
| 29 |
+
tseslint.configs.strictTypeChecked,
|
| 30 |
+
// Optionally, add this for stylistic rules
|
| 31 |
+
tseslint.configs.stylisticTypeChecked,
|
| 32 |
+
|
| 33 |
+
// Other configs...
|
| 34 |
+
],
|
| 35 |
+
languageOptions: {
|
| 36 |
+
parserOptions: {
|
| 37 |
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
| 38 |
+
tsconfigRootDir: import.meta.dirname,
|
| 39 |
+
},
|
| 40 |
+
// other options...
|
| 41 |
+
},
|
| 42 |
+
},
|
| 43 |
+
])
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
| 47 |
+
|
| 48 |
+
```js
|
| 49 |
+
// eslint.config.js
|
| 50 |
+
import reactX from 'eslint-plugin-react-x'
|
| 51 |
+
import reactDom from 'eslint-plugin-react-dom'
|
| 52 |
+
|
| 53 |
+
export default defineConfig([
|
| 54 |
+
globalIgnores(['dist']),
|
| 55 |
+
{
|
| 56 |
+
files: ['**/*.{ts,tsx}'],
|
| 57 |
+
extends: [
|
| 58 |
+
// Other configs...
|
| 59 |
+
// Enable lint rules for React
|
| 60 |
+
reactX.configs['recommended-typescript'],
|
| 61 |
+
// Enable lint rules for React DOM
|
| 62 |
+
reactDom.configs.recommended,
|
| 63 |
+
],
|
| 64 |
+
languageOptions: {
|
| 65 |
+
parserOptions: {
|
| 66 |
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
| 67 |
+
tsconfigRootDir: import.meta.dirname,
|
| 68 |
+
},
|
| 69 |
+
// other options...
|
| 70 |
+
},
|
| 71 |
+
},
|
| 72 |
+
])
|
| 73 |
+
```
|
eslint.config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import js from '@eslint/js'
|
| 2 |
+
import globals from 'globals'
|
| 3 |
+
import reactHooks from 'eslint-plugin-react-hooks'
|
| 4 |
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
| 5 |
+
import tseslint from 'typescript-eslint'
|
| 6 |
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
| 7 |
+
|
| 8 |
+
export default defineConfig([
|
| 9 |
+
globalIgnores(['dist']),
|
| 10 |
+
{
|
| 11 |
+
files: ['**/*.{ts,tsx}'],
|
| 12 |
+
extends: [
|
| 13 |
+
js.configs.recommended,
|
| 14 |
+
tseslint.configs.recommended,
|
| 15 |
+
reactHooks.configs.flat.recommended,
|
| 16 |
+
reactRefresh.configs.vite,
|
| 17 |
+
],
|
| 18 |
+
languageOptions: {
|
| 19 |
+
ecmaVersion: 2020,
|
| 20 |
+
globals: globals.browser,
|
| 21 |
+
},
|
| 22 |
+
},
|
| 23 |
+
])
|
index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>qmd-web</title>
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div id="root"></div>
|
| 11 |
+
<script type="module" src="/src/main.tsx"></script>
|
| 12 |
+
</body>
|
| 13 |
+
</html>
|
package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "qmd-web",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "0.0.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"build": "tsc -b && vite build",
|
| 9 |
+
"lint": "eslint .",
|
| 10 |
+
"preview": "vite preview"
|
| 11 |
+
},
|
| 12 |
+
"dependencies": {
|
| 13 |
+
"@huggingface/transformers": "^4.0.0-next.7",
|
| 14 |
+
"react": "^19.2.0",
|
| 15 |
+
"react-dom": "^19.2.0"
|
| 16 |
+
},
|
| 17 |
+
"devDependencies": {
|
| 18 |
+
"@eslint/js": "^9.39.1",
|
| 19 |
+
"@types/node": "^24.10.1",
|
| 20 |
+
"@types/react": "^19.2.7",
|
| 21 |
+
"@types/react-dom": "^19.2.3",
|
| 22 |
+
"@vitejs/plugin-react": "^5.1.1",
|
| 23 |
+
"eslint": "^9.39.1",
|
| 24 |
+
"eslint-plugin-react-hooks": "^7.0.1",
|
| 25 |
+
"eslint-plugin-react-refresh": "^0.4.24",
|
| 26 |
+
"globals": "^16.5.0",
|
| 27 |
+
"typescript": "~5.9.3",
|
| 28 |
+
"typescript-eslint": "^8.48.0",
|
| 29 |
+
"vite": "^7.3.1"
|
| 30 |
+
}
|
| 31 |
+
}
|
public/eval-docs/api-design-principles.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# API Design Principles
|
| 2 |
+
|
| 3 |
+
## Introduction
|
| 4 |
+
|
| 5 |
+
Good API design is crucial for developer experience. This document outlines the core principles we follow when designing REST APIs.
|
| 6 |
+
|
| 7 |
+
## Principle 1: Use Nouns, Not Verbs
|
| 8 |
+
|
| 9 |
+
URLs should represent resources, not actions. Use HTTP methods to indicate the action.
|
| 10 |
+
|
| 11 |
+
**Good:**
|
| 12 |
+
- GET /users/123
|
| 13 |
+
- POST /orders
|
| 14 |
+
- DELETE /products/456
|
| 15 |
+
|
| 16 |
+
**Bad:**
|
| 17 |
+
- GET /getUser?id=123
|
| 18 |
+
- POST /createOrder
|
| 19 |
+
- GET /deleteProduct/456
|
| 20 |
+
|
| 21 |
+
## Principle 2: Use Plural Nouns
|
| 22 |
+
|
| 23 |
+
Always use plural nouns for consistency.
|
| 24 |
+
|
| 25 |
+
- /users (not /user)
|
| 26 |
+
- /orders (not /order)
|
| 27 |
+
- /products (not /product)
|
| 28 |
+
|
| 29 |
+
## Principle 3: Hierarchical Relationships
|
| 30 |
+
|
| 31 |
+
Express relationships through URL hierarchy.
|
| 32 |
+
|
| 33 |
+
- GET /users/123/orders - Get all orders for user 123
|
| 34 |
+
- GET /users/123/orders/456 - Get specific order 456 for user 123
|
| 35 |
+
|
| 36 |
+
## Principle 4: Filtering and Pagination
|
| 37 |
+
|
| 38 |
+
Use query parameters for filtering, sorting, and pagination.
|
| 39 |
+
|
| 40 |
+
- GET /products?category=electronics&sort=price&page=2&limit=20
|
| 41 |
+
|
| 42 |
+
## Principle 5: Versioning
|
| 43 |
+
|
| 44 |
+
Always version your APIs. We prefer URL versioning.
|
| 45 |
+
|
| 46 |
+
- /v1/users
|
| 47 |
+
- /v2/users
|
| 48 |
+
|
| 49 |
+
## Principle 6: Error Handling
|
| 50 |
+
|
| 51 |
+
Return consistent error responses with appropriate HTTP status codes.
|
| 52 |
+
|
| 53 |
+
```json
|
| 54 |
+
{
|
| 55 |
+
"error": {
|
| 56 |
+
"code": "VALIDATION_ERROR",
|
| 57 |
+
"message": "Email format is invalid",
|
| 58 |
+
"field": "email"
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
## Principle 7: Rate Limiting
|
| 64 |
+
|
| 65 |
+
Implement rate limiting and communicate limits via headers:
|
| 66 |
+
|
| 67 |
+
- X-RateLimit-Limit: 1000
|
| 68 |
+
- X-RateLimit-Remaining: 999
|
| 69 |
+
- X-RateLimit-Reset: 1640000000
|
| 70 |
+
|
| 71 |
+
## Conclusion
|
| 72 |
+
|
| 73 |
+
Following these principles leads to APIs that are intuitive, consistent, and easy to maintain. Remember: the best API is one that developers can use without reading documentation.
|
public/eval-docs/distributed-systems-overview.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Distributed Systems: A Practical Overview
|
| 2 |
+
|
| 3 |
+
## What Makes a System "Distributed"?
|
| 4 |
+
|
| 5 |
+
A distributed system is a collection of independent computers that appears to users as a single coherent system. The key challenges arise from:
|
| 6 |
+
|
| 7 |
+
1. **Partial failure** - Parts of the system can fail independently
|
| 8 |
+
2. **Unreliable networks** - Messages can be lost, delayed, or duplicated
|
| 9 |
+
3. **No global clock** - Different nodes have different views of time
|
| 10 |
+
|
| 11 |
+
## The CAP Theorem
|
| 12 |
+
|
| 13 |
+
Eric Brewer's CAP theorem states that a distributed system can only provide two of three guarantees:
|
| 14 |
+
|
| 15 |
+
- **Consistency**: All nodes see the same data at the same time
|
| 16 |
+
- **Availability**: Every request receives a response
|
| 17 |
+
- **Partition tolerance**: System continues operating despite network partitions
|
| 18 |
+
|
| 19 |
+
In practice, network partitions happen, so you're really choosing between CP and AP systems.
|
| 20 |
+
|
| 21 |
+
### CP Systems (Consistency + Partition Tolerance)
|
| 22 |
+
- Examples: ZooKeeper, etcd, Consul
|
| 23 |
+
- Sacrifice availability during partitions
|
| 24 |
+
- Good for: coordination, leader election, configuration
|
| 25 |
+
|
| 26 |
+
### AP Systems (Availability + Partition Tolerance)
|
| 27 |
+
- Examples: Cassandra, DynamoDB, CouchDB
|
| 28 |
+
- Sacrifice consistency during partitions
|
| 29 |
+
- Good for: high-throughput, always-on services
|
| 30 |
+
|
| 31 |
+
## Consensus Algorithms
|
| 32 |
+
|
| 33 |
+
When nodes need to agree on something, they use consensus algorithms.
|
| 34 |
+
|
| 35 |
+
### Paxos
|
| 36 |
+
- Original consensus algorithm by Leslie Lamport
|
| 37 |
+
- Notoriously difficult to understand and implement
|
| 38 |
+
- Foundation for many other algorithms
|
| 39 |
+
|
| 40 |
+
### Raft
|
| 41 |
+
- Designed to be understandable
|
| 42 |
+
- Used in etcd, Consul, CockroachDB
|
| 43 |
+
- Separates leader election from log replication
|
| 44 |
+
|
| 45 |
+
### PBFT (Practical Byzantine Fault Tolerance)
|
| 46 |
+
- Handles malicious nodes
|
| 47 |
+
- Used in blockchain systems
|
| 48 |
+
- Higher overhead than crash-fault-tolerant algorithms
|
| 49 |
+
|
| 50 |
+
## Replication Strategies
|
| 51 |
+
|
| 52 |
+
### Single-Leader Replication
|
| 53 |
+
- One node accepts writes
|
| 54 |
+
- Followers replicate from leader
|
| 55 |
+
- Simple but leader is bottleneck
|
| 56 |
+
|
| 57 |
+
### Multi-Leader Replication
|
| 58 |
+
- Multiple nodes accept writes
|
| 59 |
+
- Must handle write conflicts
|
| 60 |
+
- Good for multi-datacenter deployments
|
| 61 |
+
|
| 62 |
+
### Leaderless Replication
|
| 63 |
+
- Any node accepts writes
|
| 64 |
+
- Uses quorum reads/writes
|
| 65 |
+
- Examples: Dynamo-style databases
|
| 66 |
+
|
| 67 |
+
## Consistency Models
|
| 68 |
+
|
| 69 |
+
From strongest to weakest:
|
| 70 |
+
|
| 71 |
+
1. **Linearizability** - Operations appear instantaneous
|
| 72 |
+
2. **Sequential consistency** - Operations appear in some sequential order
|
| 73 |
+
3. **Causal consistency** - Causally related operations appear in order
|
| 74 |
+
4. **Eventual consistency** - Given enough time, all replicas converge
|
| 75 |
+
|
| 76 |
+
## Partitioning (Sharding)
|
| 77 |
+
|
| 78 |
+
Distributing data across nodes:
|
| 79 |
+
|
| 80 |
+
### Hash Partitioning
|
| 81 |
+
- Hash key to determine partition
|
| 82 |
+
- Even distribution
|
| 83 |
+
- Range queries are inefficient
|
| 84 |
+
|
| 85 |
+
### Range Partitioning
|
| 86 |
+
- Ranges of keys on different nodes
|
| 87 |
+
- Good for range queries
|
| 88 |
+
- Risk of hot spots
|
| 89 |
+
|
| 90 |
+
## Conclusion
|
| 91 |
+
|
| 92 |
+
Building distributed systems requires understanding these fundamental concepts. Start simple, add complexity only when needed, and always plan for failure.
|
public/eval-docs/machine-learning-primer.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Machine Learning: A Beginner's Guide
|
| 2 |
+
|
| 3 |
+
## What is Machine Learning?
|
| 4 |
+
|
| 5 |
+
Machine learning is a subset of artificial intelligence where systems learn patterns from data rather than being explicitly programmed. Instead of writing rules, you provide examples and let the algorithm discover the rules.
|
| 6 |
+
|
| 7 |
+
## Types of Machine Learning
|
| 8 |
+
|
| 9 |
+
### Supervised Learning
|
| 10 |
+
|
| 11 |
+
The algorithm learns from labeled examples.
|
| 12 |
+
|
| 13 |
+
**Classification**: Predicting categories
|
| 14 |
+
- Email spam detection
|
| 15 |
+
- Image recognition
|
| 16 |
+
- Medical diagnosis
|
| 17 |
+
|
| 18 |
+
**Regression**: Predicting continuous values
|
| 19 |
+
- House price prediction
|
| 20 |
+
- Stock price forecasting
|
| 21 |
+
- Temperature prediction
|
| 22 |
+
|
| 23 |
+
Common algorithms:
|
| 24 |
+
- Linear Regression
|
| 25 |
+
- Logistic Regression
|
| 26 |
+
- Decision Trees
|
| 27 |
+
- Random Forests
|
| 28 |
+
- Support Vector Machines (SVM)
|
| 29 |
+
- Neural Networks
|
| 30 |
+
|
| 31 |
+
### Unsupervised Learning
|
| 32 |
+
|
| 33 |
+
The algorithm finds patterns in unlabeled data.
|
| 34 |
+
|
| 35 |
+
**Clustering**: Grouping similar items
|
| 36 |
+
- Customer segmentation
|
| 37 |
+
- Document categorization
|
| 38 |
+
- Anomaly detection
|
| 39 |
+
|
| 40 |
+
**Dimensionality Reduction**: Simplifying data
|
| 41 |
+
- Feature extraction
|
| 42 |
+
- Visualization
|
| 43 |
+
- Noise reduction
|
| 44 |
+
|
| 45 |
+
Common algorithms:
|
| 46 |
+
- K-Means Clustering
|
| 47 |
+
- Hierarchical Clustering
|
| 48 |
+
- Principal Component Analysis (PCA)
|
| 49 |
+
- t-SNE
|
| 50 |
+
|
| 51 |
+
### Reinforcement Learning
|
| 52 |
+
|
| 53 |
+
The algorithm learns through trial and error, receiving rewards or penalties.
|
| 54 |
+
|
| 55 |
+
Applications:
|
| 56 |
+
- Game playing (AlphaGo, chess)
|
| 57 |
+
- Robotics
|
| 58 |
+
- Autonomous vehicles
|
| 59 |
+
- Resource management
|
| 60 |
+
|
| 61 |
+
## The Machine Learning Pipeline
|
| 62 |
+
|
| 63 |
+
1. **Data Collection**: Gather relevant data
|
| 64 |
+
2. **Data Cleaning**: Handle missing values, outliers
|
| 65 |
+
3. **Feature Engineering**: Create useful features
|
| 66 |
+
4. **Model Selection**: Choose appropriate algorithm
|
| 67 |
+
5. **Training**: Fit model to training data
|
| 68 |
+
6. **Evaluation**: Test on held-out data
|
| 69 |
+
7. **Deployment**: Put model into production
|
| 70 |
+
8. **Monitoring**: Track performance over time
|
| 71 |
+
|
| 72 |
+
## Key Concepts
|
| 73 |
+
|
| 74 |
+
### Overfitting vs Underfitting
|
| 75 |
+
|
| 76 |
+
**Overfitting**: Model memorizes training data, performs poorly on new data
|
| 77 |
+
- Solution: More data, regularization, simpler model
|
| 78 |
+
|
| 79 |
+
**Underfitting**: Model too simple to capture patterns
|
| 80 |
+
- Solution: More features, complex model, less regularization
|
| 81 |
+
|
| 82 |
+
### Train/Test Split
|
| 83 |
+
|
| 84 |
+
Never evaluate on training data. Common splits:
|
| 85 |
+
- 80% training, 20% testing
|
| 86 |
+
- 70% training, 15% validation, 15% testing
|
| 87 |
+
|
| 88 |
+
### Cross-Validation
|
| 89 |
+
|
| 90 |
+
K-fold cross-validation provides more robust evaluation:
|
| 91 |
+
1. Split data into K folds
|
| 92 |
+
2. Train on K-1 folds, test on remaining fold
|
| 93 |
+
3. Repeat K times
|
| 94 |
+
4. Average the results
|
| 95 |
+
|
| 96 |
+
### Bias-Variance Tradeoff
|
| 97 |
+
|
| 98 |
+
- **High Bias**: Oversimplified model (underfitting)
|
| 99 |
+
- **High Variance**: Overcomplicated model (overfitting)
|
| 100 |
+
- Goal: Find the sweet spot
|
| 101 |
+
|
| 102 |
+
## Evaluation Metrics
|
| 103 |
+
|
| 104 |
+
### Classification
|
| 105 |
+
- Accuracy: Correct predictions / Total predictions
|
| 106 |
+
- Precision: True positives / Predicted positives
|
| 107 |
+
- Recall: True positives / Actual positives
|
| 108 |
+
- F1 Score: Harmonic mean of precision and recall
|
| 109 |
+
- AUC-ROC: Area under receiver operating curve
|
| 110 |
+
|
| 111 |
+
### Regression
|
| 112 |
+
- Mean Absolute Error (MAE)
|
| 113 |
+
- Mean Squared Error (MSE)
|
| 114 |
+
- Root Mean Squared Error (RMSE)
|
| 115 |
+
- R-squared (R2)
|
| 116 |
+
|
| 117 |
+
## Getting Started
|
| 118 |
+
|
| 119 |
+
1. Learn Python and libraries (NumPy, Pandas, Scikit-learn)
|
| 120 |
+
2. Work through classic datasets (Iris, MNIST, Titanic)
|
| 121 |
+
3. Take online courses (Coursera, fast.ai)
|
| 122 |
+
4. Practice on Kaggle competitions
|
| 123 |
+
5. Build projects with real-world data
|
| 124 |
+
|
| 125 |
+
Remember: Machine learning is 80% data preparation and 20% modeling. Start with clean data and simple models before going complex.
|
src/App.tsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function App() {
|
| 2 |
+
return (
|
| 3 |
+
<div style={{ fontFamily: 'system-ui, sans-serif', padding: '2rem' }}>
|
| 4 |
+
<h1>QMD Web Demo</h1>
|
| 5 |
+
<p>In-Browser Hybrid Search Pipeline</p>
|
| 6 |
+
</div>
|
| 7 |
+
)
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export default App
|
src/main.tsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { StrictMode } from 'react'
|
| 2 |
+
import { createRoot } from 'react-dom/client'
|
| 3 |
+
import App from './App.tsx'
|
| 4 |
+
|
| 5 |
+
createRoot(document.getElementById('root')!).render(
|
| 6 |
+
<StrictMode>
|
| 7 |
+
<App />
|
| 8 |
+
</StrictMode>,
|
| 9 |
+
)
|
tsconfig.app.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
| 4 |
+
"target": "ES2022",
|
| 5 |
+
"useDefineForClassFields": true,
|
| 6 |
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
| 7 |
+
"module": "ESNext",
|
| 8 |
+
"types": ["vite/client"],
|
| 9 |
+
"skipLibCheck": true,
|
| 10 |
+
|
| 11 |
+
/* Bundler mode */
|
| 12 |
+
"moduleResolution": "bundler",
|
| 13 |
+
"allowImportingTsExtensions": true,
|
| 14 |
+
"verbatimModuleSyntax": true,
|
| 15 |
+
"moduleDetection": "force",
|
| 16 |
+
"noEmit": true,
|
| 17 |
+
"jsx": "react-jsx",
|
| 18 |
+
|
| 19 |
+
/* Linting */
|
| 20 |
+
"strict": true,
|
| 21 |
+
"noUnusedLocals": true,
|
| 22 |
+
"noUnusedParameters": true,
|
| 23 |
+
"erasableSyntaxOnly": true,
|
| 24 |
+
"noFallthroughCasesInSwitch": true,
|
| 25 |
+
"noUncheckedSideEffectImports": true
|
| 26 |
+
},
|
| 27 |
+
"include": ["src"]
|
| 28 |
+
}
|
tsconfig.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"files": [],
|
| 3 |
+
"references": [
|
| 4 |
+
{ "path": "./tsconfig.app.json" },
|
| 5 |
+
{ "path": "./tsconfig.node.json" }
|
| 6 |
+
]
|
| 7 |
+
}
|
tsconfig.node.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
| 4 |
+
"target": "ES2023",
|
| 5 |
+
"lib": ["ES2023"],
|
| 6 |
+
"module": "ESNext",
|
| 7 |
+
"types": ["node"],
|
| 8 |
+
"skipLibCheck": true,
|
| 9 |
+
|
| 10 |
+
/* Bundler mode */
|
| 11 |
+
"moduleResolution": "bundler",
|
| 12 |
+
"allowImportingTsExtensions": true,
|
| 13 |
+
"verbatimModuleSyntax": true,
|
| 14 |
+
"moduleDetection": "force",
|
| 15 |
+
"noEmit": true,
|
| 16 |
+
|
| 17 |
+
/* Linting */
|
| 18 |
+
"strict": true,
|
| 19 |
+
"noUnusedLocals": true,
|
| 20 |
+
"noUnusedParameters": true,
|
| 21 |
+
"erasableSyntaxOnly": true,
|
| 22 |
+
"noFallthroughCasesInSwitch": true,
|
| 23 |
+
"noUncheckedSideEffectImports": true
|
| 24 |
+
},
|
| 25 |
+
"include": ["vite.config.ts"]
|
| 26 |
+
}
|
vite.config.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig } from 'vite'
|
| 2 |
+
import react from '@vitejs/plugin-react'
|
| 3 |
+
|
| 4 |
+
// https://vite.dev/config/
|
| 5 |
+
export default defineConfig({
|
| 6 |
+
plugins: [react()],
|
| 7 |
+
})
|