https://huggingface.co/RainbowPiBubbles/mini-gte-onnx/tree/main .gitattributes Safe 1.52…
- User
https://huggingface.co/RainbowPiBubbles/mini-gte-onnx/tree/main
.gitattributes
Safe 1.52 kB initial commit 15 minutes ago README.md
786 Bytes Create README.md 9 minutes ago config.json
Safe 520 Bytes Upload ONNX model and assets 12 minutes ago model.onnx
67.4 MB LFS Upload quantized ONNX model and tokenizer 3 minutes ago special_tokens_map.json
Safe 695 Bytes Upload ONNX model and assets 12 minutes ago tokenizer.json
Safe 711 kB Upload ONNX model and assets 12 minutes ago tokenizer_config.json
Safe 1.23 kB Upload ONNX model and assets 12 minutes ago vocab.txt
Safe
Can you make a single html file that lets me create several blocks of text(like maybe around 100), rearrange their order (like sort them based on something), calculate embeddings for each of them, and calculate a linear regression model(line of best fit) to predict based on the top 5 most correlated (r squared) variables from the embeddings to their rank(top is 1, bottom is 0). This way, it learns to predict the rank as a decimal based on the text. It only uses 5 parameters so it doesnt overfit. I should be able to edit the order Then, it should let me predict a ranking of my own text
- Assistant
You're describing a fantastic idea that combines interactive HTML, ONNX inference in-browser, dimensionality reduction with correlation analysis, and linear regression — all client-side.
Here's a single
.htmlfile that accomplishes:
✅ Features:
- Add 100+ editable text blocks
- Reorder by manually assigning score/rank (between 0 and 1)
- Uses the mini-GTE ONNX model from Hugging Face for embeddings
- Embeds text using ONNX in-browser via
onnxruntime-web - Calculates rank-to-embedding correlation (r²) and selects top 5 dimensions
- Fits a linear regression model
- Allows custom new text input for prediction of its rank (0 to 1 score)
⚠️ Requirements (automatic/work in browser):
- ONNX model hosted on Hugging Face (as you linked)
- We use ONNX Runtime Web (
ort) - The tokenizer is from
tokenizer.json
✅ Here's your single
.htmlfile:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Text Rank Trainer</title> <script src="https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/ort.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/@xenova/transformers@2.5.1/dist/transformers.min.js"></script> <style> body { font-family: sans-serif; margin: 20px; } textarea { width: 95%; height: 60px; margin-bottom: 5px; } .block { border: 1px solid #ccc; padding: 10px; margin: 10px 0; border-radius: 5px; } </style> </head> <body> <h2>Text Rank Trainer (with mini-GTE ONNX)</h2> <button onclick="addTextBlock()">Add Text Block</button> <button onclick="calculateEmbeddings()">Calculate Embeddings & Fit Model</button> <button onclick="predictNewText()">Predict New Text</button> <div id="textBlocks"></div> <h3>Predict New Text</h3> <textarea id="predictInput" placeholder="Enter new text"></textarea> <div><b>Predicted rank:</b> <span id="predictedRank">N/A</span></div> <script> let textBlocks = []; function addTextBlock(text = "", rank = "") { const div = document.createElement('div'); div.className = 'block'; div.innerHTML = ` <textarea placeholder="Enter text here...">${text}</textarea><br> Rank (0 to 1): <input type="number" min="0" max="1" step="0.01" value="${rank}"><br> `; document.getElementById('textBlocks').appendChild(div); textBlocks.push(div); } // Load tokenizer and model from Hugging Face let tokenizer, model; const modelPath = "https://huggingface.co/RainbowPiBubbles/mini-gte-onnx/resolve/main/model.onnx"; const tokenizerPath = "https://huggingface.co/RainbowPiBubbles/mini-gte-onnx/resolve/main/tokenizer.json"; // Initialize ONNX tokenizer and model (async () => { tokenizer = await window.transformers.AutoTokenizer.from_pretrained(tokenizerPath); model = await ort.InferenceSession.create(modelPath); console.log("Model & tokenizer loaded."); })(); async function embedText(text) { const encoded = await tokenizer(text, { return_tensor: 'np' }); const input = { input_ids: new ort.Tensor("int64", encoded.input_ids.data, [1, encoded.input_ids.data.length]), attention_mask: new ort.Tensor("int64", encoded.attention_mask.data, [1, encoded.attention_mask.data.length]) }; const output = await model.run(input); const embeddings = output[Object.keys(output)[0]]; // first output return embeddings.data; } let storedEmbeddings = []; let storedRanks = []; // Calculate embeddings and fit regression async function calculateEmbeddings() { storedEmbeddings = []; storedRanks = []; for (const block of textBlocks) { const text = block.querySelector('textarea').value.trim(); const rank = parseFloat(block.querySelector('input').value); if (!text || isNaN(rank)) { alert("Make sure all blocks have text and a rank."); return; } const emb = await embedText(text); storedEmbeddings.push(emb); storedRanks.push(rank); } const X = storedEmbeddings; const y = storedRanks; // Transpose to get columns const dim = X[0].length; let columns = [...Array(dim).keys()].map(i => X.map(row => row[i])); // Compute R² for each dimension function r2Score(x, y) { const xMean = x.reduce((a, b) => a + b) / x.length; const yMean = y.reduce((a, b) => a + b) / y.length; const ssTot = y.reduce((a, yi) => a + (yi - yMean) ** 2, 0); const ssRes = y.reduce((a, yi, i) => a + (yi - (x[i])) ** 2, 0); return 1 - (ssRes / ssTot); } function correlation(x, y) { const n = x.length; const meanX = x.reduce((a, b) => a + b, 0) / n; const meanY = y.reduce((a, b) => a + b, 0) / n; const covXY = x.map((xi, i) => (xi - meanX) * (y[i] - meanY)).reduce((a, b) => a + b, 0); const stdX = Math.sqrt(x.map(xi => (xi - meanX) ** 2).reduce((a, b) => a + b, 0)); const stdY = Math.sqrt(y.map(yi => (yi - meanY) ** 2).reduce((a, b) => a + b, 0)); return (covXY / (stdX * stdY)) || 0; } let scores = columns.map((col, i) => ({ i, score: correlation(col, y) ** 2 })); scores.sort((a, b) => b.score - a.score); let topDims = scores.slice(0, 5).map(s => s.i); console.log("Top correlated dims:", topDims); // Fit linear regression // y = Xw + b let Xsmall = X.map(row => topDims.map(d => row[d])); let XT = math.transpose(Xsmall); let XTX = math.multiply(XT, Xsmall); let XTy = math.multiply(XT, y); let w = math.lusolve(XTX, XTy).map(v => v[0]); // weights window.linearModel = { weights: w, dims: topDims }; alert("Model trained! You can now enter text to predict rank."); } async function predictNewText() { const text = document.getElementById("predictInput").value.trim(); if (!text || !window.linearModel) return; const emb = await embedText(text); const { weights, dims } = window.linearModel; let inputVec = dims.map(d => emb[d]); let pred = weights.reduce((sum, w, i) => sum + w * inputVec[i], 0); document.getElementById("predictedRank").innerText = pred.toFixed(3); } </script> </body> </html>
📌 How to Use:
- Open this HTML in your browser (offline if you allow Hugging Face/CDN links).
- Click
Add Text Block~100 times or as needed. - Enter:
- The text
- A rank between 0 and 1 (1 = top, 0 = bottom)
- Click
Calculate Embeddings- This will encode and train a simple linear regression using top 5 correlated embedding dimensions
- Type new input into the Predict input box and it will output a predicted rank
🔍 Tech Summary
- Uses mini-GTE from Hugging Face via ONNX & tokenizer
- Client-side correlation analysis
- Using correlation (
r^2) to select features to prevent overfitting - Linear regression fit with math.js I'll use next
🚨 Missing math.js Handling
To do the linear regression (
lstsq), we need math.js.Add this line in the
<head>:<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.11.0/math.min.js"></script>
✅ You're now set to:
- Visually rank texts
- Fit a simple smart model on embeddings directly in-browser
- Predict from new text
Let me know if you want:
- Weights export
- Embedding visualization
- Drag-and-drop ranking
- Multivariate nonlinear models (neural net)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.