René's URL Explorer Experiment


Title: Mini LLM in JavaScript - Runnable Code Snippet

Open Graph Title: Mini LLM in JavaScript - Runnable Code Snippet

X Title: Mini LLM in JavaScript - Runnable Code Snippet

Description: Demonstrate the core mechanism behind LLMs by predicting the next token, appending it, and repeating. Runnable JavaScript snippet with live execution.

Open Graph Description: Demonstrate the core mechanism behind LLMs by predicting the next token, appending it, and repeating. Runnable JavaScript snippet with live execution.

X Description: Demonstrate the core mechanism behind LLMs by predicting the next token, appending it, and repeating. Runnable JavaScript snippet with live execution.

Keywords:

Opengraph URL: https://tempercode.dev/snippets/mini-llm-javascript

direct link

Domain: tempercode.dev


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"SoftwareSourceCode","name":"Mini LLM","description":"Demonstrate the core mechanism behind LLMs by predicting the next token, appending it, and repeating.","programmingLanguage":"JavaScript","text":"// LLM is a next-token predictor. That's the whole trick.\n// It looks at text, predicts what comes next, appends it, and repeats.\n\n// These patterns simulate what a model \"learned\" from training.\n// Real LLM learned from trillions of words - same idea, bigger scale.\nconst learned = {\n  'hel': {'l': 0.9},\n  'ell': {'o': 0.9},\n  'llo': {' ': 0.6, '!': 0.3},\n  'lo ': {'w': 0.5, 't': 0.3},\n  'o w': {'o': 0.8},\n  ' wo': {'r': 0.9},\n  'wor': {'l': 0.7},\n  'orl': {'d': 0.9},\n  'the': {' ': 0.9},\n  'he ': {'c': 0.4},\n  'e c': {'a': 0.8},\n  ' ca': {'t': 0.7},\n  'cat': {' ': 0.6, 's': 0.3},\n  'at ': {'s': 0.5},\n  't s': {'a': 0.6},\n  ' sa': {'t': 0.7},\n};\n\nlet text = prompt.toLowerCase();\nconst steps = [`Generating from \"${text}\":`];\n\n// Generate up to 12 more characters\nfor (let i = 0; i < 12 && text.length < 20; i++) {\n  const context = text.slice(-3);\n  const probs = learned[context];\n\n  if (!probs) break;  // Unknown pattern\n\n  // Pick highest probability (greedy decoding)\n  const [next, prob] = Object.entries(probs).sort((a,b) => b[1]-a[1])[0];\n  steps.push(`  \"${context}\" → \"${next}\" (${Math.round(prob*100)}%)`);\n  text += next;\n}\n\nsteps.push(`Result: \"${text}\"`);\nreturn steps.join('\\n');"}

theme-color#0c0d12
color-schemedark
authorTemper
creatorTemper
publisherTemper
og:imagehttps://tempercode.dev/og-image.png
og:typearticle
twitter:cardsummary_large_image
twitter:imagehttps://tempercode.dev/og-image.png

Links:

Temperhttps://tempercode.dev/snippets
Snippetshttps://tempercode.dev/snippets
Editorhttps://tempercode.dev/editor
CLIhttps://tempercode.dev/cli
https://github.com/handcraftbyte/temper-snippets
Snippetshttps://tempercode.dev/snippets
Editorhttps://tempercode.dev/editor
CLIhttps://tempercode.dev/cli
https://github.com/handcraftbyte/temper-snippets/blob/main/algorithms/mini-llm-javascript.md
Pythonhttps://tempercode.dev/snippets/mini-llm-python
Rubyhttps://tempercode.dev/snippets/mini-llm-ruby
PHPhttps://tempercode.dev/snippets/mini-llm-php
Add Days to DateAdd a specified number of days to a date and return the result in ISO format.https://tempercode.dev/snippets/add-days-javascript
Add Query ParameterAdd or update a query parameter in a URL string.https://tempercode.dev/snippets/add-query-param-javascript
Array DifferenceFind elements in the first array that are not present in the second array.https://tempercode.dev/snippets/array-difference-javascript
Array FrequenciesCount how many times each value appears in an array and return a frequency map.https://tempercode.dev/snippets/array-frequencies-javascript
Array HeadGet the first n elements of an array.https://tempercode.dev/snippets/array-head-javascript
Array IntersectionFind common elements that exist in both arrays.https://tempercode.dev/snippets/array-intersection-javascript

Viewport: width=device-width, initial-scale=1


URLs of crawlers that visited me.