feat: Add support for switching models and the 27b-4a backend
Browse files- firefox-extension/content.js +13 -6
- firefox-extension/popup.html +7 -0
- firefox-extension/popup.js +6 -1
- flowread-extension.zip +0 -0
- generate_all.py +111 -0
- main.py +64 -20
- requirements.txt +2 -1
- study_texts.json +89 -0
- test_tok.py +14 -0
- test_tok2.py +8 -0
firefox-extension/content.js
CHANGED
|
@@ -37,18 +37,19 @@ browser.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
|
|
| 37 |
const range = selection.getRangeAt(0);
|
| 38 |
|
| 39 |
// Get user settings
|
| 40 |
-
const settings = await browser.storage.local.get(['threshold', 'gradientMode', 'preprompt', 'saliencyMode', 'apiUrl']);
|
| 41 |
const threshold = settings.threshold !== undefined ? settings.threshold : 0.35;
|
| 42 |
const useGradient = settings.gradientMode || false;
|
| 43 |
const preprompt = settings.preprompt || "";
|
| 44 |
const saliencyMode = settings.saliencyMode || "local";
|
|
|
|
| 45 |
const apiUrl = settings.apiUrl || "http://127.0.0.1:8000";
|
| 46 |
// Default to middle layers just like the playground
|
| 47 |
const checkedLayers = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
| 48 |
|
| 49 |
try {
|
| 50 |
// Connect to the configured API Space
|
| 51 |
-
const response = await fetch(`${apiUrl}/analyze`, {
|
| 52 |
method: 'POST',
|
| 53 |
headers: { 'Content-Type': 'application/json' },
|
| 54 |
body: JSON.stringify({
|
|
@@ -75,6 +76,7 @@ browser.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
|
|
| 75 |
container.dataset.tokens = JSON.stringify(currentTokens);
|
| 76 |
container.dataset.preprompt = preprompt;
|
| 77 |
container.dataset.saliencyMode = saliencyMode;
|
|
|
|
| 78 |
container.dataset.originalText = selectedText;
|
| 79 |
container.innerHTML = htmlString;
|
| 80 |
range.insertNode(container);
|
|
@@ -93,11 +95,12 @@ browser.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
|
|
| 93 |
});
|
| 94 |
|
| 95 |
async function processEntirePage() {
|
| 96 |
-
const settings = await browser.storage.local.get(['threshold', 'gradientMode', 'preprompt', 'saliencyMode', 'apiUrl']);
|
| 97 |
const threshold = settings.threshold !== undefined ? settings.threshold : 0.35;
|
| 98 |
const useGradient = settings.gradientMode || false;
|
| 99 |
const preprompt = settings.preprompt || "";
|
| 100 |
const saliencyMode = settings.saliencyMode || "local";
|
|
|
|
| 101 |
const apiUrl = settings.apiUrl || "http://127.0.0.1:8000";
|
| 102 |
const checkedLayers = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
| 103 |
|
|
@@ -165,7 +168,7 @@ async function processEntirePage() {
|
|
| 165 |
if (!text.trim()) return;
|
| 166 |
|
| 167 |
try {
|
| 168 |
-
const response = await fetch(`${apiUrl}/analyze`, {
|
| 169 |
method: 'POST',
|
| 170 |
headers: { 'Content-Type': 'application/json' },
|
| 171 |
body: JSON.stringify({
|
|
@@ -187,6 +190,7 @@ async function processEntirePage() {
|
|
| 187 |
container.dataset.tokens = JSON.stringify(data.words);
|
| 188 |
container.dataset.preprompt = preprompt;
|
| 189 |
container.dataset.saliencyMode = saliencyMode;
|
|
|
|
| 190 |
container.dataset.originalText = text;
|
| 191 |
container.innerHTML = htmlString;
|
| 192 |
|
|
@@ -210,6 +214,7 @@ async function updateExisting(newSettings) {
|
|
| 210 |
const useGradient = newSettings.gradientMode || false;
|
| 211 |
const preprompt = newSettings.preprompt || "";
|
| 212 |
const saliencyMode = newSettings.saliencyMode || "local";
|
|
|
|
| 213 |
const apiUrl = newSettings.apiUrl || "http://127.0.0.1:8000";
|
| 214 |
const checkedLayers = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
| 215 |
|
|
@@ -222,15 +227,16 @@ async function updateExisting(newSettings) {
|
|
| 222 |
for (const container of containers) {
|
| 223 |
const oldPreprompt = container.dataset.preprompt || "";
|
| 224 |
const oldMode = container.dataset.saliencyMode || "local";
|
|
|
|
| 225 |
const text = container.dataset.originalText;
|
| 226 |
if (!text) continue;
|
| 227 |
|
| 228 |
-
if (oldPreprompt !== preprompt || oldMode !== saliencyMode) {
|
| 229 |
if (reFetchCount === 0) {
|
| 230 |
showToast("Updating FlowRead elements with new settings...", 0);
|
| 231 |
}
|
| 232 |
try {
|
| 233 |
-
const response = await fetch(`${apiUrl}/analyze`, {
|
| 234 |
method: 'POST',
|
| 235 |
headers: { 'Content-Type': 'application/json' },
|
| 236 |
body: JSON.stringify({
|
|
@@ -248,6 +254,7 @@ async function updateExisting(newSettings) {
|
|
| 248 |
container.dataset.tokens = JSON.stringify(data.words);
|
| 249 |
container.dataset.preprompt = preprompt;
|
| 250 |
container.dataset.saliencyMode = saliencyMode;
|
|
|
|
| 251 |
const htmlString = generateFlowReadHTML(data.words, threshold, useGradient);
|
| 252 |
container.innerHTML = htmlString;
|
| 253 |
reFetchCount++;
|
|
|
|
| 37 |
const range = selection.getRangeAt(0);
|
| 38 |
|
| 39 |
// Get user settings
|
| 40 |
+
const settings = await browser.storage.local.get(['threshold', 'gradientMode', 'preprompt', 'saliencyMode', 'modelVersion', 'apiUrl']);
|
| 41 |
const threshold = settings.threshold !== undefined ? settings.threshold : 0.35;
|
| 42 |
const useGradient = settings.gradientMode || false;
|
| 43 |
const preprompt = settings.preprompt || "";
|
| 44 |
const saliencyMode = settings.saliencyMode || "local";
|
| 45 |
+
const modelVersion = settings.modelVersion || "2b";
|
| 46 |
const apiUrl = settings.apiUrl || "http://127.0.0.1:8000";
|
| 47 |
// Default to middle layers just like the playground
|
| 48 |
const checkedLayers = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
| 49 |
|
| 50 |
try {
|
| 51 |
// Connect to the configured API Space
|
| 52 |
+
const response = await fetch(`${apiUrl}/analyze/${modelVersion}`, {
|
| 53 |
method: 'POST',
|
| 54 |
headers: { 'Content-Type': 'application/json' },
|
| 55 |
body: JSON.stringify({
|
|
|
|
| 76 |
container.dataset.tokens = JSON.stringify(currentTokens);
|
| 77 |
container.dataset.preprompt = preprompt;
|
| 78 |
container.dataset.saliencyMode = saliencyMode;
|
| 79 |
+
container.dataset.modelVersion = modelVersion;
|
| 80 |
container.dataset.originalText = selectedText;
|
| 81 |
container.innerHTML = htmlString;
|
| 82 |
range.insertNode(container);
|
|
|
|
| 95 |
});
|
| 96 |
|
| 97 |
async function processEntirePage() {
|
| 98 |
+
const settings = await browser.storage.local.get(['threshold', 'gradientMode', 'preprompt', 'saliencyMode', 'modelVersion', 'apiUrl']);
|
| 99 |
const threshold = settings.threshold !== undefined ? settings.threshold : 0.35;
|
| 100 |
const useGradient = settings.gradientMode || false;
|
| 101 |
const preprompt = settings.preprompt || "";
|
| 102 |
const saliencyMode = settings.saliencyMode || "local";
|
| 103 |
+
const modelVersion = settings.modelVersion || "2b";
|
| 104 |
const apiUrl = settings.apiUrl || "http://127.0.0.1:8000";
|
| 105 |
const checkedLayers = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
| 106 |
|
|
|
|
| 168 |
if (!text.trim()) return;
|
| 169 |
|
| 170 |
try {
|
| 171 |
+
const response = await fetch(`${apiUrl}/analyze/${modelVersion}`, {
|
| 172 |
method: 'POST',
|
| 173 |
headers: { 'Content-Type': 'application/json' },
|
| 174 |
body: JSON.stringify({
|
|
|
|
| 190 |
container.dataset.tokens = JSON.stringify(data.words);
|
| 191 |
container.dataset.preprompt = preprompt;
|
| 192 |
container.dataset.saliencyMode = saliencyMode;
|
| 193 |
+
container.dataset.modelVersion = modelVersion;
|
| 194 |
container.dataset.originalText = text;
|
| 195 |
container.innerHTML = htmlString;
|
| 196 |
|
|
|
|
| 214 |
const useGradient = newSettings.gradientMode || false;
|
| 215 |
const preprompt = newSettings.preprompt || "";
|
| 216 |
const saliencyMode = newSettings.saliencyMode || "local";
|
| 217 |
+
const modelVersion = newSettings.modelVersion || "2b";
|
| 218 |
const apiUrl = newSettings.apiUrl || "http://127.0.0.1:8000";
|
| 219 |
const checkedLayers = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
| 220 |
|
|
|
|
| 227 |
for (const container of containers) {
|
| 228 |
const oldPreprompt = container.dataset.preprompt || "";
|
| 229 |
const oldMode = container.dataset.saliencyMode || "local";
|
| 230 |
+
const oldModelVersion = container.dataset.modelVersion || "2b";
|
| 231 |
const text = container.dataset.originalText;
|
| 232 |
if (!text) continue;
|
| 233 |
|
| 234 |
+
if (oldPreprompt !== preprompt || oldMode !== saliencyMode || oldModelVersion !== modelVersion) {
|
| 235 |
if (reFetchCount === 0) {
|
| 236 |
showToast("Updating FlowRead elements with new settings...", 0);
|
| 237 |
}
|
| 238 |
try {
|
| 239 |
+
const response = await fetch(`${apiUrl}/analyze/${modelVersion}`, {
|
| 240 |
method: 'POST',
|
| 241 |
headers: { 'Content-Type': 'application/json' },
|
| 242 |
body: JSON.stringify({
|
|
|
|
| 254 |
container.dataset.tokens = JSON.stringify(data.words);
|
| 255 |
container.dataset.preprompt = preprompt;
|
| 256 |
container.dataset.saliencyMode = saliencyMode;
|
| 257 |
+
container.dataset.modelVersion = modelVersion;
|
| 258 |
const htmlString = generateFlowReadHTML(data.words, threshold, useGradient);
|
| 259 |
container.innerHTML = htmlString;
|
| 260 |
reFetchCount++;
|
firefox-extension/popup.html
CHANGED
|
@@ -98,6 +98,13 @@
|
|
| 98 |
</select>
|
| 99 |
<p class="help" style="margin-top: 0;">Global mode allows comparing importance across different paragraphs.</p>
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
<label for="api-url">Backend API URL</label>
|
| 102 |
<input type="text" id="api-url" placeholder="http://127.0.0.1:8000">
|
| 103 |
<p class="help">URL of your FlowRead backend (Local or Hugging Face).</p>
|
|
|
|
| 98 |
</select>
|
| 99 |
<p class="help" style="margin-top: 0;">Global mode allows comparing importance across different paragraphs.</p>
|
| 100 |
|
| 101 |
+
<label for="model-version">Model Version</label>
|
| 102 |
+
<select id="model-version" style="width: 100%; margin-bottom: 15px; padding: 8px; border: 1px solid #d6d3d1; border-radius: 4px; font-family: inherit;">
|
| 103 |
+
<option value="2b">Gemma 2B (Fast / Default)</option>
|
| 104 |
+
<option value="27b-4a">Gemma 27B 4-bit (High Quality)</option>
|
| 105 |
+
</select>
|
| 106 |
+
<p class="help" style="margin-top: 0;">Select which LLM to use for saliency analysis.</p>
|
| 107 |
+
|
| 108 |
<label for="api-url">Backend API URL</label>
|
| 109 |
<input type="text" id="api-url" placeholder="http://127.0.0.1:8000">
|
| 110 |
<p class="help">URL of your FlowRead backend (Local or Hugging Face).</p>
|
firefox-extension/popup.js
CHANGED
|
@@ -4,12 +4,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 4 |
const gradientModeInput = document.getElementById('gradient-mode');
|
| 5 |
const prepromptInput = document.getElementById('preprompt');
|
| 6 |
const saliencyModeInput = document.getElementById('saliency-mode');
|
|
|
|
| 7 |
const apiUrlInput = document.getElementById('api-url');
|
| 8 |
const saveBtn = document.getElementById('save-btn');
|
| 9 |
const pageBtn = document.getElementById('page-btn');
|
| 10 |
|
| 11 |
// Load existing settings
|
| 12 |
-
browser.storage.local.get(['threshold', 'gradientMode', 'preprompt', 'saliencyMode', 'apiUrl'], (res) => {
|
| 13 |
if (res.threshold !== undefined) {
|
| 14 |
thresholdInput.value = res.threshold;
|
| 15 |
thresholdVal.textContent = parseFloat(res.threshold).toFixed(2);
|
|
@@ -23,6 +24,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 23 |
if (res.saliencyMode !== undefined) {
|
| 24 |
saliencyModeInput.value = res.saliencyMode;
|
| 25 |
}
|
|
|
|
|
|
|
|
|
|
| 26 |
apiUrlInput.value = res.apiUrl || "http://127.0.0.1:8000";
|
| 27 |
});
|
| 28 |
|
|
@@ -38,6 +42,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 38 |
gradientMode: gradientModeInput.checked,
|
| 39 |
preprompt: prepromptInput.value.trim(),
|
| 40 |
saliencyMode: saliencyModeInput.value,
|
|
|
|
| 41 |
apiUrl: apiUrlInput.value.trim().replace(/\/$/, '') // Remove trailing slash
|
| 42 |
};
|
| 43 |
|
|
|
|
| 4 |
const gradientModeInput = document.getElementById('gradient-mode');
|
| 5 |
const prepromptInput = document.getElementById('preprompt');
|
| 6 |
const saliencyModeInput = document.getElementById('saliency-mode');
|
| 7 |
+
const modelVersionInput = document.getElementById('model-version');
|
| 8 |
const apiUrlInput = document.getElementById('api-url');
|
| 9 |
const saveBtn = document.getElementById('save-btn');
|
| 10 |
const pageBtn = document.getElementById('page-btn');
|
| 11 |
|
| 12 |
// Load existing settings
|
| 13 |
+
browser.storage.local.get(['threshold', 'gradientMode', 'preprompt', 'saliencyMode', 'modelVersion', 'apiUrl'], (res) => {
|
| 14 |
if (res.threshold !== undefined) {
|
| 15 |
thresholdInput.value = res.threshold;
|
| 16 |
thresholdVal.textContent = parseFloat(res.threshold).toFixed(2);
|
|
|
|
| 24 |
if (res.saliencyMode !== undefined) {
|
| 25 |
saliencyModeInput.value = res.saliencyMode;
|
| 26 |
}
|
| 27 |
+
if (res.modelVersion !== undefined) {
|
| 28 |
+
modelVersionInput.value = res.modelVersion;
|
| 29 |
+
}
|
| 30 |
apiUrlInput.value = res.apiUrl || "http://127.0.0.1:8000";
|
| 31 |
});
|
| 32 |
|
|
|
|
| 42 |
gradientMode: gradientModeInput.checked,
|
| 43 |
preprompt: prepromptInput.value.trim(),
|
| 44 |
saliencyMode: saliencyModeInput.value,
|
| 45 |
+
modelVersion: modelVersionInput.value,
|
| 46 |
apiUrl: apiUrlInput.value.trim().replace(/\/$/, '') // Remove trailing slash
|
| 47 |
};
|
| 48 |
|
flowread-extension.zip
CHANGED
|
Binary files a/flowread-extension.zip and b/flowread-extension.zip differ
|
|
|
generate_all.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
texts = [
|
| 5 |
+
{
|
| 6 |
+
"id": 1,
|
| 7 |
+
"topic": "Science",
|
| 8 |
+
"text": "The human brain is a marvel of biological engineering, containing approximately 86 billion neurons interconnected by trillions of synapses. These neural networks are responsible for everything from basic autonomic functions, like breathing and heart rate, to complex cognitive processes such as memory, emotion, and problem-solving. Neuroplasticity, the brain's ability to reorganize itself by forming new neural connections throughout life, allows humans to learn new skills, recover from injuries, and adapt to changing environments. This extraordinary adaptability is what makes our species so resilient and capable of continuous intellectual growth.",
|
| 9 |
+
"questions": [
|
| 10 |
+
{
|
| 11 |
+
"question": "Approximately how many neurons are in the human brain?",
|
| 12 |
+
"options": ["86 million", "86 billion", "100 trillion", "50 billion"],
|
| 13 |
+
"correct": 1
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"question": "What is the term for the brain's ability to reorganize itself?",
|
| 17 |
+
"options": ["Synaptic generation", "Neurogenesis", "Neuroplasticity", "Cognitive adaptation"],
|
| 18 |
+
"correct": 2
|
| 19 |
+
}
|
| 20 |
+
]
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"id": 2,
|
| 24 |
+
"topic": "History",
|
| 25 |
+
"text": "The Industrial Revolution, which began in Britain in the late 18th century, marked a profound turning point in human history. It initiated the transition from agrarian, handicraft economies to industry and machine manufacturing. The invention of the steam engine, pioneered by figures like James Watt, dramatically increased the efficiency of factories and transportation, revolutionizing the textile industry and leading to the expansion of railways. This era brought about unprecedented economic growth and urbanization, fundamentally altering social structures and paving the way for the modern capitalist system, despite also causing significant social inequalities and poor working conditions initially.",
|
| 26 |
+
"questions": [
|
| 27 |
+
{
|
| 28 |
+
"question": "Where did the Industrial Revolution begin?",
|
| 29 |
+
"options": ["United States", "France", "Germany", "Britain"],
|
| 30 |
+
"correct": 3
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"question": "Which invention dramatically increased factory efficiency?",
|
| 34 |
+
"options": ["The cotton gin", "The telegraph", "The steam engine", "The assembly line"],
|
| 35 |
+
"correct": 2
|
| 36 |
+
}
|
| 37 |
+
]
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"id": 3,
|
| 41 |
+
"topic": "Technology",
|
| 42 |
+
"text": "The James Webb Space Telescope is the largest and most powerful space telescope ever built. Launched in 2021, it operates primarily in the infrared spectrum, allowing it to peer through dense cosmic dust and observe the universe's most distant, early galaxies. Unlike its predecessor, Hubble, JWST orbits the Sun at the second Lagrange point, keeping it constantly shielded from the Sun's heat and light by its massive sunshield. This incredibly cold environment is necessary to prevent the telescope's own infrared emissions from interfering with its highly sensitive observations of exoplanet atmospheres and star formation.",
|
| 43 |
+
"questions": [
|
| 44 |
+
{
|
| 45 |
+
"question": "What spectrum does the James Webb Space Telescope primarily operate in?",
|
| 46 |
+
"options": ["Ultraviolet", "X-ray", "Infrared", "Visible light"],
|
| 47 |
+
"correct": 2
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"question": "Where does the telescope orbit to stay cold?",
|
| 51 |
+
"options": ["Low Earth Orbit", "The Moon's orbit", "The first Lagrange point", "The second Lagrange point"],
|
| 52 |
+
"correct": 3
|
| 53 |
+
}
|
| 54 |
+
]
|
| 55 |
+
}
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
for t in texts:
|
| 59 |
+
res = requests.post("http://localhost:7860/analyze", json={"text": t["text"], "layers": [4,5,6,7,8,9,10,11,12,13]})
|
| 60 |
+
data = res.json()
|
| 61 |
+
|
| 62 |
+
words = []
|
| 63 |
+
current_word = []
|
| 64 |
+
current_max = 0
|
| 65 |
+
|
| 66 |
+
for i, item in enumerate(data["words"]):
|
| 67 |
+
if i == 0 and ("<bos>" in item["token"] or "<bos>" in item["word"]):
|
| 68 |
+
continue
|
| 69 |
+
|
| 70 |
+
token_str = item["token"]
|
| 71 |
+
is_whitespace = (token_str.strip() == '')
|
| 72 |
+
prev_is_whitespace = (current_word[-1]["token"].strip() == '') if len(current_word) > 0 else False
|
| 73 |
+
|
| 74 |
+
if token_str.startswith(" ") or (len(current_word) > 0 and is_whitespace != prev_is_whitespace):
|
| 75 |
+
if len(current_word) > 0:
|
| 76 |
+
words.append({"tokens": current_word, "max_score": current_max})
|
| 77 |
+
current_word = [item]
|
| 78 |
+
current_max = item["score"]
|
| 79 |
+
else:
|
| 80 |
+
current_word.append(item)
|
| 81 |
+
current_max = max(current_max, item["score"])
|
| 82 |
+
|
| 83 |
+
if len(current_word) > 0:
|
| 84 |
+
words.append({"tokens": current_word, "max_score": current_max})
|
| 85 |
+
|
| 86 |
+
word_scores = [w["max_score"] for w in words]
|
| 87 |
+
word_scores.sort()
|
| 88 |
+
threshold_idx = int(len(word_scores) * 0.60)
|
| 89 |
+
threshold = word_scores[threshold_idx] if len(word_scores) > 0 else 0
|
| 90 |
+
|
| 91 |
+
binary_html = ""
|
| 92 |
+
gradient_html = ""
|
| 93 |
+
|
| 94 |
+
for w in words:
|
| 95 |
+
# Binary
|
| 96 |
+
className = "token highlighted" if w["max_score"] >= threshold else "token"
|
| 97 |
+
for item in w["tokens"]:
|
| 98 |
+
binary_html += f'<span class="{className}">{item["token"]}</span>'
|
| 99 |
+
|
| 100 |
+
# Gradient
|
| 101 |
+
opacity = 0.4 + (w["max_score"] * 0.6)
|
| 102 |
+
weight = 400 + int(w["max_score"] * 400)
|
| 103 |
+
for item in w["tokens"]:
|
| 104 |
+
gradient_html += f'<span class="token" style="opacity: {opacity:.2f}; font-weight: {weight};">{item["token"]}</span>'
|
| 105 |
+
|
| 106 |
+
t["flowread_html"] = binary_html
|
| 107 |
+
t["flowread_gradient_html"] = gradient_html
|
| 108 |
+
|
| 109 |
+
with open("study_texts.json", "w") as f:
|
| 110 |
+
json.dump(texts, f, indent=4)
|
| 111 |
+
print("Saved to study_texts.json")
|
main.py
CHANGED
|
@@ -234,27 +234,61 @@ def get_study_stats():
|
|
| 234 |
}
|
| 235 |
|
| 236 |
# --- Saliency API (Existing) ---
|
| 237 |
-
|
|
|
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
device = torch.device("mps" if torch.backends.mps.is_available() else "cpu")
|
| 242 |
-
print(f"Loading {model_id} on {device}...")
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
try:
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
model_id,
|
| 249 |
-
torch_dtype=torch.bfloat16,
|
| 250 |
-
attn_implementation="eager",
|
| 251 |
-
token=hf_token
|
| 252 |
-
).to(device)
|
| 253 |
-
print("Model loaded successfully.")
|
| 254 |
-
except Exception as e:
|
| 255 |
-
print(f"Error loading model: {e}")
|
| 256 |
-
print("Make sure you are logged into Hugging Face and have access to the Gemma model.")
|
| 257 |
-
print("Run `huggingface-cli login` in your terminal.")
|
| 258 |
|
| 259 |
class TextRequest(BaseModel):
|
| 260 |
text: str
|
|
@@ -263,17 +297,27 @@ class TextRequest(BaseModel):
|
|
| 263 |
saliency_mode: str = "local" # "local" or "global"
|
| 264 |
|
| 265 |
@app.post("/analyze")
|
| 266 |
-
async def
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
text = request.text
|
| 268 |
preprompt = request.preprompt.strip()
|
| 269 |
|
| 270 |
if not text.strip():
|
| 271 |
return {"tokens": [], "scores": []}
|
| 272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
# Combine preprompt and text if preprompt exists
|
| 274 |
full_text = f"{preprompt}\n\n{text}" if preprompt else text
|
| 275 |
|
| 276 |
-
inputs = tokenizer(full_text, return_tensors="pt").to(device)
|
| 277 |
|
| 278 |
# Calculate how many tokens belong to the preprompt so we can strip them later
|
| 279 |
num_preprompt_tokens = 1 # default is 1 for <bos>
|
|
|
|
| 234 |
}
|
| 235 |
|
| 236 |
# --- Saliency API (Existing) ---
|
| 237 |
+
models = {}
|
| 238 |
+
tokenizers = {}
|
| 239 |
|
| 240 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu")
|
| 241 |
+
hf_token = os.environ.get("HF_TOKEN")
|
|
|
|
|
|
|
| 242 |
|
| 243 |
+
def load_model(model_name: str):
|
| 244 |
+
if model_name in models:
|
| 245 |
+
return models[model_name], tokenizers[model_name]
|
| 246 |
+
|
| 247 |
+
print(f"Loading {model_name} on {device}...")
|
| 248 |
+
try:
|
| 249 |
+
if model_name == "27b-4a":
|
| 250 |
+
# Use Gemma 2 27B in 4-bit (requires CUDA)
|
| 251 |
+
hf_model_id = "google/gemma-2-27b"
|
| 252 |
+
tokenizer = AutoTokenizer.from_pretrained(hf_model_id, token=hf_token)
|
| 253 |
+
|
| 254 |
+
# BitsAndBytes for 4-bit quantization
|
| 255 |
+
from transformers import BitsAndBytesConfig
|
| 256 |
+
bnb_config = BitsAndBytesConfig(
|
| 257 |
+
load_in_4bit=True,
|
| 258 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 262 |
+
hf_model_id,
|
| 263 |
+
quantization_config=bnb_config,
|
| 264 |
+
device_map="auto",
|
| 265 |
+
attn_implementation="eager",
|
| 266 |
+
token=hf_token
|
| 267 |
+
)
|
| 268 |
+
else:
|
| 269 |
+
# Default to 2b
|
| 270 |
+
hf_model_id = "google/gemma-2b"
|
| 271 |
+
tokenizer = AutoTokenizer.from_pretrained(hf_model_id, token=hf_token)
|
| 272 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 273 |
+
hf_model_id,
|
| 274 |
+
torch_dtype=torch.bfloat16,
|
| 275 |
+
attn_implementation="eager",
|
| 276 |
+
token=hf_token
|
| 277 |
+
).to(device)
|
| 278 |
+
|
| 279 |
+
print(f"Model {model_name} loaded successfully.")
|
| 280 |
+
models[model_name] = model
|
| 281 |
+
tokenizers[model_name] = tokenizer
|
| 282 |
+
return model, tokenizer
|
| 283 |
+
except Exception as e:
|
| 284 |
+
print(f"Error loading model {model_name}: {e}")
|
| 285 |
+
raise e
|
| 286 |
+
|
| 287 |
+
# Pre-load default 2b
|
| 288 |
try:
|
| 289 |
+
load_model("2b")
|
| 290 |
+
except:
|
| 291 |
+
print("Could not preload 2b model.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
class TextRequest(BaseModel):
|
| 294 |
text: str
|
|
|
|
| 297 |
saliency_mode: str = "local" # "local" or "global"
|
| 298 |
|
| 299 |
@app.post("/analyze")
|
| 300 |
+
async def analyze_text_legacy(request: TextRequest):
|
| 301 |
+
return await analyze_text_model("2b", request)
|
| 302 |
+
|
| 303 |
+
@app.post("/analyze/{model_name}")
|
| 304 |
+
async def analyze_text_model(model_name: str, request: TextRequest):
|
| 305 |
text = request.text
|
| 306 |
preprompt = request.preprompt.strip()
|
| 307 |
|
| 308 |
if not text.strip():
|
| 309 |
return {"tokens": [], "scores": []}
|
| 310 |
|
| 311 |
+
try:
|
| 312 |
+
model, tokenizer = load_model(model_name)
|
| 313 |
+
except Exception as e:
|
| 314 |
+
from fastapi import HTTPException
|
| 315 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 316 |
+
|
| 317 |
# Combine preprompt and text if preprompt exists
|
| 318 |
full_text = f"{preprompt}\n\n{text}" if preprompt else text
|
| 319 |
|
| 320 |
+
inputs = tokenizer(full_text, return_tensors="pt").to(model.device)
|
| 321 |
|
| 322 |
# Calculate how many tokens belong to the preprompt so we can strip them later
|
| 323 |
num_preprompt_tokens = 1 # default is 1 for <bos>
|
requirements.txt
CHANGED
|
@@ -3,4 +3,5 @@ uvicorn
|
|
| 3 |
torch
|
| 4 |
transformers
|
| 5 |
pydantic
|
| 6 |
-
accelerate
|
|
|
|
|
|
| 3 |
torch
|
| 4 |
transformers
|
| 5 |
pydantic
|
| 6 |
+
accelerate
|
| 7 |
+
bitsandbytes
|
study_texts.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": 1,
|
| 4 |
+
"topic": "Science",
|
| 5 |
+
"text": "The human brain is a marvel of biological engineering, containing approximately 86 billion neurons interconnected by trillions of synapses. These neural networks are responsible for everything from basic autonomic functions, like breathing and heart rate, to complex cognitive processes such as memory, emotion, and problem-solving. Neuroplasticity, the brain's ability to reorganize itself by forming new neural connections throughout life, allows humans to learn new skills, recover from injuries, and adapt to changing environments. This extraordinary adaptability is what makes our species so resilient and capable of continuous intellectual growth.",
|
| 6 |
+
"questions": [
|
| 7 |
+
{
|
| 8 |
+
"question": "Approximately how many neurons are in the human brain?",
|
| 9 |
+
"options": [
|
| 10 |
+
"86 million",
|
| 11 |
+
"86 billion",
|
| 12 |
+
"100 trillion",
|
| 13 |
+
"50 billion"
|
| 14 |
+
],
|
| 15 |
+
"correct": 1
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"question": "What is the term for the brain's ability to reorganize itself?",
|
| 19 |
+
"options": [
|
| 20 |
+
"Synaptic generation",
|
| 21 |
+
"Neurogenesis",
|
| 22 |
+
"Neuroplasticity",
|
| 23 |
+
"Cognitive adaptation"
|
| 24 |
+
],
|
| 25 |
+
"correct": 2
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"flowread_html": "<span class=\"token highlighted\">The</span><span class=\"token highlighted\"> human</span><span class=\"token highlighted\"> brain</span><span class=\"token highlighted\"> is</span><span class=\"token highlighted\"> a</span><span class=\"token highlighted\"> marvel</span><span class=\"token\"> of</span><span class=\"token highlighted\"> biological</span><span class=\"token highlighted\"> engineering</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> containing</span><span class=\"token\"> approximately</span><span class=\"token\"> </span><span class=\"token\">8</span><span class=\"token\">6</span><span class=\"token highlighted\"> billion</span><span class=\"token highlighted\"> neurons</span><span class=\"token highlighted\"> interconnected</span><span class=\"token highlighted\"> by</span><span class=\"token\"> tri</span><span class=\"token\">lli</span><span class=\"token\">ons</span><span class=\"token\"> of</span><span class=\"token highlighted\"> synapses</span><span class=\"token highlighted\">.</span><span class=\"token highlighted\"> These</span><span class=\"token highlighted\"> neural</span><span class=\"token highlighted\"> networks</span><span class=\"token\"> are</span><span class=\"token\"> responsible</span><span class=\"token highlighted\"> for</span><span class=\"token\"> everything</span><span class=\"token highlighted\"> from</span><span class=\"token highlighted\"> basic</span><span class=\"token highlighted\"> autonomic</span><span class=\"token highlighted\"> functions</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> like</span><span class=\"token\"> breathing</span><span class=\"token\"> and</span><span class=\"token\"> heart</span><span class=\"token\"> rate</span><span class=\"token\">,</span><span class=\"token highlighted\"> to</span><span class=\"token\"> complex</span><span class=\"token highlighted\"> cognitive</span><span class=\"token\"> processes</span><span class=\"token\"> such</span><span class=\"token\"> as</span><span class=\"token highlighted\"> memory</span><span class=\"token highlighted\">,</span><span class=\"token\"> emotion</span><span class=\"token\">,</span><span class=\"token\"> and</span><span class=\"token highlighted\"> problem</span><span class=\"token highlighted\">-</span><span class=\"token highlighted\">solving</span><span class=\"token highlighted\">.</span><span class=\"token highlighted\"> Neurop</span><span class=\"token highlighted\">lastic</span><span class=\"token highlighted\">ity</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> the</span><span class=\"token highlighted\"> brain</span><span class=\"token highlighted\">'</span><span class=\"token highlighted\">s</span><span class=\"token\"> ability</span><span class=\"token\"> to</span><span class=\"token highlighted\"> reorgan</span><span class=\"token highlighted\">ize</span><span class=\"token\"> itself</span><span class=\"token\"> by</span><span class=\"token\"> forming</span><span class=\"token\"> new</span><span class=\"token\"> neural</span><span class=\"token\"> connections</span><span class=\"token\"> throughout</span><span class=\"token highlighted\"> life</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> allows</span><span class=\"token highlighted\"> humans</span><span class=\"token\"> to</span><span class=\"token highlighted\"> learn</span><span class=\"token\"> new</span><span class=\"token\"> skills</span><span class=\"token\">,</span><span class=\"token\"> recover</span><span class=\"token\"> from</span><span class=\"token\"> injuries</span><span class=\"token\">,</span><span class=\"token\"> and</span><span class=\"token\"> adapt</span><span class=\"token\"> to</span><span class=\"token\"> changing</span><span class=\"token highlighted\"> environments</span><span class=\"token highlighted\">.</span><span class=\"token\"> This</span><span class=\"token\"> extraordinary</span><span class=\"token highlighted\"> adaptability</span><span class=\"token\"> is</span><span class=\"token\"> what</span><span class=\"token\"> makes</span><span class=\"token\"> our</span><span class=\"token\"> species</span><span class=\"token\"> so</span><span class=\"token\"> resilient</span><span class=\"token\"> and</span><span class=\"token\"> capable</span><span class=\"token\"> of</span><span class=\"token\"> continuous</span><span class=\"token\"> intellectual</span><span class=\"token\"> growth</span><span class=\"token\">.</span>",
|
| 29 |
+
"flowread_gradient_html": "<span class=\"token\" style=\"opacity: 0.53; font-weight: 489;\">The</span><span class=\"token\" style=\"opacity: 0.56; font-weight: 506;\"> human</span><span class=\"token\" style=\"opacity: 1.00; font-weight: 800;\"> brain</span><span class=\"token\" style=\"opacity: 0.54; font-weight: 490;\"> is</span><span class=\"token\" style=\"opacity: 0.51; font-weight: 472;\"> a</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 489;\"> marvel</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 452;\"> of</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 484;\"> biological</span><span class=\"token\" style=\"opacity: 0.55; font-weight: 498;\"> engineering</span><span class=\"token\" style=\"opacity: 0.55; font-weight: 498;\">,</span><span class=\"token\" style=\"opacity: 0.56; font-weight: 506;\"> containing</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 455;\"> approximately</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 455;\"> </span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\">8</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\">6</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 469;\"> billion</span><span class=\"token\" style=\"opacity: 0.71; font-weight: 608;\"> neurons</span><span class=\"token\" style=\"opacity: 0.55; font-weight: 500;\"> interconnected</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 484;\"> by</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 419;\"> tri</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 419;\">lli</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 419;\">ons</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 413;\"> of</span><span class=\"token\" style=\"opacity: 0.72; font-weight: 613;\"> synapses</span><span class=\"token\" style=\"opacity: 0.72; font-weight: 613;\">.</span><span class=\"token\" style=\"opacity: 0.51; font-weight: 472;\"> These</span><span class=\"token\" style=\"opacity: 0.57; font-weight: 516;\"> neural</span><span class=\"token\" style=\"opacity: 0.57; font-weight: 515;\"> networks</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 455;\"> are</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 452;\"> responsible</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 482;\"> for</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 464;\"> everything</span><span class=\"token\" style=\"opacity: 0.59; font-weight: 529;\"> from</span><span class=\"token\" style=\"opacity: 0.51; font-weight: 474;\"> basic</span><span class=\"token\" style=\"opacity: 0.56; font-weight: 504;\"> autonomic</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 482;\"> functions</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 482;\">,</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 481;\"> like</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 466;\"> breathing</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 444;\"> and</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 424;\"> heart</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 435;\"> rate</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 435;\">,</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 479;\"> to</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 462;\"> complex</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 487;\"> cognitive</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 451;\"> processes</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 432;\"> such</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 451;\"> as</span><span class=\"token\" style=\"opacity: 0.51; font-weight: 474;\"> memory</span><span class=\"token\" style=\"opacity: 0.51; font-weight: 474;\">,</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 450;\"> emotion</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 450;\">,</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 428;\"> and</span><span class=\"token\" style=\"opacity: 0.64; font-weight: 559;\"> problem</span><span class=\"token\" style=\"opacity: 0.64; font-weight: 559;\">-</span><span class=\"token\" style=\"opacity: 0.64; font-weight: 559;\">solving</span><span class=\"token\" style=\"opacity: 0.64; font-weight: 559;\">.</span><span class=\"token\" style=\"opacity: 0.68; font-weight: 587;\"> Neurop</span><span class=\"token\" style=\"opacity: 0.68; font-weight: 587;\">lastic</span><span class=\"token\" style=\"opacity: 0.68; font-weight: 587;\">ity</span><span class=\"token\" style=\"opacity: 0.68; font-weight: 587;\">,</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 469;\"> the</span><span class=\"token\" style=\"opacity: 0.59; font-weight: 527;\"> brain</span><span class=\"token\" style=\"opacity: 0.59; font-weight: 527;\">'</span><span class=\"token\" style=\"opacity: 0.59; font-weight: 527;\">s</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 434;\"> ability</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 464;\"> to</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 469;\"> reorgan</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 469;\">ize</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 444;\"> itself</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 454;\"> by</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 434;\"> forming</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 431;\"> new</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 426;\"> neural</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 433;\"> connections</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 426;\"> throughout</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 480;\"> life</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 480;\">,</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 485;\"> allows</span><span class=\"token\" style=\"opacity: 0.54; font-weight: 493;\"> humans</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 463;\"> to</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 482;\"> learn</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 433;\"> new</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 454;\"> skills</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 454;\">,</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 449;\"> recover</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> from</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 438;\"> injuries</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 438;\">,</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 433;\"> and</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 436;\"> adapt</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\"> to</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 414;\"> changing</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 485;\"> environments</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 485;\">.</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> This</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 442;\"> extraordinary</span><span class=\"token\" style=\"opacity: 0.51; font-weight: 472;\"> adaptability</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 428;\"> is</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 435;\"> what</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 443;\"> makes</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 428;\"> our</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 468;\"> species</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 430;\"> so</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 443;\"> resilient</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 427;\"> and</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 412;\"> capable</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 422;\"> of</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 420;\"> continuous</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 413;\"> intellectual</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 403;\"> growth</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 403;\">.</span>"
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"id": 2,
|
| 33 |
+
"topic": "History",
|
| 34 |
+
"text": "The Industrial Revolution, which began in Britain in the late 18th century, marked a profound turning point in human history. It initiated the transition from agrarian, handicraft economies to industry and machine manufacturing. The invention of the steam engine, pioneered by figures like James Watt, dramatically increased the efficiency of factories and transportation, revolutionizing the textile industry and leading to the expansion of railways. This era brought about unprecedented economic growth and urbanization, fundamentally altering social structures and paving the way for the modern capitalist system, despite also causing significant social inequalities and poor working conditions initially.",
|
| 35 |
+
"questions": [
|
| 36 |
+
{
|
| 37 |
+
"question": "Where did the Industrial Revolution begin?",
|
| 38 |
+
"options": [
|
| 39 |
+
"United States",
|
| 40 |
+
"France",
|
| 41 |
+
"Germany",
|
| 42 |
+
"Britain"
|
| 43 |
+
],
|
| 44 |
+
"correct": 3
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"question": "Which invention dramatically increased factory efficiency?",
|
| 48 |
+
"options": [
|
| 49 |
+
"The cotton gin",
|
| 50 |
+
"The telegraph",
|
| 51 |
+
"The steam engine",
|
| 52 |
+
"The assembly line"
|
| 53 |
+
],
|
| 54 |
+
"correct": 2
|
| 55 |
+
}
|
| 56 |
+
],
|
| 57 |
+
"flowread_html": "<span class=\"token highlighted\">The</span><span class=\"token highlighted\"> Industrial</span><span class=\"token highlighted\"> Revolution</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> which</span><span class=\"token highlighted\"> began</span><span class=\"token\"> in</span><span class=\"token highlighted\"> Britain</span><span class=\"token\"> in</span><span class=\"token\"> the</span><span class=\"token\"> late</span><span class=\"token\"> </span><span class=\"token highlighted\">1</span><span class=\"token highlighted\">8</span><span class=\"token highlighted\">th</span><span class=\"token highlighted\"> century</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> marked</span><span class=\"token\"> a</span><span class=\"token highlighted\"> profound</span><span class=\"token\"> turning</span><span class=\"token highlighted\"> point</span><span class=\"token\"> in</span><span class=\"token highlighted\"> human</span><span class=\"token highlighted\"> history</span><span class=\"token highlighted\">.</span><span class=\"token highlighted\"> It</span><span class=\"token highlighted\"> initiated</span><span class=\"token\"> the</span><span class=\"token\"> transition</span><span class=\"token highlighted\"> from</span><span class=\"token highlighted\"> agrarian</span><span class=\"token highlighted\">,</span><span class=\"token\"> handic</span><span class=\"token\">raft</span><span class=\"token highlighted\"> economies</span><span class=\"token highlighted\"> to</span><span class=\"token highlighted\"> industry</span><span class=\"token\"> and</span><span class=\"token highlighted\"> machine</span><span class=\"token highlighted\"> manufacturing</span><span class=\"token highlighted\">.</span><span class=\"token highlighted\"> The</span><span class=\"token highlighted\"> invention</span><span class=\"token highlighted\"> of</span><span class=\"token\"> the</span><span class=\"token highlighted\"> steam</span><span class=\"token highlighted\"> engine</span><span class=\"token highlighted\">,</span><span class=\"token\"> pioneered</span><span class=\"token highlighted\"> by</span><span class=\"token\"> figures</span><span class=\"token\"> like</span><span class=\"token\"> James</span><span class=\"token\"> Watt</span><span class=\"token\">,</span><span class=\"token highlighted\"> dramatically</span><span class=\"token highlighted\"> increased</span><span class=\"token\"> the</span><span class=\"token\"> efficiency</span><span class=\"token\"> of</span><span class=\"token highlighted\"> factories</span><span class=\"token\"> and</span><span class=\"token highlighted\"> transportation</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> revolution</span><span class=\"token highlighted\">izing</span><span class=\"token\"> the</span><span class=\"token\"> textile</span><span class=\"token\"> industry</span><span class=\"token\"> and</span><span class=\"token\"> leading</span><span class=\"token\"> to</span><span class=\"token\"> the</span><span class=\"token\"> expansion</span><span class=\"token\"> of</span><span class=\"token highlighted\"> railways</span><span class=\"token highlighted\">.</span><span class=\"token\"> This</span><span class=\"token highlighted\"> era</span><span class=\"token highlighted\"> brought</span><span class=\"token\"> about</span><span class=\"token\"> unprecedented</span><span class=\"token highlighted\"> economic</span><span class=\"token highlighted\"> growth</span><span class=\"token\"> and</span><span class=\"token highlighted\"> urbanization</span><span class=\"token highlighted\">,</span><span class=\"token\"> fundamentally</span><span class=\"token highlighted\"> altering</span><span class=\"token\"> social</span><span class=\"token\"> structures</span><span class=\"token\"> and</span><span class=\"token\"> paving</span><span class=\"token\"> the</span><span class=\"token\"> way</span><span class=\"token\"> for</span><span class=\"token\"> the</span><span class=\"token\"> modern</span><span class=\"token\"> capitalist</span><span class=\"token\"> system</span><span class=\"token\">,</span><span class=\"token\"> despite</span><span class=\"token\"> also</span><span class=\"token\"> causing</span><span class=\"token\"> significant</span><span class=\"token\"> social</span><span class=\"token\"> inequalities</span><span class=\"token\"> and</span><span class=\"token\"> poor</span><span class=\"token\"> working</span><span class=\"token\"> conditions</span><span class=\"token\"> initially</span><span class=\"token\">.</span>",
|
| 58 |
+
"flowread_gradient_html": "<span class=\"token\" style=\"opacity: 0.49; font-weight: 462;\">The</span><span class=\"token\" style=\"opacity: 0.59; font-weight: 524;\"> Industrial</span><span class=\"token\" style=\"opacity: 1.00; font-weight: 800;\"> Revolution</span><span class=\"token\" style=\"opacity: 1.00; font-weight: 800;\">,</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 456;\"> which</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 467;\"> began</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 430;\"> in</span><span class=\"token\" style=\"opacity: 0.58; font-weight: 519;\"> Britain</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> in</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 410;\"> the</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 418;\"> late</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 415;\"> </span><span class=\"token\" style=\"opacity: 0.49; font-weight: 457;\">1</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 457;\">8</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 457;\">th</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 467;\"> century</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 467;\">,</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 460;\"> marked</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 422;\"> a</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 439;\"> profound</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 418;\"> turning</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 440;\"> point</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 423;\"> in</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 447;\"> human</span><span class=\"token\" style=\"opacity: 0.57; font-weight: 511;\"> history</span><span class=\"token\" style=\"opacity: 0.57; font-weight: 511;\">.</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 456;\"> It</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 450;\"> initiated</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 431;\"> the</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 426;\"> transition</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 444;\"> from</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 469;\"> agrarian</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 469;\">,</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 433;\"> handic</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 433;\">raft</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 451;\"> economies</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 452;\"> to</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 489;\"> industry</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 432;\"> and</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 444;\"> machine</span><span class=\"token\" style=\"opacity: 0.55; font-weight: 498;\"> manufacturing</span><span class=\"token\" style=\"opacity: 0.55; font-weight: 498;\">.</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 461;\"> The</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 442;\"> invention</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 440;\"> of</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 417;\"> the</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 465;\"> steam</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 483;\"> engine</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 483;\">,</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 434;\"> pioneered</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 436;\"> by</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\"> figures</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 426;\"> like</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 414;\"> James</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 428;\"> Watt</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 428;\">,</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 437;\"> dramatically</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 445;\"> increased</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\"> the</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 432;\"> efficiency</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\"> of</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 467;\"> factories</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 432;\"> and</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 442;\"> transportation</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 442;\">,</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\"> revolution</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\">izing</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 415;\"> the</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 436;\"> textile</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 428;\"> industry</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 433;\"> and</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 416;\"> leading</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 425;\"> to</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 409;\"> the</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 413;\"> expansion</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 407;\"> of</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 468;\"> railways</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 468;\">.</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 423;\"> This</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 454;\"> era</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 447;\"> brought</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 418;\"> about</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 434;\"> unprecedented</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 438;\"> economic</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 437;\"> growth</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 431;\"> and</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 449;\"> urbanization</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 449;\">,</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 424;\"> fundamentally</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 441;\"> altering</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 432;\"> social</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 427;\"> structures</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 432;\"> and</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 419;\"> paving</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 407;\"> the</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 410;\"> way</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 423;\"> for</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 409;\"> the</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 422;\"> modern</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> capitalist</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 415;\"> system</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 415;\">,</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 432;\"> despite</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 417;\"> also</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 431;\"> causing</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 419;\"> significant</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 416;\"> social</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> inequalities</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 415;\"> and</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 414;\"> poor</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 407;\"> working</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 406;\"> conditions</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 403;\"> initially</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 403;\">.</span>"
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"id": 3,
|
| 62 |
+
"topic": "Technology",
|
| 63 |
+
"text": "The James Webb Space Telescope is the largest and most powerful space telescope ever built. Launched in 2021, it operates primarily in the infrared spectrum, allowing it to peer through dense cosmic dust and observe the universe's most distant, early galaxies. Unlike its predecessor, Hubble, JWST orbits the Sun at the second Lagrange point, keeping it constantly shielded from the Sun's heat and light by its massive sunshield. This incredibly cold environment is necessary to prevent the telescope's own infrared emissions from interfering with its highly sensitive observations of exoplanet atmospheres and star formation.",
|
| 64 |
+
"questions": [
|
| 65 |
+
{
|
| 66 |
+
"question": "What spectrum does the James Webb Space Telescope primarily operate in?",
|
| 67 |
+
"options": [
|
| 68 |
+
"Ultraviolet",
|
| 69 |
+
"X-ray",
|
| 70 |
+
"Infrared",
|
| 71 |
+
"Visible light"
|
| 72 |
+
],
|
| 73 |
+
"correct": 2
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"question": "Where does the telescope orbit to stay cold?",
|
| 77 |
+
"options": [
|
| 78 |
+
"Low Earth Orbit",
|
| 79 |
+
"The Moon's orbit",
|
| 80 |
+
"The first Lagrange point",
|
| 81 |
+
"The second Lagrange point"
|
| 82 |
+
],
|
| 83 |
+
"correct": 3
|
| 84 |
+
}
|
| 85 |
+
],
|
| 86 |
+
"flowread_html": "<span class=\"token highlighted\">The</span><span class=\"token\"> James</span><span class=\"token highlighted\"> Webb</span><span class=\"token highlighted\"> Space</span><span class=\"token highlighted\"> Telescope</span><span class=\"token highlighted\"> is</span><span class=\"token highlighted\"> the</span><span class=\"token highlighted\"> largest</span><span class=\"token\"> and</span><span class=\"token\"> most</span><span class=\"token highlighted\"> powerful</span><span class=\"token highlighted\"> space</span><span class=\"token highlighted\"> telescope</span><span class=\"token\"> ever</span><span class=\"token highlighted\"> built</span><span class=\"token highlighted\">.</span><span class=\"token highlighted\"> Launched</span><span class=\"token\"> in</span><span class=\"token\"> </span><span class=\"token highlighted\">2</span><span class=\"token highlighted\">0</span><span class=\"token highlighted\">2</span><span class=\"token highlighted\">1</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> it</span><span class=\"token highlighted\"> operates</span><span class=\"token\"> primarily</span><span class=\"token\"> in</span><span class=\"token\"> the</span><span class=\"token highlighted\"> infrared</span><span class=\"token highlighted\"> spectrum</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> allowing</span><span class=\"token\"> it</span><span class=\"token\"> to</span><span class=\"token\"> peer</span><span class=\"token\"> through</span><span class=\"token\"> dense</span><span class=\"token highlighted\"> cosmic</span><span class=\"token\"> dust</span><span class=\"token\"> and</span><span class=\"token highlighted\"> observe</span><span class=\"token\"> the</span><span class=\"token highlighted\"> universe</span><span class=\"token highlighted\">'</span><span class=\"token highlighted\">s</span><span class=\"token\"> most</span><span class=\"token\"> distant</span><span class=\"token\">,</span><span class=\"token\"> early</span><span class=\"token highlighted\"> galaxies</span><span class=\"token highlighted\">.</span><span class=\"token highlighted\"> Unlike</span><span class=\"token\"> its</span><span class=\"token\"> predecessor</span><span class=\"token\">,</span><span class=\"token highlighted\"> Hubble</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> JW</span><span class=\"token highlighted\">ST</span><span class=\"token highlighted\"> orbits</span><span class=\"token\"> the</span><span class=\"token highlighted\"> Sun</span><span class=\"token highlighted\"> at</span><span class=\"token\"> the</span><span class=\"token\"> second</span><span class=\"token highlighted\"> Lagrange</span><span class=\"token highlighted\"> point</span><span class=\"token highlighted\">,</span><span class=\"token highlighted\"> keeping</span><span class=\"token\"> it</span><span class=\"token\"> constantly</span><span class=\"token highlighted\"> shielded</span><span class=\"token highlighted\"> from</span><span class=\"token\"> the</span><span class=\"token highlighted\"> Sun</span><span class=\"token highlighted\">'</span><span class=\"token highlighted\">s</span><span class=\"token\"> heat</span><span class=\"token\"> and</span><span class=\"token\"> light</span><span class=\"token\"> by</span><span class=\"token\"> its</span><span class=\"token\"> massive</span><span class=\"token highlighted\"> sun</span><span class=\"token highlighted\">shield</span><span class=\"token highlighted\">.</span><span class=\"token\"> This</span><span class=\"token\"> incredibly</span><span class=\"token highlighted\"> cold</span><span class=\"token\"> environment</span><span class=\"token\"> is</span><span class=\"token\"> necessary</span><span class=\"token\"> to</span><span class=\"token highlighted\"> prevent</span><span class=\"token\"> the</span><span class=\"token highlighted\"> telescope</span><span class=\"token highlighted\">'</span><span class=\"token highlighted\">s</span><span class=\"token\"> own</span><span class=\"token\"> infrared</span><span class=\"token\"> emissions</span><span class=\"token\"> from</span><span class=\"token\"> interfering</span><span class=\"token\"> with</span><span class=\"token\"> its</span><span class=\"token\"> highly</span><span class=\"token\"> sensitive</span><span class=\"token\"> observations</span><span class=\"token\"> of</span><span class=\"token\"> ex</span><span class=\"token\">oplan</span><span class=\"token\">et</span><span class=\"token\"> atmospheres</span><span class=\"token\"> and</span><span class=\"token\"> star</span><span class=\"token\"> formation</span><span class=\"token\">.</span>",
|
| 87 |
+
"flowread_gradient_html": "<span class=\"token\" style=\"opacity: 0.49; font-weight: 458;\">The</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 435;\"> James</span><span class=\"token\" style=\"opacity: 1.00; font-weight: 800;\"> Webb</span><span class=\"token\" style=\"opacity: 0.59; font-weight: 523;\"> Space</span><span class=\"token\" style=\"opacity: 0.75; font-weight: 632;\"> Telescope</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 478;\"> is</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 447;\"> the</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 463;\"> largest</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 423;\"> and</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 412;\"> most</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 443;\"> powerful</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 441;\"> space</span><span class=\"token\" style=\"opacity: 0.54; font-weight: 491;\"> telescope</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 422;\"> ever</span><span class=\"token\" style=\"opacity: 0.56; font-weight: 503;\"> built</span><span class=\"token\" style=\"opacity: 0.56; font-weight: 503;\">.</span><span class=\"token\" style=\"opacity: 0.51; font-weight: 475;\"> Launched</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\"> in</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 418;\"> </span><span class=\"token\" style=\"opacity: 0.50; font-weight: 463;\">2</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 463;\">0</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 463;\">2</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 463;\">1</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 463;\">,</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 452;\"> it</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 449;\"> operates</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 433;\"> primarily</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> in</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 418;\"> the</span><span class=\"token\" style=\"opacity: 0.57; font-weight: 510;\"> infrared</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\"> spectrum</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\">,</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 453;\"> allowing</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 420;\"> it</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 423;\"> to</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 437;\"> peer</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 437;\"> through</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 430;\"> dense</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 441;\"> cosmic</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 438;\"> dust</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 431;\"> and</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 458;\"> observe</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 439;\"> the</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 451;\"> universe</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 451;\">'</span><span class=\"token\" style=\"opacity: 0.48; font-weight: 451;\">s</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 414;\"> most</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 436;\"> distant</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 436;\">,</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 414;\"> early</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 478;\"> galaxies</span><span class=\"token\" style=\"opacity: 0.52; font-weight: 478;\">.</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 445;\"> Unlike</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 419;\"> its</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 437;\"> predecessor</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 437;\">,</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 467;\"> Hubble</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 467;\">,</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 468;\"> JW</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 468;\">ST</span><span class=\"token\" style=\"opacity: 0.55; font-weight: 496;\"> orbits</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 430;\"> the</span><span class=\"token\" style=\"opacity: 0.53; font-weight: 489;\"> Sun</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 441;\"> at</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 417;\"> the</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 415;\"> second</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 456;\"> Lagrange</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\"> point</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\">,</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 444;\"> keeping</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 431;\"> it</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 428;\"> constantly</span><span class=\"token\" style=\"opacity: 0.49; font-weight: 457;\"> shielded</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 445;\"> from</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 419;\"> the</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\"> Sun</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\">'</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\">s</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 438;\"> heat</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 423;\"> and</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 420;\"> light</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> by</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\"> its</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 418;\"> massive</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 465;\"> sun</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 465;\">shield</span><span class=\"token\" style=\"opacity: 0.50; font-weight: 465;\">.</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 422;\"> This</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 415;\"> incredibly</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 440;\"> cold</span><span class=\"token\" style=\"opacity: 0.46; font-weight: 439;\"> environment</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 414;\"> is</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 422;\"> necessary</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 431;\"> to</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 446;\"> prevent</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 420;\"> the</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 445;\"> telescope</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 445;\">'</span><span class=\"token\" style=\"opacity: 0.47; font-weight: 445;\">s</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> own</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> infrared</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 436;\"> emissions</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 414;\"> from</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 417;\"> interfering</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 419;\"> with</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 416;\"> its</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 407;\"> highly</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 417;\"> sensitive</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 421;\"> observations</span><span class=\"token\" style=\"opacity: 0.44; font-weight: 429;\"> of</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 430;\"> ex</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 430;\">oplan</span><span class=\"token\" style=\"opacity: 0.45; font-weight: 430;\">et</span><span class=\"token\" style=\"opacity: 0.43; font-weight: 418;\"> atmospheres</span><span class=\"token\" style=\"opacity: 0.42; font-weight: 413;\"> and</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 408;\"> star</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 403;\"> formation</span><span class=\"token\" style=\"opacity: 0.41; font-weight: 403;\">.</span>"
|
| 88 |
+
}
|
| 89 |
+
]
|
test_tok.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from transformers import AutoTokenizer
|
| 3 |
+
|
| 4 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b", token=os.environ.get("HF_TOKEN"))
|
| 5 |
+
preprompt = "Focus on numbers"
|
| 6 |
+
text = "The 86 billion neurons."
|
| 7 |
+
full = f"{preprompt}\n\n{text}"
|
| 8 |
+
|
| 9 |
+
p_tok = tokenizer(preprompt + "\n\n")["input_ids"]
|
| 10 |
+
f_tok = tokenizer(full)["input_ids"]
|
| 11 |
+
print(f"Preprompt tokens: {len(p_tok)}")
|
| 12 |
+
print(f"Full tokens: {len(f_tok)}")
|
| 13 |
+
print("Preprompt tokens:", tokenizer.convert_ids_to_tokens(p_tok))
|
| 14 |
+
print("Full tokens:", tokenizer.convert_ids_to_tokens(f_tok))
|
test_tok2.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from transformers import AutoTokenizer
|
| 3 |
+
|
| 4 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b", token=os.environ.get("HF_TOKEN"))
|
| 5 |
+
p = "Hello"
|
| 6 |
+
t = " world" # starts with space
|
| 7 |
+
print("Pre:", tokenizer.convert_ids_to_tokens(tokenizer(p + "\n\n")["input_ids"]))
|
| 8 |
+
print("Full:", tokenizer.convert_ids_to_tokens(tokenizer(p + "\n\n" + t)["input_ids"]))
|