Alleinzellgaenger commited on
Commit
9f60175
·
1 Parent(s): 63428e7

Add highlighting for Cian's paper

Browse files
frontend/package-lock.json CHANGED
The diff for this file is too large to render. See raw diff
 
frontend/package.json CHANGED
@@ -4,6 +4,7 @@
4
  "version": "0.0.0",
5
  "type": "module",
6
  "scripts": {
 
7
  "dev": "vite",
8
  "build": "vite build",
9
  "lint": "eslint .",
@@ -11,7 +12,6 @@
11
  },
12
  "dependencies": {
13
  "@ai-sdk/react": "^2.0.11",
14
- "@llamaindex/chat-ui": "^0.5.17",
15
  "@swc/helpers": "^0.5.17",
16
  "@tailwindcss/postcss": "^4.1.11",
17
  "ai": "^5.0.11",
@@ -20,12 +20,13 @@
20
  "clsx": "^2.1.1",
21
  "katex": "^0.16.22",
22
  "lucide-react": "^0.539.0",
 
23
  "postcss": "^8.5.6",
24
  "react": "^18.3.1",
25
  "react-dom": "^18.3.1",
26
  "react-katex": "^3.1.0",
27
  "react-markdown": "^10.1.0",
28
- "react-pdf": "^10.0.1",
29
  "react-router-dom": "^7.7.0",
30
  "rehype-katex": "^7.0.1",
31
  "rehype-raw": "^7.0.0",
@@ -33,6 +34,9 @@
33
  "tailwind-merge": "^3.3.1",
34
  "tailwindcss": "^4.1.11"
35
  },
 
 
 
36
  "devDependencies": {
37
  "@eslint/js": "^9.30.1",
38
  "@types/react": "^19.1.8",
@@ -42,6 +46,7 @@
42
  "eslint-plugin-react-hooks": "^5.2.0",
43
  "eslint-plugin-react-refresh": "^0.4.20",
44
  "globals": "^16.3.0",
 
45
  "tw-animate-css": "^1.3.6",
46
  "vite": "^7.0.4"
47
  }
 
4
  "version": "0.0.0",
5
  "type": "module",
6
  "scripts": {
7
+ "preinstall": "npx npm-force-resolutions",
8
  "dev": "vite",
9
  "build": "vite build",
10
  "lint": "eslint .",
 
12
  },
13
  "dependencies": {
14
  "@ai-sdk/react": "^2.0.11",
 
15
  "@swc/helpers": "^0.5.17",
16
  "@tailwindcss/postcss": "^4.1.11",
17
  "ai": "^5.0.11",
 
20
  "clsx": "^2.1.1",
21
  "katex": "^0.16.22",
22
  "lucide-react": "^0.539.0",
23
+ "pdfjs-dist": "^4.10.38",
24
  "postcss": "^8.5.6",
25
  "react": "^18.3.1",
26
  "react-dom": "^18.3.1",
27
  "react-katex": "^3.1.0",
28
  "react-markdown": "^10.1.0",
29
+ "react-pdf-highlighter-extended": "^8.1.0",
30
  "react-router-dom": "^7.7.0",
31
  "rehype-katex": "^7.0.1",
32
  "rehype-raw": "^7.0.0",
 
34
  "tailwind-merge": "^3.3.1",
35
  "tailwindcss": "^4.1.11"
36
  },
37
+ "resolutions": {
38
+ "pdfjs-dist": "^4.10.38"
39
+ },
40
  "devDependencies": {
41
  "@eslint/js": "^9.30.1",
42
  "@types/react": "^19.1.8",
 
46
  "eslint-plugin-react-hooks": "^5.2.0",
47
  "eslint-plugin-react-refresh": "^0.4.20",
48
  "globals": "^16.3.0",
49
+ "npm-force-resolutions": "^0.0.10",
50
  "tw-animate-css": "^1.3.6",
51
  "vite": "^7.0.4"
52
  }
frontend/public/pdf.worker.min.js CHANGED
The diff for this file is too large to render. See raw diff
 
frontend/src/components/ChunkPanel.jsx CHANGED
@@ -31,9 +31,10 @@ const ChunkPanel = ({
31
  // Only for initial chunk (0) and when not transitioning
32
  useEffect(() => {
33
  if (documentData && showChat && !hasChunkMessages(currentChunkIndex) && currentChunkIndex === 0) {
 
34
  generateGreetingStreaming();
35
  }
36
- }, [currentChunkIndex, documentData, showChat]);
37
 
38
  const updateLastAssistantMessage = (delta) => {
39
  const allMessages = getGlobalChatHistory();
 
31
  // Only for initial chunk (0) and when not transitioning
32
  useEffect(() => {
33
  if (documentData && showChat && !hasChunkMessages(currentChunkIndex) && currentChunkIndex === 0) {
34
+ console.log("🤖 Triggering greeting generation for chunk 0");
35
  generateGreetingStreaming();
36
  }
37
+ }, [documentData?.chunks?.length, showChat, currentChunkIndex]); // More stable dependencies
38
 
39
  const updateLastAssistantMessage = (delta) => {
40
  const allMessages = getGlobalChatHistory();
frontend/src/components/DocumentProcessor.jsx CHANGED
@@ -58,6 +58,1449 @@ function DocumentProcessor() {
58
  handleMouseDown
59
  } = usePanelResize(50);
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  // Sync PDF page navigation with chunk switching
62
  useEffect(() => {
63
  if (pdfNavigation && documentData && documentData.chunks[currentChunkIndex]) {
@@ -130,8 +1573,10 @@ function DocumentProcessor() {
130
  <div className="flex-1 min-h-0">
131
  <DocumentViewer
132
  selectedFile={selectedFile}
133
- documentData={documentData}
134
  onPageChange={setPdfNavigation}
 
 
135
  />
136
  </div>
137
  </div>
@@ -167,7 +1612,7 @@ function DocumentProcessor() {
167
  {/* Chunk Panel */}
168
  <div className="flex-1 flex flex-col min-h-0 bg-white rounded-lg shadow-sm">
169
  <ChunkPanel
170
- documentData={documentData}
171
  currentChunkIndex={currentChunkIndex}
172
  showChat={showChat}
173
  updateGlobalChatHistory={updateGlobalChatHistory}
 
58
  handleMouseDown
59
  } = usePanelResize(50);
60
 
61
+ // Add test preloaded highlights data - keyed by chunk index
62
+ const testPreloadedHighlights = {
63
+ 0: [{
64
+ "id": "highlight_1755504511620",
65
+ "position": {
66
+ "boundingRect": {
67
+ "x1": 177.89999389648438,
68
+ "y1": 160.8833465576172,
69
+ "x2": 829.5500183105469,
70
+ "y2": 252.83331298828125,
71
+ "width": 1008,
72
+ "height": 1304.4705882352941,
73
+ "pageNumber": 2
74
+ },
75
+ "rects": [
76
+ {
77
+ "x1": 177.89999389648438,
78
+ "y1": 160.8833465576172,
79
+ "x2": 829.3500366210938,
80
+ "y2": 180.9833526611328,
81
+ "width": 1008,
82
+ "height": 1304.4705882352941,
83
+ "pageNumber": 2
84
+ },
85
+ {
86
+ "x1": 177.89999389648438,
87
+ "y1": 178.8833465576172,
88
+ "x2": 826.1000061035156,
89
+ "y2": 198.9833526611328,
90
+ "width": 1008,
91
+ "height": 1304.4705882352941,
92
+ "pageNumber": 2
93
+ },
94
+ {
95
+ "x1": 177.89999389648438,
96
+ "y1": 196.7333221435547,
97
+ "x2": 829.5500183105469,
98
+ "y2": 216.83331298828125,
99
+ "width": 1008,
100
+ "height": 1304.4705882352941,
101
+ "pageNumber": 2
102
+ },
103
+ {
104
+ "x1": 177.89999389648438,
105
+ "y1": 214.7333221435547,
106
+ "x2": 826.4333190917969,
107
+ "y2": 234.83331298828125,
108
+ "width": 1008,
109
+ "height": 1304.4705882352941,
110
+ "pageNumber": 2
111
+ },
112
+ {
113
+ "x1": 177.89999389648438,
114
+ "y1": 232.7333221435547,
115
+ "x2": 345.4499969482422,
116
+ "y2": 252.83331298828125,
117
+ "width": 1008,
118
+ "height": 1304.4705882352941,
119
+ "pageNumber": 2
120
+ }
121
+ ]
122
+ },
123
+ "content": {
124
+ "text": "Recurrent neural networks, long short-term memory [13] and gated recurrent [7] neural networks\r in particular, have been firmly established as state of the art approaches in sequence modeling and\r transduction problems such as language modeling and machine translation [ 35 , 2 , 5]. Numerous\r efforts have since continued to push the boundaries of recurrent language models and encoder-decoder\r architectures [38, 24, 15]."
125
+ }
126
+ }],
127
+ 1: [{
128
+ "id": "highlight_1755504528640",
129
+ "position": {
130
+ "boundingRect": {
131
+ "x1": 177.89999389648438,
132
+ "y1": 259.71665954589844,
133
+ "x2": 829.9999694824219,
134
+ "y2": 405.5333251953125,
135
+ "width": 1008,
136
+ "height": 1304.4705882352941,
137
+ "pageNumber": 2
138
+ },
139
+ "rects": [
140
+ {
141
+ "x1": 177.89999389648438,
142
+ "y1": 259.71665954589844,
143
+ "x2": 826.1333312988281,
144
+ "y2": 279.81666564941406,
145
+ "width": 1008,
146
+ "height": 1304.4705882352941,
147
+ "pageNumber": 2
148
+ },
149
+ {
150
+ "x1": 177.89999389648438,
151
+ "y1": 277.71665954589844,
152
+ "x2": 826.0833435058594,
153
+ "y2": 297.81666564941406,
154
+ "width": 1008,
155
+ "height": 1304.4705882352941,
156
+ "pageNumber": 2
157
+ },
158
+ {
159
+ "x1": 177.89999389648438,
160
+ "y1": 295.5833282470703,
161
+ "x2": 520.6666564941406,
162
+ "y2": 315.68333435058594,
163
+ "width": 1008,
164
+ "height": 1304.4705882352941,
165
+ "pageNumber": 2
166
+ },
167
+ {
168
+ "x1": 548.25,
169
+ "y1": 295.5833282470703,
170
+ "x2": 829.9999694824219,
171
+ "y2": 315.68333435058594,
172
+ "width": 1008,
173
+ "height": 1304.4705882352941,
174
+ "pageNumber": 2
175
+ },
176
+ {
177
+ "x1": 227.5,
178
+ "y1": 302.2999725341797,
179
+ "x2": 231.35000610351562,
180
+ "y2": 316.81663513183594,
181
+ "width": 1008,
182
+ "height": 1304.4705882352941,
183
+ "pageNumber": 2
184
+ },
185
+ {
186
+ "x1": 521.5333251953125,
187
+ "y1": 302.2999725341797,
188
+ "x2": 545.8999786376953,
189
+ "y2": 316.81663513183594,
190
+ "width": 1008,
191
+ "height": 1304.4705882352941,
192
+ "pageNumber": 2
193
+ },
194
+ {
195
+ "x1": 177.89999389648438,
196
+ "y1": 313.5832977294922,
197
+ "x2": 826.3999938964844,
198
+ "y2": 333.6833038330078,
199
+ "width": 1008,
200
+ "height": 1304.4705882352941,
201
+ "pageNumber": 2
202
+ },
203
+ {
204
+ "x1": 177.89999389648438,
205
+ "y1": 331.5666961669922,
206
+ "x2": 826.1166687011719,
207
+ "y2": 351.66668701171875,
208
+ "width": 1008,
209
+ "height": 1304.4705882352941,
210
+ "pageNumber": 2
211
+ },
212
+ {
213
+ "x1": 177.89999389648438,
214
+ "y1": 349.5666961669922,
215
+ "x2": 829.4666442871094,
216
+ "y2": 369.66668701171875,
217
+ "width": 1008,
218
+ "height": 1304.4705882352941,
219
+ "pageNumber": 2
220
+ },
221
+ {
222
+ "x1": 177.89999389648438,
223
+ "y1": 367.43333435058594,
224
+ "x2": 826.7833251953125,
225
+ "y2": 387.5333251953125,
226
+ "width": 1008,
227
+ "height": 1304.4705882352941,
228
+ "pageNumber": 2
229
+ },
230
+ {
231
+ "x1": 177.89999389648438,
232
+ "y1": 385.43333435058594,
233
+ "x2": 542.1999816894531,
234
+ "y2": 405.5333251953125,
235
+ "width": 1008,
236
+ "height": 1304.4705882352941,
237
+ "pageNumber": 2
238
+ }
239
+ ]
240
+ },
241
+ "content": {
242
+ "text": "Recurrent models typically factor computation along the symbol positions of the input and output\r sequences. Aligning the positions to steps in computation time, they generate a sequence of hidden\r states ht, as a function of the previous hidden state ht−1 and the input for position t. This inherently\r sequential nature precludes parallelization within training examples, which becomes critical at longer\r sequence lengths, as memory constraints limit batching across examples. Recent work has achieved\r significant improvements in computational efficiency through factorization tricks [ 21 ] and conditional\r computation [ 32 ], while also improving model performance in case of the latter. The fundamental\r constraint of sequential computation, however, remains."
243
+ }
244
+ }],
245
+ 2: [{
246
+ "id": "highlight_1755504541270",
247
+ "position": {
248
+ "boundingRect": {
249
+ "x1": 177.3000030517578,
250
+ "y1": 412.4166717529297,
251
+ "x2": 828.8333282470703,
252
+ "y2": 486.3833312988281,
253
+ "width": 1008,
254
+ "height": 1304.4705882352941,
255
+ "pageNumber": 2
256
+ },
257
+ "rects": [
258
+ {
259
+ "x1": 177.3000030517578,
260
+ "y1": 412.4166717529297,
261
+ "x2": 828.8333282470703,
262
+ "y2": 432.51666259765625,
263
+ "width": 1008,
264
+ "height": 1304.4705882352941,
265
+ "pageNumber": 2
266
+ },
267
+ {
268
+ "x1": 177.89999389648438,
269
+ "y1": 430.4166717529297,
270
+ "x2": 826.1333312988281,
271
+ "y2": 450.51666259765625,
272
+ "width": 1008,
273
+ "height": 1304.4705882352941,
274
+ "pageNumber": 2
275
+ },
276
+ {
277
+ "x1": 177.89999389648438,
278
+ "y1": 448.28334045410156,
279
+ "x2": 828.5833282470703,
280
+ "y2": 468.3833312988281,
281
+ "width": 1008,
282
+ "height": 1304.4705882352941,
283
+ "pageNumber": 2
284
+ },
285
+ {
286
+ "x1": 177.89999389648438,
287
+ "y1": 466.28334045410156,
288
+ "x2": 498.3333435058594,
289
+ "y2": 486.3833312988281,
290
+ "width": 1008,
291
+ "height": 1304.4705882352941,
292
+ "pageNumber": 2
293
+ }
294
+ ]
295
+ },
296
+ "content": {
297
+ "text": "Attention mechanisms have become an integral part of compelling sequence modeling and transduc-\r tion models in various tasks, allowing modeling of dependencies without regard to their distance in\r the input or output sequences [ 2, 19 ]. In all but a few cases [ 27 ], however, such attention mechanisms\r are used in conjunction with a recurrent network."
298
+ }
299
+ }],
300
+ 3: [{
301
+ "id": "highlight_1755504577785",
302
+ "position": {
303
+ "boundingRect": {
304
+ "x1": 177.39999389648438,
305
+ "y1": 638.9333190917969,
306
+ "x2": 828.9333343505859,
307
+ "y2": 784.7333221435547,
308
+ "width": 1008,
309
+ "height": 1304.4705882352941,
310
+ "pageNumber": 2
311
+ },
312
+ "rects": [
313
+ {
314
+ "x1": 177.39999389648438,
315
+ "y1": 638.9333190917969,
316
+ "x2": 826.1166687011719,
317
+ "y2": 659.0333099365234,
318
+ "width": 1008,
319
+ "height": 1304.4705882352941,
320
+ "pageNumber": 2
321
+ },
322
+ {
323
+ "x1": 177.89999389648438,
324
+ "y1": 656.7999877929688,
325
+ "x2": 827.5333557128906,
326
+ "y2": 676.8999938964844,
327
+ "width": 1008,
328
+ "height": 1304.4705882352941,
329
+ "pageNumber": 2
330
+ },
331
+ {
332
+ "x1": 177.89999389648438,
333
+ "y1": 674.7833251953125,
334
+ "x2": 828.2166442871094,
335
+ "y2": 694.8833312988281,
336
+ "width": 1008,
337
+ "height": 1304.4705882352941,
338
+ "pageNumber": 2
339
+ },
340
+ {
341
+ "x1": 177.89999389648438,
342
+ "y1": 692.7833251953125,
343
+ "x2": 826.1166687011719,
344
+ "y2": 712.8833312988281,
345
+ "width": 1008,
346
+ "height": 1304.4705882352941,
347
+ "pageNumber": 2
348
+ },
349
+ {
350
+ "x1": 177.89999389648438,
351
+ "y1": 710.6499938964844,
352
+ "x2": 826.1999816894531,
353
+ "y2": 730.75,
354
+ "width": 1008,
355
+ "height": 1304.4705882352941,
356
+ "pageNumber": 2
357
+ },
358
+ {
359
+ "x1": 177.89999389648438,
360
+ "y1": 728.6499938964844,
361
+ "x2": 828.9333343505859,
362
+ "y2": 748.75,
363
+ "width": 1008,
364
+ "height": 1304.4705882352941,
365
+ "pageNumber": 2
366
+ },
367
+ {
368
+ "x1": 177.89999389648438,
369
+ "y1": 746.6333312988281,
370
+ "x2": 826.0833435058594,
371
+ "y2": 766.7333221435547,
372
+ "width": 1008,
373
+ "height": 1304.4705882352941,
374
+ "pageNumber": 2
375
+ },
376
+ {
377
+ "x1": 177.89999389648438,
378
+ "y1": 764.6333312988281,
379
+ "x2": 826.1000061035156,
380
+ "y2": 784.7333221435547,
381
+ "width": 1008,
382
+ "height": 1304.4705882352941,
383
+ "pageNumber": 2
384
+ }
385
+ ]
386
+ },
387
+ "content": {
388
+ "text": "The goal of reducing sequential computation also forms the foundation of the Extended Neural GPU\r [16 ], ByteNet [ 18 ] and ConvS2S [ 9], all of which use convolutional neural networks as basic building\r block, computing hidden representations in parallel for all input and output positions. In these models,\r the number of operations required to relate signals from two arbitrary input or output positions grows\r in the distance between positions, linearly for ConvS2S and logarithmically for ByteNet. This makes\r it more difficult to learn dependencies between distant positions [12 ]. In the Transformer this is\r reduced to a constant number of operations, albeit at the cost of reduced effective resolution due\r to averaging attention-weighted positions, an effect we counteract with Multi-Head Attention as\r described in section 3.2."
389
+ }
390
+ }],
391
+ 4: [{
392
+ "id": "highlight_1755504661834",
393
+ "position": {
394
+ "boundingRect": {
395
+ "x1": 177.39999389648438,
396
+ "y1": 809.4833374023438,
397
+ "x2": 828.8500061035156,
398
+ "y2": 1027.2833557128906,
399
+ "width": 1008,
400
+ "height": 1304.4705882352941,
401
+ "pageNumber": 2
402
+ },
403
+ "rects": [
404
+ {
405
+ "x1": 177.89999389648438,
406
+ "y1": 809.4833374023438,
407
+ "x2": 826.1499938964844,
408
+ "y2": 829.5833282470703,
409
+ "width": 1008,
410
+ "height": 1304.4705882352941,
411
+ "pageNumber": 2
412
+ },
413
+ {
414
+ "x1": 177.89999389648438,
415
+ "y1": 827.4833374023438,
416
+ "x2": 826.0833435058594,
417
+ "y2": 847.5833282470703,
418
+ "width": 1008,
419
+ "height": 1304.4705882352941,
420
+ "pageNumber": 2
421
+ },
422
+ {
423
+ "x1": 177.89999389648438,
424
+ "y1": 845.4833374023438,
425
+ "x2": 828.1833190917969,
426
+ "y2": 865.5833282470703,
427
+ "width": 1008,
428
+ "height": 1304.4705882352941,
429
+ "pageNumber": 2
430
+ },
431
+ {
432
+ "x1": 177.89999389648438,
433
+ "y1": 863.4833374023438,
434
+ "x2": 759.1999816894531,
435
+ "y2": 883.5833282470703,
436
+ "width": 1008,
437
+ "height": 1304.4705882352941,
438
+ "pageNumber": 2
439
+ },
440
+ {
441
+ "x1": 177.89999389648438,
442
+ "y1": 890.4666748046875,
443
+ "x2": 828.7833557128906,
444
+ "y2": 910.5666809082031,
445
+ "width": 1008,
446
+ "height": 1304.4705882352941,
447
+ "pageNumber": 2
448
+ },
449
+ {
450
+ "x1": 177.89999389648438,
451
+ "y1": 908.3333129882812,
452
+ "x2": 826.1333312988281,
453
+ "y2": 928.4333190917969,
454
+ "width": 1008,
455
+ "height": 1304.4705882352941,
456
+ "pageNumber": 2
457
+ },
458
+ {
459
+ "x1": 177.89999389648438,
460
+ "y1": 926.3333129882812,
461
+ "x2": 374.46665954589844,
462
+ "y2": 946.4333190917969,
463
+ "width": 1008,
464
+ "height": 1304.4705882352941,
465
+ "pageNumber": 2
466
+ },
467
+ {
468
+ "x1": 177.39999389648438,
469
+ "y1": 953.316650390625,
470
+ "x2": 826.1333312988281,
471
+ "y2": 973.4166564941406,
472
+ "width": 1008,
473
+ "height": 1304.4705882352941,
474
+ "pageNumber": 2
475
+ },
476
+ {
477
+ "x1": 177.89999389648438,
478
+ "y1": 971.316650390625,
479
+ "x2": 828.8500061035156,
480
+ "y2": 991.4166564941406,
481
+ "width": 1008,
482
+ "height": 1304.4705882352941,
483
+ "pageNumber": 2
484
+ },
485
+ {
486
+ "x1": 177.89999389648438,
487
+ "y1": 989.183349609375,
488
+ "x2": 826.1000061035156,
489
+ "y2": 1009.2833557128906,
490
+ "width": 1008,
491
+ "height": 1304.4705882352941,
492
+ "pageNumber": 2
493
+ },
494
+ {
495
+ "x1": 177.89999389648438,
496
+ "y1": 1007.183349609375,
497
+ "x2": 684.2666625976562,
498
+ "y2": 1027.2833557128906,
499
+ "width": 1008,
500
+ "height": 1304.4705882352941,
501
+ "pageNumber": 2
502
+ }
503
+ ]
504
+ },
505
+ "content": {
506
+ "text": "Self-attention, sometimes called intra-attention is an attention mechanism relating different positions\r of a single sequence in order to compute a representation of the sequence. Self-attention has been\r used successfully in a variety of tasks including reading comprehension, abstractive summarization,\r textual entailment and learning task-independent sentence representations [4, 27, 28, 22].\r End-to-end memory networks are based on a recurrent attention mechanism instead of sequence-\r aligned recurrence and have been shown to perform well on simple-language question answering and\r language modeling tasks [34].\r To the best of our knowledge, however, the Transformer is the first transduction model relying\r entirely on self-attention to compute representations of its input and output without using sequence-\r aligned RNNs or convolution. In the following sections, we will describe the Transformer, motivate\r self-attention and discuss its advantages over models such as [17, 18] and [9]."
507
+ }
508
+ }],
509
+ 5: [{
510
+ "id": "highlight_1755504696254",
511
+ "position": {
512
+ "boundingRect": {
513
+ "x1": 177.89999389648438,
514
+ "y1": 1098.8499755859375,
515
+ "x2": 832.8833465576172,
516
+ "y2": 1190.7999725341797,
517
+ "width": 1008,
518
+ "height": 1304.4705882352941,
519
+ "pageNumber": 2
520
+ },
521
+ "rects": [
522
+ {
523
+ "x1": 177.89999389648438,
524
+ "y1": 1098.8499755859375,
525
+ "x2": 832.8833465576172,
526
+ "y2": 1118.9499816894531,
527
+ "width": 1008,
528
+ "height": 1304.4705882352941,
529
+ "pageNumber": 2
530
+ },
531
+ {
532
+ "x1": 177.89999389648438,
533
+ "y1": 1116.8499755859375,
534
+ "x2": 829.5166931152344,
535
+ "y2": 1136.9499816894531,
536
+ "width": 1008,
537
+ "height": 1304.4705882352941,
538
+ "pageNumber": 2
539
+ },
540
+ {
541
+ "x1": 671.316650390625,
542
+ "y1": 1123.566650390625,
543
+ "x2": 677.1333160400391,
544
+ "y2": 1138.0833282470703,
545
+ "width": 1008,
546
+ "height": 1304.4705882352941,
547
+ "pageNumber": 2
548
+ },
549
+ {
550
+ "x1": 716.2833251953125,
551
+ "y1": 1123.566650390625,
552
+ "x2": 722.316650390625,
553
+ "y2": 1138.0833282470703,
554
+ "width": 1008,
555
+ "height": 1304.4705882352941,
556
+ "pageNumber": 2
557
+ },
558
+ {
559
+ "x1": 177.89999389648438,
560
+ "y1": 1134.8333129882812,
561
+ "x2": 828.5333251953125,
562
+ "y2": 1154.9333038330078,
563
+ "width": 1008,
564
+ "height": 1304.4705882352941,
565
+ "pageNumber": 2
566
+ },
567
+ {
568
+ "x1": 436.45001220703125,
569
+ "y1": 1141.4332885742188,
570
+ "x2": 442.2666778564453,
571
+ "y2": 1155.949966430664,
572
+ "width": 1008,
573
+ "height": 1304.4705882352941,
574
+ "pageNumber": 2
575
+ },
576
+ {
577
+ "x1": 479.70001220703125,
578
+ "y1": 1141.4332885742188,
579
+ "x2": 485.7333526611328,
580
+ "y2": 1155.949966430664,
581
+ "width": 1008,
582
+ "height": 1304.4705882352941,
583
+ "pageNumber": 2
584
+ },
585
+ {
586
+ "x1": 177.89999389648438,
587
+ "y1": 1152.8333129882812,
588
+ "x2": 301.25001525878906,
589
+ "y2": 1172.9333038330078,
590
+ "width": 1008,
591
+ "height": 1304.4705882352941,
592
+ "pageNumber": 2
593
+ },
594
+ {
595
+ "x1": 313.98333740234375,
596
+ "y1": 1152.8333129882812,
597
+ "x2": 826.9166564941406,
598
+ "y2": 1172.9333038330078,
599
+ "width": 1008,
600
+ "height": 1304.4705882352941,
601
+ "pageNumber": 2
602
+ },
603
+ {
604
+ "x1": 257.83331298828125,
605
+ "y1": 1159.4332885742188,
606
+ "x2": 263.6499786376953,
607
+ "y2": 1173.949966430664,
608
+ "width": 1008,
609
+ "height": 1304.4705882352941,
610
+ "pageNumber": 2
611
+ },
612
+ {
613
+ "x1": 301.48333740234375,
614
+ "y1": 1159.4332885742188,
615
+ "x2": 310.6499938964844,
616
+ "y2": 1173.949966430664,
617
+ "width": 1008,
618
+ "height": 1304.4705882352941,
619
+ "pageNumber": 2
620
+ },
621
+ {
622
+ "x1": 177.89999389648438,
623
+ "y1": 1170.6999816894531,
624
+ "x2": 804.1000061035156,
625
+ "y2": 1190.7999725341797,
626
+ "width": 1008,
627
+ "height": 1304.4705882352941,
628
+ "pageNumber": 2
629
+ }
630
+ ]
631
+ },
632
+ "content": {
633
+ "text": "Most competitive neural sequence transduction models have an encoder-decoder structure [ 5, 2 , 35].\r Here, the encoder maps an input sequence of symbol representations (x1, ..., xn) to a sequence\r of continuous representations z = (z1, ..., zn). Given z, the decoder then generates an output\r sequence (y1, ..., ym) of symbols one element at a time. At each step the model is auto-regressive\r [10], consuming the previously generated symbols as additional input when generating the next."
634
+ }
635
+ }],
636
+ 6: [{
637
+ "id": "highlight_1755504745750",
638
+ "position": {
639
+ "boundingRect": {
640
+ "x1": 177.3000030517578,
641
+ "y1": 826.0499877929688,
642
+ "x2": 829.4333343505859,
643
+ "y2": 1099.6499938964844,
644
+ "width": 1008,
645
+ "height": 1304.4705882352941,
646
+ "pageNumber": 3
647
+ },
648
+ "rects": [
649
+ {
650
+ "x1": 177.89999389648438,
651
+ "y1": 826.0499877929688,
652
+ "x2": 247.6333465576172,
653
+ "y2": 846.1499938964844,
654
+ "width": 1008,
655
+ "height": 1304.4705882352941,
656
+ "pageNumber": 3
657
+ },
658
+ {
659
+ "x1": 260.25,
660
+ "y1": 826.0499877929688,
661
+ "x2": 828.5832977294922,
662
+ "y2": 846.1499938964844,
663
+ "width": 1008,
664
+ "height": 1304.4705882352941,
665
+ "pageNumber": 3
666
+ },
667
+ {
668
+ "x1": 177.89999389648438,
669
+ "y1": 843.9166564941406,
670
+ "x2": 828.8666687011719,
671
+ "y2": 864.0166473388672,
672
+ "width": 1008,
673
+ "height": 1304.4705882352941,
674
+ "pageNumber": 3
675
+ },
676
+ {
677
+ "x1": 177.3000030517578,
678
+ "y1": 861.9166564941406,
679
+ "x2": 829.4333343505859,
680
+ "y2": 882.0166473388672,
681
+ "width": 1008,
682
+ "height": 1304.4705882352941,
683
+ "pageNumber": 3
684
+ },
685
+ {
686
+ "x1": 177.89999389648438,
687
+ "y1": 879.8999938964844,
688
+ "x2": 828.3499755859375,
689
+ "y2": 899.9999847412109,
690
+ "width": 1008,
691
+ "height": 1304.4705882352941,
692
+ "pageNumber": 3
693
+ },
694
+ {
695
+ "x1": 177.89999389648438,
696
+ "y1": 897.8999938964844,
697
+ "x2": 828.4833374023438,
698
+ "y2": 917.9999847412109,
699
+ "width": 1008,
700
+ "height": 1304.4705882352941,
701
+ "pageNumber": 3
702
+ },
703
+ {
704
+ "x1": 177.89999389648438,
705
+ "y1": 915.7666625976562,
706
+ "x2": 826.1833190917969,
707
+ "y2": 935.8666687011719,
708
+ "width": 1008,
709
+ "height": 1304.4705882352941,
710
+ "pageNumber": 3
711
+ },
712
+ {
713
+ "x1": 177.89999389648438,
714
+ "y1": 933.7666625976562,
715
+ "x2": 433.48333740234375,
716
+ "y2": 953.8666687011719,
717
+ "width": 1008,
718
+ "height": 1304.4705882352941,
719
+ "pageNumber": 3
720
+ },
721
+ {
722
+ "x1": 467.5,
723
+ "y1": 933.7666625976562,
724
+ "x2": 513.5666809082031,
725
+ "y2": 953.8666687011719,
726
+ "width": 1008,
727
+ "height": 1304.4705882352941,
728
+ "pageNumber": 3
729
+ },
730
+ {
731
+ "x1": 433.433349609375,
732
+ "y1": 940.3499755859375,
733
+ "x2": 464.7666778564453,
734
+ "y2": 954.8666381835938,
735
+ "width": 1008,
736
+ "height": 1304.4705882352941,
737
+ "pageNumber": 3
738
+ },
739
+ {
740
+ "x1": 177.89999389648438,
741
+ "y1": 971.8333129882812,
742
+ "x2": 244.10000610351562,
743
+ "y2": 991.9333038330078,
744
+ "width": 1008,
745
+ "height": 1304.4705882352941,
746
+ "pageNumber": 3
747
+ },
748
+ {
749
+ "x1": 256.83331298828125,
750
+ "y1": 971.8333129882812,
751
+ "x2": 828.5499877929688,
752
+ "y2": 991.9333038330078,
753
+ "width": 1008,
754
+ "height": 1304.4705882352941,
755
+ "pageNumber": 3
756
+ },
757
+ {
758
+ "x1": 177.89999389648438,
759
+ "y1": 989.8333129882812,
760
+ "x2": 826.1333312988281,
761
+ "y2": 1009.9333038330078,
762
+ "width": 1008,
763
+ "height": 1304.4705882352941,
764
+ "pageNumber": 3
765
+ },
766
+ {
767
+ "x1": 177.89999389648438,
768
+ "y1": 1007.6999816894531,
769
+ "x2": 826.1333312988281,
770
+ "y2": 1027.7999877929688,
771
+ "width": 1008,
772
+ "height": 1304.4705882352941,
773
+ "pageNumber": 3
774
+ },
775
+ {
776
+ "x1": 177.89999389648438,
777
+ "y1": 1025.6999816894531,
778
+ "x2": 826.1000061035156,
779
+ "y2": 1045.7999877929688,
780
+ "width": 1008,
781
+ "height": 1304.4705882352941,
782
+ "pageNumber": 3
783
+ },
784
+ {
785
+ "x1": 177.89999389648438,
786
+ "y1": 1043.6833190917969,
787
+ "x2": 826.1833190917969,
788
+ "y2": 1063.7833251953125,
789
+ "width": 1008,
790
+ "height": 1304.4705882352941,
791
+ "pageNumber": 3
792
+ },
793
+ {
794
+ "x1": 177.89999389648438,
795
+ "y1": 1061.6833190917969,
796
+ "x2": 826.1000061035156,
797
+ "y2": 1081.7833251953125,
798
+ "width": 1008,
799
+ "height": 1304.4705882352941,
800
+ "pageNumber": 3
801
+ },
802
+ {
803
+ "x1": 177.89999389648438,
804
+ "y1": 1079.5499877929688,
805
+ "x2": 752.1666564941406,
806
+ "y2": 1099.6499938964844,
807
+ "width": 1008,
808
+ "height": 1304.4705882352941,
809
+ "pageNumber": 3
810
+ }
811
+ ]
812
+ },
813
+ "content": {
814
+ "text": "Encoder: The encoder is composed of a stack of N = 6 identical layers. Each layer has two\r sub-layers. The first is a multi-head self-attention mechanism, and the second is a simple, position-\r wise fully connected feed-forward network. We employ a residual connection [ 11 ] around each of\r the two sub-layers, followed by layer normalization [1]. That is, the output of each sub-layer is\r LayerNorm(x + Sublayer(x)), where Sublayer(x) is the function implemented by the sub-layer\r itself. To facilitate these residual connections, all sub-layers in the model, as well as the embedding\r layers, produce outputs of dimension dmodel = 512.\r Decoder: The decoder is also composed of a stack of N = 6 identical layers. In addition to the two\r sub-layers in each encoder layer, the decoder inserts a third sub-layer, which performs multi-head\r attention over the output of the encoder stack. Similar to the encoder, we employ residual connections\r around each of the sub-layers, followed by layer normalization. We also modify the self-attention\r sub-layer in the decoder stack to prevent positions from attending to subsequent positions. This\r masking, combined with fact that the output embeddings are offset by one position, ensures that the\r predictions for position i can depend only on the known outputs at positions less than i."
815
+ }
816
+ }],
817
+ 7: [{
818
+ "id": "highlight_1755504777374",
819
+ "position": {
820
+ "boundingRect": {
821
+ "x1": 177.3000030517578,
822
+ "y1": 1119.8500213623047,
823
+ "x2": 828.1166534423828,
824
+ "y2": 1190.8000030517578,
825
+ "width": 1008,
826
+ "height": 1304.4705882352941,
827
+ "pageNumber": 3
828
+ },
829
+ "rects": [
830
+ {
831
+ "x1": 177.89999389648438,
832
+ "y1": 1119.8500213623047,
833
+ "x2": 202.06666564941406,
834
+ "y2": 1139.9500274658203,
835
+ "width": 1008,
836
+ "height": 1304.4705882352941,
837
+ "pageNumber": 3
838
+ },
839
+ {
840
+ "x1": 214.8000030517578,
841
+ "y1": 1119.8500213623047,
842
+ "x2": 280.93333435058594,
843
+ "y2": 1139.9500274658203,
844
+ "width": 1008,
845
+ "height": 1304.4705882352941,
846
+ "pageNumber": 3
847
+ },
848
+ {
849
+ "x1": 177.3000030517578,
850
+ "y1": 1152.8333740234375,
851
+ "x2": 828.1166534423828,
852
+ "y2": 1172.9333801269531,
853
+ "width": 1008,
854
+ "height": 1304.4705882352941,
855
+ "pageNumber": 3
856
+ },
857
+ {
858
+ "x1": 177.3000030517578,
859
+ "y1": 1170.7000122070312,
860
+ "x2": 826.1166534423828,
861
+ "y2": 1190.8000030517578,
862
+ "width": 1008,
863
+ "height": 1304.4705882352941,
864
+ "pageNumber": 3
865
+ }
866
+ ]
867
+ },
868
+ "content": {
869
+ "text": "3.2 Attention\r An attention function can be described as mapping a query and a set of key-value pairs to an output,\r where the query, keys, values, and output are all vectors. The output is computed as a weighted sum"
870
+ }
871
+ }, {
872
+ "id": "highlight_1755504793920",
873
+ "position": {
874
+ "boundingRect": {
875
+ "x1": 177.89999389648438,
876
+ "y1": 520,
877
+ "x2": 826.0500183105469,
878
+ "y2": 557.9666748046875,
879
+ "width": 1008,
880
+ "height": 1304.4705882352941,
881
+ "pageNumber": 4
882
+ },
883
+ "rects": [
884
+ {
885
+ "x1": 177.89999389648438,
886
+ "y1": 520,
887
+ "x2": 826.0500183105469,
888
+ "y2": 540.1000061035156,
889
+ "width": 1008,
890
+ "height": 1304.4705882352941,
891
+ "pageNumber": 4
892
+ },
893
+ {
894
+ "x1": 177.89999389648438,
895
+ "y1": 537.8666687011719,
896
+ "x2": 399.73333740234375,
897
+ "y2": 557.9666748046875,
898
+ "width": 1008,
899
+ "height": 1304.4705882352941,
900
+ "pageNumber": 4
901
+ }
902
+ ]
903
+ },
904
+ "content": {
905
+ "text": "of the values, where the weight assigned to each value is computed by a compatibility function of the\r query with the corresponding key."
906
+ }
907
+ }],
908
+ 8: [{
909
+ "id": "highlight_1755504830102",
910
+ "position": {
911
+ "boundingRect": {
912
+ "x1": 177.10000610351562,
913
+ "y1": 606.5833282470703,
914
+ "x2": 831.0499877929688,
915
+ "y2": 810.25,
916
+ "width": 1008,
917
+ "height": 1304.4705882352941,
918
+ "pageNumber": 4
919
+ },
920
+ "rects": [
921
+ {
922
+ "x1": 177.10000610351562,
923
+ "y1": 606.5833282470703,
924
+ "x2": 826.0666809082031,
925
+ "y2": 626.6833343505859,
926
+ "width": 1008,
927
+ "height": 1304.4705882352941,
928
+ "pageNumber": 4
929
+ },
930
+ {
931
+ "x1": 177.89999389648438,
932
+ "y1": 624.4499969482422,
933
+ "x2": 828.5833587646484,
934
+ "y2": 644.5500030517578,
935
+ "width": 1008,
936
+ "height": 1304.4705882352941,
937
+ "pageNumber": 4
938
+ },
939
+ {
940
+ "x1": 411.8666687011719,
941
+ "y1": 629.6666717529297,
942
+ "x2": 420.03334045410156,
943
+ "y2": 649.7666625976562,
944
+ "width": 1008,
945
+ "height": 1304.4705882352941,
946
+ "pageNumber": 4
947
+ },
948
+ {
949
+ "x1": 390.08331298828125,
950
+ "y1": 631.1833343505859,
951
+ "x2": 395.29998779296875,
952
+ "y2": 645.6999969482422,
953
+ "width": 1008,
954
+ "height": 1304.4705882352941,
955
+ "pageNumber": 4
956
+ },
957
+ {
958
+ "x1": 578.88330078125,
959
+ "y1": 631.1833343505859,
960
+ "x2": 588.0333557128906,
961
+ "y2": 645.6999969482422,
962
+ "width": 1008,
963
+ "height": 1304.4705882352941,
964
+ "pageNumber": 4
965
+ },
966
+ {
967
+ "x1": 177.89999389648438,
968
+ "y1": 642.4499969482422,
969
+ "x2": 411.43333435058594,
970
+ "y2": 662.5500030517578,
971
+ "width": 1008,
972
+ "height": 1304.4705882352941,
973
+ "pageNumber": 4
974
+ },
975
+ {
976
+ "x1": 425.4666748046875,
977
+ "y1": 642.4499969482422,
978
+ "x2": 827.6499938964844,
979
+ "y2": 662.5500030517578,
980
+ "width": 1008,
981
+ "height": 1304.4705882352941,
982
+ "pageNumber": 4
983
+ },
984
+ {
985
+ "x1": 434.0333251953125,
986
+ "y1": 649.1666717529297,
987
+ "x2": 439.24998474121094,
988
+ "y2": 663.6833343505859,
989
+ "width": 1008,
990
+ "height": 1304.4705882352941,
991
+ "pageNumber": 4
992
+ },
993
+ {
994
+ "x1": 177.5,
995
+ "y1": 660.4499969482422,
996
+ "x2": 222.8333282470703,
997
+ "y2": 680.5500030517578,
998
+ "width": 1008,
999
+ "height": 1304.4705882352941,
1000
+ "pageNumber": 4
1001
+ },
1002
+ {
1003
+ "x1": 177.89999389648438,
1004
+ "y1": 687.4333343505859,
1005
+ "x2": 826.3833312988281,
1006
+ "y2": 707.5333404541016,
1007
+ "width": 1008,
1008
+ "height": 1304.4705882352941,
1009
+ "pageNumber": 4
1010
+ },
1011
+ {
1012
+ "x1": 177.89999389648438,
1013
+ "y1": 705.4333343505859,
1014
+ "x2": 829.4833221435547,
1015
+ "y2": 725.5333404541016,
1016
+ "width": 1008,
1017
+ "height": 1304.4705882352941,
1018
+ "pageNumber": 4
1019
+ },
1020
+ {
1021
+ "x1": 177.89999389648438,
1022
+ "y1": 723.2999877929688,
1023
+ "x2": 336.43333435058594,
1024
+ "y2": 743.3999786376953,
1025
+ "width": 1008,
1026
+ "height": 1304.4705882352941,
1027
+ "pageNumber": 4
1028
+ },
1029
+ {
1030
+ "x1": 613.7666625976562,
1031
+ "y1": 764.0499877929688,
1032
+ "x2": 619.3666687011719,
1033
+ "y2": 778.566650390625,
1034
+ "width": 1008,
1035
+ "height": 1304.4705882352941,
1036
+ "pageNumber": 4
1037
+ },
1038
+ {
1039
+ "x1": 585.7333374023438,
1040
+ "y1": 765.7999877929688,
1041
+ "x2": 612.4833374023438,
1042
+ "y2": 785.8999786376953,
1043
+ "width": 1008,
1044
+ "height": 1304.4705882352941,
1045
+ "pageNumber": 4
1046
+ },
1047
+ {
1048
+ "x1": 362.26666259765625,
1049
+ "y1": 776.8833312988281,
1050
+ "x2": 597.9333343505859,
1051
+ "y2": 796.9833374023438,
1052
+ "width": 1008,
1053
+ "height": 1304.4705882352941,
1054
+ "pageNumber": 4
1055
+ },
1056
+ {
1057
+ "x1": 626.066650390625,
1058
+ "y1": 776.8833312988281,
1059
+ "x2": 645.7833251953125,
1060
+ "y2": 796.9833374023438,
1061
+ "width": 1008,
1062
+ "height": 1304.4705882352941,
1063
+ "pageNumber": 4
1064
+ },
1065
+ {
1066
+ "x1": 812.0333251953125,
1067
+ "y1": 776.8833312988281,
1068
+ "x2": 831.0499877929688,
1069
+ "y2": 796.9833374023438,
1070
+ "width": 1008,
1071
+ "height": 1304.4705882352941,
1072
+ "pageNumber": 4
1073
+ },
1074
+ {
1075
+ "x1": 603.4833374023438,
1076
+ "y1": 789.1499938964844,
1077
+ "x2": 612.1000061035156,
1078
+ "y2": 809.25,
1079
+ "width": 1008,
1080
+ "height": 1304.4705882352941,
1081
+ "pageNumber": 4
1082
+ },
1083
+ {
1084
+ "x1": 611.9500122070312,
1085
+ "y1": 795.7333374023438,
1086
+ "x2": 617.1666870117188,
1087
+ "y2": 810.25,
1088
+ "width": 1008,
1089
+ "height": 1304.4705882352941,
1090
+ "pageNumber": 4
1091
+ }
1092
+ ]
1093
+ },
1094
+ "content": {
1095
+ "text": "We call our particular attention \"Scaled Dot-Product Attention\" (Figure 2). The input consists of\r queries and keys of dimension dk, and values of dimension dv . We compute the dot products of the\r query with all keys, divide each by √dk, and apply a softmax function to obtain the weights on the\r values.\r In practice, we compute the attention function on a set of queries simultaneously, packed together\r into a matrix Q. The keys and values are also packed together into matrices K and V . We compute\r the matrix of outputs as:\r Attention(Q, K, V ) = softmax( QKT\r √dk\r )V (1)"
1096
+ }
1097
+ }],
1098
+ 9: [{
1099
+ "id": "highlight_1755504856607",
1100
+ "position": {
1101
+ "boundingRect": {
1102
+ "x1": 177.10000610351562,
1103
+ "y1": 820.183349609375,
1104
+ "x2": 831.7500305175781,
1105
+ "y2": 1020.2000122070312,
1106
+ "width": 1008,
1107
+ "height": 1304.4705882352941,
1108
+ "pageNumber": 4
1109
+ },
1110
+ "rects": [
1111
+ {
1112
+ "x1": 177.39999389648438,
1113
+ "y1": 820.183349609375,
1114
+ "x2": 831.7500305175781,
1115
+ "y2": 840.2833557128906,
1116
+ "width": 1008,
1117
+ "height": 1304.4705882352941,
1118
+ "pageNumber": 4
1119
+ },
1120
+ {
1121
+ "x1": 177.89999389648438,
1122
+ "y1": 838.183349609375,
1123
+ "x2": 826.3999938964844,
1124
+ "y2": 858.2833557128906,
1125
+ "width": 1008,
1126
+ "height": 1304.4705882352941,
1127
+ "pageNumber": 4
1128
+ },
1129
+ {
1130
+ "x1": 177.89999389648438,
1131
+ "y1": 856.0499877929688,
1132
+ "x2": 195.4166717529297,
1133
+ "y2": 876.1499786376953,
1134
+ "width": 1008,
1135
+ "height": 1304.4705882352941,
1136
+ "pageNumber": 4
1137
+ },
1138
+ {
1139
+ "x1": 224.46665954589844,
1140
+ "y1": 856.0499877929688,
1141
+ "x2": 826.3500213623047,
1142
+ "y2": 876.1499786376953,
1143
+ "width": 1008,
1144
+ "height": 1304.4705882352941,
1145
+ "pageNumber": 4
1146
+ },
1147
+ {
1148
+ "x1": 197.76666259765625,
1149
+ "y1": 858.3333129882812,
1150
+ "x2": 212.64999389648438,
1151
+ "y2": 872.8499908447266,
1152
+ "width": 1008,
1153
+ "height": 1304.4705882352941,
1154
+ "pageNumber": 4
1155
+ },
1156
+ {
1157
+ "x1": 208.5500030517578,
1158
+ "y1": 867.2000122070312,
1159
+ "x2": 219.03334045410156,
1160
+ "y2": 881.7166748046875,
1161
+ "width": 1008,
1162
+ "height": 1304.4705882352941,
1163
+ "pageNumber": 4
1164
+ },
1165
+ {
1166
+ "x1": 215.3000030517578,
1167
+ "y1": 873.0166625976562,
1168
+ "x2": 219.03334045410156,
1169
+ "y2": 881.2166595458984,
1170
+ "width": 1008,
1171
+ "height": 1304.4705882352941,
1172
+ "pageNumber": 4
1173
+ },
1174
+ {
1175
+ "x1": 177.89999389648438,
1176
+ "y1": 877.816650390625,
1177
+ "x2": 826.1000061035156,
1178
+ "y2": 897.9166564941406,
1179
+ "width": 1008,
1180
+ "height": 1304.4705882352941,
1181
+ "pageNumber": 4
1182
+ },
1183
+ {
1184
+ "x1": 177.89999389648438,
1185
+ "y1": 895.683349609375,
1186
+ "x2": 826.0833435058594,
1187
+ "y2": 915.7833557128906,
1188
+ "width": 1008,
1189
+ "height": 1304.4705882352941,
1190
+ "pageNumber": 4
1191
+ },
1192
+ {
1193
+ "x1": 177.89999389648438,
1194
+ "y1": 913.683349609375,
1195
+ "x2": 355.03334045410156,
1196
+ "y2": 933.7833557128906,
1197
+ "width": 1008,
1198
+ "height": 1304.4705882352941,
1199
+ "pageNumber": 4
1200
+ },
1201
+ {
1202
+ "x1": 177.10000610351562,
1203
+ "y1": 940.6666870117188,
1204
+ "x2": 357.0666809082031,
1205
+ "y2": 960.7666778564453,
1206
+ "width": 1008,
1207
+ "height": 1304.4705882352941,
1208
+ "pageNumber": 4
1209
+ },
1210
+ {
1211
+ "x1": 369.1166687011719,
1212
+ "y1": 940.6666870117188,
1213
+ "x2": 827.2833557128906,
1214
+ "y2": 960.7666778564453,
1215
+ "width": 1008,
1216
+ "height": 1304.4705882352941,
1217
+ "pageNumber": 4
1218
+ },
1219
+ {
1220
+ "x1": 357.0333251953125,
1221
+ "y1": 947.2666625976562,
1222
+ "x2": 366.5833282470703,
1223
+ "y2": 961.7833404541016,
1224
+ "width": 1008,
1225
+ "height": 1304.4705882352941,
1226
+ "pageNumber": 4
1227
+ },
1228
+ {
1229
+ "x1": 177.89999389648438,
1230
+ "y1": 958.6666870117188,
1231
+ "x2": 562.6999816894531,
1232
+ "y2": 978.7666778564453,
1233
+ "width": 1008,
1234
+ "height": 1304.4705882352941,
1235
+ "pageNumber": 4
1236
+ },
1237
+ {
1238
+ "x1": 574.75,
1239
+ "y1": 958.6666870117188,
1240
+ "x2": 828.6000213623047,
1241
+ "y2": 978.7666778564453,
1242
+ "width": 1008,
1243
+ "height": 1304.4705882352941,
1244
+ "pageNumber": 4
1245
+ },
1246
+ {
1247
+ "x1": 562.5499877929688,
1248
+ "y1": 965.2666625976562,
1249
+ "x2": 572.1166687011719,
1250
+ "y2": 979.7833404541016,
1251
+ "width": 1008,
1252
+ "height": 1304.4705882352941,
1253
+ "pageNumber": 4
1254
+ },
1255
+ {
1256
+ "x1": 177.89999389648438,
1257
+ "y1": 976.6666870117188,
1258
+ "x2": 826.1999664306641,
1259
+ "y2": 996.7666778564453,
1260
+ "width": 1008,
1261
+ "height": 1304.4705882352941,
1262
+ "pageNumber": 4
1263
+ },
1264
+ {
1265
+ "x1": 186.36666870117188,
1266
+ "y1": 983.25,
1267
+ "x2": 191.5833282470703,
1268
+ "y2": 997.7666625976562,
1269
+ "width": 1008,
1270
+ "height": 1304.4705882352941,
1271
+ "pageNumber": 4
1272
+ },
1273
+ {
1274
+ "x1": 351.2833251953125,
1275
+ "y1": 992.7833251953125,
1276
+ "x2": 740.8499908447266,
1277
+ "y2": 1007.2999877929688,
1278
+ "width": 1008,
1279
+ "height": 1304.4705882352941,
1280
+ "pageNumber": 4
1281
+ },
1282
+ {
1283
+ "x1": 177.89999389648438,
1284
+ "y1": 994.5333251953125,
1285
+ "x2": 723.4999847412109,
1286
+ "y2": 1014.6333160400391,
1287
+ "width": 1008,
1288
+ "height": 1304.4705882352941,
1289
+ "pageNumber": 4
1290
+ },
1291
+ {
1292
+ "x1": 752.6666870117188,
1293
+ "y1": 994.5333251953125,
1294
+ "x2": 756.8000183105469,
1295
+ "y2": 1014.6333160400391,
1296
+ "width": 1008,
1297
+ "height": 1304.4705882352941,
1298
+ "pageNumber": 4
1299
+ },
1300
+ {
1301
+ "x1": 725.8499755859375,
1302
+ "y1": 998.2000122070312,
1303
+ "x2": 731.5666351318359,
1304
+ "y2": 1009.683349609375,
1305
+ "width": 1008,
1306
+ "height": 1304.4705882352941,
1307
+ "pageNumber": 4
1308
+ },
1309
+ {
1310
+ "x1": 736.63330078125,
1311
+ "y1": 1005.683349609375,
1312
+ "x2": 747.2333374023438,
1313
+ "y2": 1020.2000122070312,
1314
+ "width": 1008,
1315
+ "height": 1304.4705882352941,
1316
+ "pageNumber": 4
1317
+ },
1318
+ {
1319
+ "x1": 743.5,
1320
+ "y1": 1011.5,
1321
+ "x2": 747.2333374023438,
1322
+ "y2": 1019.6999969482422,
1323
+ "width": 1008,
1324
+ "height": 1304.4705882352941,
1325
+ "pageNumber": 4
1326
+ }
1327
+ ]
1328
+ },
1329
+ "content": {
1330
+ "text": "The two most commonly used attention functions are additive attention [ 2], and dot-product (multi-\r plicative) attention. Dot-product attention is identical to our algorithm, except for the scaling factor\r of 1√dk\r . Additive attention computes the compatibility function using a feed-forward network with\r a single hidden layer. While the two are similar in theoretical complexity, dot-product attention is\r much faster and more space-efficient in practice, since it can be implemented using highly optimized\r matrix multiplication code.\r While for small values of dk the two mechanisms perform similarly, additive attention outperforms\r dot product attention without scaling for larger values of dk [3 ]. We suspect that for large values of\r dk, the dot products grow large in magnitude, pushing the softmax function into regions where it has\r extremely small gradients 4. To counteract this effect, we scale the dot products by 1√dk\r ."
1331
+ }
1332
+ }],
1333
+ 10: [{
1334
+ "id": "highlight_1755504882387",
1335
+ "position": {
1336
+ "boundingRect": {
1337
+ "x1": 177.3000030517578,
1338
+ "y1": 1067.1666870117188,
1339
+ "x2": 830.683349609375,
1340
+ "y2": 1142.1333770751953,
1341
+ "width": 1008,
1342
+ "height": 1304.4705882352941,
1343
+ "pageNumber": 4
1344
+ },
1345
+ "rects": [
1346
+ {
1347
+ "x1": 177.89999389648438,
1348
+ "y1": 1067.1666870117188,
1349
+ "x2": 546.6833190917969,
1350
+ "y2": 1087.2666931152344,
1351
+ "width": 1008,
1352
+ "height": 1304.4705882352941,
1353
+ "pageNumber": 4
1354
+ },
1355
+ {
1356
+ "x1": 576.1666870117188,
1357
+ "y1": 1067.1666870117188,
1358
+ "x2": 830.683349609375,
1359
+ "y2": 1087.2666931152344,
1360
+ "width": 1008,
1361
+ "height": 1304.4705882352941,
1362
+ "pageNumber": 4
1363
+ },
1364
+ {
1365
+ "x1": 546.5333251953125,
1366
+ "y1": 1073.7500305175781,
1367
+ "x2": 575.1999816894531,
1368
+ "y2": 1088.2666931152344,
1369
+ "width": 1008,
1370
+ "height": 1304.4705882352941,
1371
+ "pageNumber": 4
1372
+ },
1373
+ {
1374
+ "x1": 177.3000030517578,
1375
+ "y1": 1085.0333557128906,
1376
+ "x2": 828.9999847412109,
1377
+ "y2": 1105.1333618164062,
1378
+ "width": 1008,
1379
+ "height": 1304.4705882352941,
1380
+ "pageNumber": 4
1381
+ },
1382
+ {
1383
+ "x1": 177.89999389648438,
1384
+ "y1": 1103.0166931152344,
1385
+ "x2": 347.1999816894531,
1386
+ "y2": 1123.116683959961,
1387
+ "width": 1008,
1388
+ "height": 1304.4705882352941,
1389
+ "pageNumber": 4
1390
+ },
1391
+ {
1392
+ "x1": 359.25,
1393
+ "y1": 1103.0166931152344,
1394
+ "x2": 395.7833557128906,
1395
+ "y2": 1123.116683959961,
1396
+ "width": 1008,
1397
+ "height": 1304.4705882352941,
1398
+ "pageNumber": 4
1399
+ },
1400
+ {
1401
+ "x1": 407.6333312988281,
1402
+ "y1": 1103.0166931152344,
1403
+ "x2": 827.6000061035156,
1404
+ "y2": 1123.116683959961,
1405
+ "width": 1008,
1406
+ "height": 1304.4705882352941,
1407
+ "pageNumber": 4
1408
+ },
1409
+ {
1410
+ "x1": 322.25,
1411
+ "y1": 1109.7500305175781,
1412
+ "x2": 327.46665954589844,
1413
+ "y2": 1124.2666931152344,
1414
+ "width": 1008,
1415
+ "height": 1304.4705882352941,
1416
+ "pageNumber": 4
1417
+ },
1418
+ {
1419
+ "x1": 347.04998779296875,
1420
+ "y1": 1109.7500305175781,
1421
+ "x2": 356.6999969482422,
1422
+ "y2": 1124.2666931152344,
1423
+ "width": 1008,
1424
+ "height": 1304.4705882352941,
1425
+ "pageNumber": 4
1426
+ },
1427
+ {
1428
+ "x1": 395.73333740234375,
1429
+ "y1": 1109.7500305175781,
1430
+ "x2": 404.88331604003906,
1431
+ "y2": 1124.2666931152344,
1432
+ "width": 1008,
1433
+ "height": 1304.4705882352941,
1434
+ "pageNumber": 4
1435
+ },
1436
+ {
1437
+ "x1": 177.89999389648438,
1438
+ "y1": 1121.0166931152344,
1439
+ "x2": 829.6333465576172,
1440
+ "y2": 1141.116683959961,
1441
+ "width": 1008,
1442
+ "height": 1304.4705882352941,
1443
+ "pageNumber": 4
1444
+ },
1445
+ {
1446
+ "x1": 736.8333129882812,
1447
+ "y1": 1127.61669921875,
1448
+ "x2": 746.1000061035156,
1449
+ "y2": 1142.1333770751953,
1450
+ "width": 1008,
1451
+ "height": 1304.4705882352941,
1452
+ "pageNumber": 4
1453
+ }
1454
+ ]
1455
+ },
1456
+ "content": {
1457
+ "text": "Instead of performing a single attention function with dmodel-dimensional keys, values and queries,\r we found it beneficial to linearly project the queries, keys and values h times with different, learned\r linear projections to dk, dk and dv dimensions, respectively. On each of these projected versions of\r queries, keys and values we then perform the attention function in parallel, yielding dv -dimensional"
1458
+ }
1459
+ }, {
1460
+ "id": "highlight_1755504918851",
1461
+ "position": {
1462
+ "boundingRect": {
1463
+ "x1": 177.89999389648438,
1464
+ "y1": 120.20001220703125,
1465
+ "x2": 826.1166687011719,
1466
+ "y2": 158.28335571289062,
1467
+ "width": 1008,
1468
+ "height": 1304.4705882352941,
1469
+ "pageNumber": 5
1470
+ },
1471
+ "rects": [
1472
+ {
1473
+ "x1": 177.89999389648438,
1474
+ "y1": 120.20001220703125,
1475
+ "x2": 826.1166687011719,
1476
+ "y2": 140.30001831054688,
1477
+ "width": 1008,
1478
+ "height": 1304.4705882352941,
1479
+ "pageNumber": 5
1480
+ },
1481
+ {
1482
+ "x1": 177.89999389648438,
1483
+ "y1": 138.183349609375,
1484
+ "x2": 312.8666687011719,
1485
+ "y2": 158.28335571289062,
1486
+ "width": 1008,
1487
+ "height": 1304.4705882352941,
1488
+ "pageNumber": 5
1489
+ }
1490
+ ]
1491
+ },
1492
+ "content": {
1493
+ "text": "output values. These are concatenated and once again projected, resulting in the final values, as\r depicted in Figure 2."
1494
+ }
1495
+ }],
1496
+ };
1497
+
1498
+ // Temporarily inject test highlights into documentData for testing
1499
+ const documentDataWithHighlights = documentData ? {
1500
+ ...documentData,
1501
+ preloadedHighlights: testPreloadedHighlights
1502
+ } : null;
1503
+
1504
  // Sync PDF page navigation with chunk switching
1505
  useEffect(() => {
1506
  if (pdfNavigation && documentData && documentData.chunks[currentChunkIndex]) {
 
1573
  <div className="flex-1 min-h-0">
1574
  <DocumentViewer
1575
  selectedFile={selectedFile}
1576
+ documentData={documentDataWithHighlights}
1577
  onPageChange={setPdfNavigation}
1578
+ preloadedHighlights={documentDataWithHighlights?.preloadedHighlights || null}
1579
+ currentChatId={currentChunkIndex}
1580
  />
1581
  </div>
1582
  </div>
 
1612
  {/* Chunk Panel */}
1613
  <div className="flex-1 flex flex-col min-h-0 bg-white rounded-lg shadow-sm">
1614
  <ChunkPanel
1615
+ documentData={documentDataWithHighlights}
1616
  currentChunkIndex={currentChunkIndex}
1617
  showChat={showChat}
1618
  updateGlobalChatHistory={updateGlobalChatHistory}
frontend/src/components/DocumentViewer.jsx CHANGED
@@ -1,149 +1,144 @@
1
  import { useState, useRef, useEffect } from 'react';
2
- import { Document, Page, pdfjs } from 'react-pdf';
3
- import 'react-pdf/dist/Page/AnnotationLayer.css';
4
- import 'react-pdf/dist/Page/TextLayer.css';
5
 
 
6
  pdfjs.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.js';
7
 
8
- const DocumentViewer = ({ selectedFile, documentData, onPageChange }) => {
9
- const pdfContainerRef = useRef(null);
10
- const [numPages, setNumPages] = useState(null);
11
- const [currentPage, setCurrentPage] = useState(1);
12
- const [zoomLevel, setZoomLevel] = useState(1);
13
- const [visiblePages, setVisiblePages] = useState(new Set([1]));
14
- const [containerWidth, setContainerWidth] = useState(0);
15
-
16
- // Update container width on mount and resize
17
- useEffect(() => {
18
- const updateContainerWidth = () => {
19
- if (pdfContainerRef.current) {
20
- const width = pdfContainerRef.current.clientWidth;
21
- // Subtract padding and some margin for optimal viewing
22
- const availableWidth = width - 32; // 16px padding on each side
23
- setContainerWidth(availableWidth);
24
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  };
 
 
 
 
26
 
27
- updateContainerWidth();
28
- window.addEventListener('resize', updateContainerWidth);
29
- return () => window.removeEventListener('resize', updateContainerWidth);
30
- }, []);
31
 
32
- // Expose goToPage function to parent component (only once when component mounts)
33
- useEffect(() => {
34
- if (onPageChange) {
35
- onPageChange({ goToPage });
 
 
 
 
 
 
 
 
 
36
  }
37
- }, [onPageChange]);
38
-
39
- // Calculate optimal page width
40
- const getPageWidth = () => {
41
- if (!containerWidth) return 600; // Fallback
42
- // Use container width minus some margin, but respect zoom level
43
- const baseWidth = Math.min(containerWidth * 0.99, 2000); // Max 800px for readability
44
- return baseWidth * zoomLevel;
45
  };
46
 
47
- // Handle scroll to update current page and track visible pages
48
- const handleScroll = () => {
49
- if (!pdfContainerRef.current || !numPages) return;
50
-
51
- const container = pdfContainerRef.current;
52
- const scrollTop = container.scrollTop;
53
- const containerHeight = container.clientHeight;
54
- const totalScrollHeight = container.scrollHeight - containerHeight;
55
-
56
- // Calculate which page we're viewing based on scroll position
57
- const scrollPercent = scrollTop / totalScrollHeight;
58
- const newPage = Math.min(Math.floor(scrollPercent * numPages) + 1, numPages);
59
-
60
- if (newPage !== currentPage) {
61
- setCurrentPage(newPage);
62
  }
 
63
 
64
- // Track visible pages based on zoom level
65
- const newVisiblePages = new Set();
66
- const visibleRange = Math.max(1, Math.ceil(2 / zoomLevel));
67
- for (let i = Math.max(1, newPage - visibleRange); i <= Math.min(numPages, newPage + visibleRange); i++) {
68
- newVisiblePages.add(i);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
 
 
 
 
 
 
 
 
70
 
71
- // Update visible pages if changed
72
- if (newVisiblePages.size !== visiblePages.size ||
73
- ![...newVisiblePages].every(page => visiblePages.has(page))) {
74
- setVisiblePages(newVisiblePages);
75
- }
 
 
 
76
  };
77
 
78
- // Jump to specific page
79
- const goToPage = (pageNumber) => {
80
- if (!pdfContainerRef.current || !numPages || pageNumber < 1 || pageNumber > numPages) return;
81
-
82
- // Update visible pages immediately for target page
83
- const newVisiblePages = new Set();
84
- const visibleRange = Math.max(1, Math.ceil(2 / zoomLevel));
85
- for (let i = Math.max(1, pageNumber - visibleRange); i <= Math.min(numPages, pageNumber + visibleRange); i++) {
86
- newVisiblePages.add(i);
87
- }
88
- setVisiblePages(newVisiblePages);
89
-
90
- // Use setTimeout to ensure pages are rendered before scrolling
91
- setTimeout(() => {
92
- const container = pdfContainerRef.current;
93
- if (!container) return;
94
-
95
- // Find the target page element by its data attribute or position
96
- const pageElements = container.querySelectorAll('[data-page-number]');
97
- let targetElement = null;
98
-
99
- // If we can't find elements by data attribute, calculate position manually
100
- if (pageElements.length === 0) {
101
- // Calculate approximate position based on page height
102
- // Each page has some margin (mb-4 = 16px) plus the actual page height
103
- const containerHeight = container.clientHeight;
104
- const totalContent = container.scrollHeight;
105
- const avgPageHeight = totalContent / numPages;
106
- const targetPosition = (pageNumber - 1) * avgPageHeight;
107
-
108
- // Center the page in viewport
109
- const scrollPosition = Math.max(0, targetPosition - containerHeight / 4);
110
-
111
- container.scrollTo({
112
- top: scrollPosition,
113
- behavior: 'smooth'
114
- });
115
- } else {
116
- // Find the specific page element
117
- for (const element of pageElements) {
118
- if (parseInt(element.getAttribute('data-page-number')) === pageNumber) {
119
- targetElement = element;
120
- break;
121
- }
122
- }
123
-
124
- if (targetElement) {
125
- // Scroll to center the page in viewport
126
- const elementRect = targetElement.getBoundingClientRect();
127
- const containerRect = container.getBoundingClientRect();
128
- const scrollOffset = container.scrollTop;
129
-
130
- const targetPosition = scrollOffset + elementRect.top - containerRect.top - (container.clientHeight - elementRect.height) / 4;
131
-
132
- container.scrollTo({
133
- top: Math.max(0, targetPosition),
134
- behavior: 'smooth'
135
- });
136
- }
137
- }
138
- }, 100); // Small delay to ensure rendering
139
  };
140
 
141
- // Zoom controls
142
- const zoomIn = () => setZoomLevel(prev => Math.min(prev + 0.25, 3));
143
- const zoomOut = () => setZoomLevel(prev => Math.max(prev - 0.25, 0.5));
144
- const resetZoom = () => setZoomLevel(1);
145
 
146
- if (!selectedFile) {
147
  return (
148
  <div className="bg-white rounded-lg shadow-sm flex items-center justify-center h-full">
149
  <div className="text-center text-gray-500">
@@ -152,113 +147,29 @@ const DocumentViewer = ({ selectedFile, documentData, onPageChange }) => {
152
  </div>
153
  );
154
  }
155
-
156
  return (
157
  <div className="bg-white rounded-lg shadow-sm flex flex-col relative" style={{ width: '100%', height: '100%' }}>
158
- <div className="sticky top-0 bg-white rounded-t-lg px-6 py-4 border-b border-gray-200 z-10">
159
- <h2 className="text-lg font-semibold text-left text-gray-800">
160
- {documentData?.filename || 'Document'}
161
- </h2>
162
- </div>
163
 
164
- {/* PDF Container */}
165
- <div
166
- ref={pdfContainerRef}
167
- className="flex-1 overflow-auto flex justify-center bg-gray-100"
168
- onScroll={handleScroll}
169
- >
170
- <div className="py-4">
171
- <Document
172
- file={selectedFile}
173
- onLoadSuccess={({ numPages }) => setNumPages(numPages)}
174
- >
175
- {/* Render all pages continuously */}
176
- {numPages && Array.from(new Array(numPages), (_, index) => {
177
- const pageNum = index + 1;
178
- const isVisible = visiblePages.has(pageNum);
179
-
180
- return (
181
- <div key={pageNum} className="mb-4 flex justify-center" data-page-number={pageNum}>
182
- <Page
183
- pageNumber={pageNum}
184
- width={isVisible ? getPageWidth() : getPageWidth() / zoomLevel}
185
- />
186
- </div>
187
- );
188
- })}
189
- </Document>
190
- </div>
191
- </div>
192
-
193
- {/* Pagination overlay - floating pill */}
194
- {numPages && (
195
- <div className="absolute bottom-4 left-1/2 transform -translate-x-1/2 z-10">
196
- <div className="flex items-center bg-gray-800/90 backdrop-blur-sm rounded-full shadow-lg px-3 py-2 space-x-3">
197
- <button
198
- onClick={() => goToPage(Math.max(currentPage - 1, 1))}
199
- disabled={currentPage <= 1}
200
- className="w-8 h-8 rounded-full bg-gray-600 hover:bg-gray-500 disabled:opacity-30 disabled:cursor-not-allowed flex items-center justify-center transition-colors text-white"
201
  >
202
- <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
203
- <path d="M10 12l-4-4 4-4v8z"/>
204
- </svg>
205
- </button>
206
-
207
- <span className="px-3 py-1 text-sm font-medium text-white min-w-[60px] text-center">
208
- {currentPage}/{numPages}
209
- </span>
210
-
211
- <button
212
- onClick={() => goToPage(Math.min(currentPage + 1, numPages))}
213
- disabled={currentPage >= numPages}
214
- className="w-8 h-8 rounded-full bg-gray-600 hover:bg-gray-500 disabled:opacity-30 disabled:cursor-not-allowed flex items-center justify-center transition-colors text-white"
215
- >
216
- <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
217
- <path d="M6 4l4 4-4 4V4z"/>
218
- </svg>
219
- </button>
220
- </div>
221
- </div>
222
- )}
223
-
224
- {/* Zoom controls overlay - bottom right */}
225
- {numPages && (
226
- <div className="absolute bottom-4 right-4 z-10 flex flex-col items-center space-y-2">
227
- {/* Main zoom pill - vertical */}
228
- <div className="flex flex-col items-center bg-gray-800/90 backdrop-blur-sm rounded-full shadow-lg px-2 py-2 space-y-1">
229
- <button
230
- onClick={zoomIn}
231
- disabled={zoomLevel >= 3}
232
- className="w-6 h-6 rounded-full bg-gray-600 hover:bg-gray-500 disabled:opacity-30 disabled:cursor-not-allowed flex items-center justify-center transition-colors text-white"
233
- >
234
- <svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor">
235
- <path d="M8 4v4H4v1h4v4h1V9h4V8H9V4z"/>
236
- </svg>
237
- </button>
238
-
239
- <button
240
- onClick={zoomOut}
241
- disabled={zoomLevel <= 0.5}
242
- className="w-6 h-6 rounded-full bg-gray-600 hover:bg-gray-500 disabled:opacity-30 disabled:cursor-not-allowed flex items-center justify-center transition-colors text-white"
243
- >
244
- <svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor">
245
- <path d="M4 8h8v1H4z"/>
246
- </svg>
247
- </button>
248
- </div>
249
-
250
- {/* Reset button below */}
251
- <button
252
- onClick={resetZoom}
253
- className="w-10 h-10 bg-gray-700 hover:bg-gray-500 backdrop-blur-sm rounded-full shadow-lg flex items-center justify-center text-white transition-colors"
254
- >
255
- <svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor" stroke="currentColor" strokeWidth="0.5">
256
- <path d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z" strokeWidth="1"/>
257
- <path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
258
- </svg>
259
- </button>
260
- </div>
261
- )}
262
  </div>
263
  );
264
  };
 
1
  import { useState, useRef, useEffect } from 'react';
2
+ import { PdfLoader, PdfHighlighter, useHighlightContainerContext, TextHighlight, AreaHighlight } from 'react-pdf-highlighter-extended';
3
+ import * as pdfjs from "pdfjs-dist";
 
4
 
5
+ // Tell pdf.js to use the local worker file
6
  pdfjs.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.js';
7
 
8
+ // Copy exact example from documentation
9
+ const MyHighlightContainer = () => {
10
+ const {
11
+ highlight, // The highlight being rendered
12
+ viewportToScaled, // Convert a highlight position to platform agnostic coords (useful for saving edits)
13
+ screenshot, // Screenshot a bounding rectangle
14
+ isScrolledTo, // Whether the highlight has been auto-scrolled to
15
+ highlightBindings, // Whether the highlight has been auto-scrolled to
16
+ } = useHighlightContainerContext();
17
+
18
+ const isTextHighlight = !Boolean(
19
+ highlight.content && highlight.content.image
20
+ );
21
+
22
+ const component = isTextHighlight ? (
23
+ <TextHighlight
24
+ isScrolledTo={isScrolledTo}
25
+ highlight={highlight}
26
+ />
27
+ ) : (
28
+ <AreaHighlight
29
+ isScrolledTo={isScrolledTo}
30
+ highlight={highlight}
31
+ onChange={(boundingRect) => {
32
+ const edit = {
33
+ position: {
34
+ boundingRect: viewportToScaled(boundingRect),
35
+ rects: [],
36
+ },
37
+ content: {
38
+ image: screenshot(boundingRect),
39
+ },
40
  };
41
+ }}
42
+ bounds={highlightBindings.textLayer}
43
+ />
44
+ );
45
 
46
+ return component;
47
+ };
 
 
48
 
49
+ const DocumentViewer = ({ selectedFile, documentData, onPageChange, preloadedHighlights = null, currentChatId = null }) => {
50
+ const [highlights, setHighlights] = useState([]);
51
+ const [pdfUrl, setPdfUrl] = useState(null);
52
+
53
+ /** Refs for PdfHighlighter utilities */
54
+ const highlighterUtilsRef = useRef();
55
+
56
+ // Utility function to normalize highlight data
57
+ const normalizeHighlight = (highlightData) => {
58
+ // Ensure the highlight has the required structure
59
+ if (!highlightData.id || !highlightData.position || !highlightData.content) {
60
+ console.warn('Invalid highlight data:', highlightData);
61
+ return null;
62
  }
63
+
64
+ return {
65
+ id: highlightData.id,
66
+ position: highlightData.position,
67
+ content: highlightData.content
68
+ };
 
 
69
  };
70
 
71
+ // Convert File object to URL for PdfLoader
72
+ useEffect(() => {
73
+ if (selectedFile) {
74
+ if (typeof selectedFile === 'string') {
75
+ setPdfUrl(selectedFile);
76
+ } else if (selectedFile instanceof File) {
77
+ const url = URL.createObjectURL(selectedFile);
78
+ setPdfUrl(url);
79
+ return () => URL.revokeObjectURL(url);
80
+ }
81
+ } else {
82
+ setPdfUrl(null);
 
 
 
83
  }
84
+ }, [selectedFile]);
85
 
86
+ // Load preloaded highlights when component mounts or when currentChatId changes
87
+ useEffect(() => {
88
+ if (preloadedHighlights) {
89
+ let highlightsToLoad = [];
90
+
91
+ if (currentChatId !== null && currentChatId !== undefined && preloadedHighlights[currentChatId]) {
92
+ // Load highlights for specific chat
93
+ highlightsToLoad = preloadedHighlights[currentChatId];
94
+ } else if (Array.isArray(preloadedHighlights)) {
95
+ // Load all highlights if it's an array
96
+ highlightsToLoad = preloadedHighlights;
97
+ } else if (typeof preloadedHighlights === 'object') {
98
+ // If it's an object without chatId, take all values
99
+ highlightsToLoad = Object.values(preloadedHighlights).flat();
100
+ }
101
+
102
+ // Normalize and filter valid highlights
103
+ const validHighlights = highlightsToLoad
104
+ .map(normalizeHighlight)
105
+ .filter(Boolean);
106
+
107
+ console.log(`🎨 Loading ${validHighlights.length} preloaded highlights${currentChatId ? ` for chat ${currentChatId}` : ''}`);
108
+ setHighlights(validHighlights);
109
+ } else {
110
+ // Clear highlights if no preloaded data
111
+ setHighlights([]);
112
  }
113
+ }, [preloadedHighlights, currentChatId]);
114
+
115
+ // Handle selection - log coordinates and add debugging
116
+ const handleSelection = (selection) => {
117
+ console.log("🎯 SELECTION MADE! Full selection object:", selection);
118
+ console.log("📍 Position:", selection.position);
119
+ console.log("📝 Content:", selection.content);
120
+ console.log("🔍 Type:", selection.type);
121
 
122
+ const newHighlight = {
123
+ id: `highlight_${Date.now()}`,
124
+ position: selection.position,
125
+ content: selection.content
126
+ };
127
+
128
+ console.log("✅ Adding highlight:", newHighlight);
129
+ setHighlights(prev => [...prev, newHighlight]);
130
  };
131
 
132
+ // Additional debugging handlers
133
+ const handleCreateGhost = (ghost) => {
134
+ console.log("👻 Ghost highlight created:", ghost);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  };
136
 
137
+ const handleRemoveGhost = (ghost) => {
138
+ console.log("❌ Ghost highlight removed:", ghost);
139
+ };
 
140
 
141
+ if (!selectedFile || !pdfUrl) {
142
  return (
143
  <div className="bg-white rounded-lg shadow-sm flex items-center justify-center h-full">
144
  <div className="text-center text-gray-500">
 
147
  </div>
148
  );
149
  }
 
150
  return (
151
  <div className="bg-white rounded-lg shadow-sm flex flex-col relative" style={{ width: '100%', height: '100%' }}>
152
+ <h2>{documentData?.filename || 'Document'}</h2>
 
 
 
 
153
 
154
+ <div style={{ height: '500px' }}>
155
+ <PdfLoader document={pdfUrl} workerSrc='/pdf.worker.min.js'>
156
+ {(pdfDocument) => (
157
+ <PdfHighlighter
158
+ enableAreaSelection={(event) => event.altKey}
159
+ pdfDocument={pdfDocument}
160
+ utilsRef={(_pdfHighlighterUtils) => {
161
+ highlighterUtilsRef.current = _pdfHighlighterUtils;
162
+ }}
163
+ highlights={highlights}
164
+ onSelection={handleSelection}
165
+ onCreateGhostHighlight={handleCreateGhost}
166
+ onRemoveGhostHighlight={handleRemoveGhost}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  >
168
+ <MyHighlightContainer />
169
+ </PdfHighlighter>
170
+ )}
171
+ </PdfLoader>
172
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  </div>
174
  );
175
  };
frontend/src/hooks/useDocumentProcessor.js CHANGED
@@ -46,71 +46,121 @@ export const useDocumentProcessor = () => {
46
 
47
  // Use hardcoded chunks for the document
48
  const hardcodedChunks = [
49
- {
50
- "topic": "Magnetfeldmessung und Hysterese-Analyse",
51
- "text": "Zu Beginn des Versuchs haben wir mit Hilfe des Teslameters die Magnetfeldstärke B an der Position der Cd-Lampe bei verschiedenen Spulenströmen gemessen. (siehe Messwerte in Tabelle 1 im Laborbuch). In Figure 1 sind die gemessenen Feldstärken als Funktion der Stromstärke aufgetragen.\nAnhand der Fehlerbalken und der praktisch identischen Überlagerung der beiden linearen Fitgeraden für auf- und absteigende Stromstärken, wird deutlich, dass keine Hystereseeffekte vorliegen. Der lineare Fit wurde hierbei nur auf die Stromstärken bis einschl. 10A angewandt, da für größere Stromstärken das Magnetfeld nicht in direktem proportionalen Zusammenhang ansteigt. Dies ist mit Sättigungseffekten der Magnetisierung des Eisenkerns der verwendeten Spule zu erklären.",
52
- "page": 1
53
- },
54
- {
55
- "topic": "Qualitative Beobachtung des Zeeman-Effekts",
56
- "text": "Mit Hilfe der CMOS Kamera wurde das Spektrum des emittierten Lichts der Cadmiumlampe unter Verwendung des Lummer Gehercke Interferometers beobachtet. Die Beobachtungen wurden in longitudinaler und transversaler Richtung zum Magnetfeld durchgeführt.",
 
 
 
 
 
 
 
 
 
 
57
  "page": 2
58
- },
59
  {
60
- "topic": "Zeeman-Effekt: Longitudinale Richtung mit Filtern",
61
- "text": "## ohne Filter:\n\nEs sind deutlich zwei Linien pro Ordnung zu erkennen. Dies sind die $\\sigma^{+}$und $\\sigma^{-}$Linien. Die $\\pi$ Linie ist in longitudinaler Richtung nicht zu beobachten\n\n## mit $\\lambda / 4$-Plättchen und Polarisationsfilter:\n\nVon der Cadmiumlampe aus betrachtet wird zuerst ein $\\lambda / 4$-Plättchen und danach ein Polarisationsfilter in den Strahlengang gebracht. Je nach Ausrichtung der Filter zueinander wird nun eine der beiden Linien ausgeblendet.\n\n$$\n-45^{\\circ} \\text { Winkel: }\n$$\n\nStehen $\\lambda / 4$-Plättchen und Polarisationsfilter zueinander im $-45^{\\circ}$ Winkel, wird das zirkular polarisierte Licht der $\\sigma^{-}$Linie um $45^{\\circ}$ verschoben linear polarisiert und somit vom Polarisationsfilter abgeschirmt. Folglich ist in dieser Konstellation nur die linke der beiden $\\sigma$ Linien zu beobachten.\n\n$$\n+45^{\\circ} \\text { Winkel: }\n$$\n\nStehen $\\lambda / 4$-Plättchen und Polarisationsfilter zueinander im $+45^{\\circ}$ Winkel, ist nach analogem Prinzip wie zuvor nur die rechte Linie auf dem Kamerabild zu beobachten.",
62
  "page": 2
63
- },
64
  {
65
- "topic": "Zeeman-Effekt: Transversale Richtung und Polarisation",
66
- "text": "## ohne Filter:\n\nEs sind deutlich drei Linien pro Ordnung zu erkennen. Dies sind die $\\sigma^{+}, \\pi$ und $\\sigma^{-}$Linien.\n\n## mit Polarisationsfilter horizontal (in B-Feld Richtung):\n\nDie beiden $\\sigma$-Linien sind vollständig ausgeblendet. Die $\\pi-$ Linie ist deutlich sichtbar.\nmit Polarisationsfilter vertikal $\\left(90^{\\circ}\\right.$ zu B-Feld Richtung):\nDie beiden $\\sigma$-Linien sind klar sichtbar. Die $\\pi$-Linie ist ausgeblendet.\n\nWie in Figure 3 gut zu erkennen ist, sind die ausgeblendeten Linien in beiden Konfigurationen weiterhin leicht sichtbar. Dies ist auf das nicht perfekt homogene Magnetfeld am Ort der Ca-Lampe zurückzuführen. Das Licht ist also nicht perfekt zirkular bzw. in B-Feld Richtung polarisiert, weshalb ein vollständiges Ausblenden im Experiment nicht zu beobachten ist.",
 
 
 
 
 
 
 
 
 
 
67
  "page": 3
68
- },
69
  {
70
- "topic": "Bestimmung des Zeemanshifts und Datenaufbereitung",
71
- "text": "Die Messdaten bei verschiedene Stromstärken wurden jeweils in einem Plot dargestellt. Um für den Fit möglichst saubere Messkurven des Spektrums zu verwenden, wurde die Messreihe bei $I=8 A$ nicht in die Datenauswertung einbezogen, da die Aufspaltung der Cadmiumlinie nur schwer zu beobachten war. Das gleich gilt für die 8. Interferenzodnung, die nicht berücksichtigt wurde. Für die Datenauswertung fließen also die Nullte bis 7. Ordnung jeweils bei 9 bis 13 Ampere ein.\nAls Funktion um die Messdaten zu fitten wurde ein Pseudo-Voigt-Profil verwendet. Die drei Kurven einer Ordnung wurden hierbei gemeinsam mit der Summe dreier Pseudo-Voigt-Profile gefittet. In Figure 4 sind exemplarisch anhand der Daten für $I=12 A$ die Messdaten und der abschnittsweise Fit zu erkennen.",
72
  "page": 4
73
- },
74
  {
75
- "topic": "Fehleranalyse der Fitparameter und Verzerrungseffekte",
76
- "text": "Anhand der Fitparameter wird die Position der $\\sigma$ und $\\pi$ Linien bestimmt. Die Fehler der Fitparameter sind extrem klein $(\\approx 0,1 p x)$ und eigenen sich nicht als realistische Fehler für unsere weitere Rechnung. Als minimalen Fehler nehmen wir daher die Auflösung der Kamera an ( $1 p x$ ) und skalieren alle Fehler so, dass der kleineste Fehler exakt $1 p x$ beträgt. Die anderen Fehler sind dann entsprechend linear skaliert größer. Dies berücksichtigt die unterschiedliche Qualität der Fits auf unterschiedliche Interferenz-Ordnungen, bringt die Fehler aber in einen experimentell realistischen Bereich.\nFür die Berechnung des Zeemanshifts müssen die Verzerrungseffekte der Lummer-Gehrcke-Platte beachtet werden. Hierfür wird die Position der $\\pi$-Linien gegen der Interferenzordnung $k$ der entsprechenden Linie aufgetragen. Der funktionelle Zusammenhang dieser beiden Größen wird durch eine quadratische Funktion $k=f(a)$ approximiert: \n\n $k=f(a)=b a^{2}+c a+d$",
77
  "page": 4
78
- },
 
 
 
 
 
 
 
 
 
 
79
  {
80
- "topic": "Berechnung der Wellenlängen- und Energieverschiebung",
81
- "text": "Die Differenz zur ganzzahligen Ordnung der zugehörigen $\\pi$-Linie ergibt $\\delta k$. Für eine (kleine) Wellenlängenverschiebung $\\delta \\lambda$ gilt:\n\n$$\\n\\delta \\lambda=\\frac{\\delta k}{\\Delta k} \\cdot \\frac{\\lambda^{2}}{2 d \\cdot \\sqrt{n^{2}-1}}\n$$\n\nFür den Abstand $\\Delta k$ zweier Ordnungen gilt $\\Delta k=1$. Für die Wellenlänge $\\lambda$ der betrachten Linie verwenden wir den in Part 2 bestimmten Wert von $\\lambda=$ $(643,842 \\pm 0,007) \\mathrm{nm}$.\nWir kennen nun die Wellenlänge des Zeemanshift für jede von uns betrachtete Linie. Mit dem Zusammenhang zwischen Wellenlänge und Energie $E=\\frac{h c}{\\lambda}$ lässt sich nun die Energieverschiebung der Linine bestimmen. Wir nehmen an, dass die Wellenlängenverschiebung $\\delta \\lambda$ klein gegenüber der absoluten Wellenlänge $\\lambda$ ist, und erhalten daher für die Energieverschiebung $\\delta E$ in guter Näherung:\n\n$$\\n\\delta E=\\frac{h c}{\\lambda^{2}} \\delta \\lambda\n$$",
82
  "page": 5
83
- },
84
  {
85
- "topic": "Bestimmung des Bohrschen Magnetons aus experimentellen Daten",
86
- "text": "Abschließend nehmen wir den Durchschnitt aller Werte $\\delta E$ für eine Stromstärke $I$.\n\n### 3.2 Bestimmen des Bohrschen Magnetons $\\mu_{B}$ \n\nFür die Energieverschiebung beim Zeemaneffekt gilt:\n\n$$\n\\delta E=\\mu_{B} \\cdot m_{l} \\cdot B\n$$\n\nDa es sich bei der betrachteten Cadmiumlinie um einen ${ }^{1} D_{2} \\rightarrow{ }^{1} P_{1}$ Übergang handelt gilt hier $m_{l}= \\pm 1$. Somit folgt für das Bohrsche Magneton $\\mu_{B}$ als Funktion des Spulenstroms $I$ :\n\n$$\n\\mu_{B}(I)=\\frac{\\delta E(I)}{B(I)}\n$$\n\nDie Magnetfeldstärke $B(I)$ wurde hier anhand der Messwerte aus Teil 1 des Experiments bestimmt.\nWir erhalten für jeden Spulenstrom $I$ einen experimentell bestimmten Wert des Bohrschen Magnetons $\\mu_{B}$. Unsere Ergebnisse sind in Figure 6 graphisch dargestellt.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  "page": 6
88
- },
89
  {
90
- "topic": "Vergleich des experimentellen Werts mit dem Literaturwert",
91
- "text": "Für den experimentellen Mittelwert erhalten wir:\n\n$$\n\\mu_{B, \\exp }=(10,1 \\pm 0.8) \\cdot 10^{-24} \\frac{J}{T}\n$$\n\nDer Literaturwert beträgt:\n\n$$\n\\mu_{B, l i t}=9,27400949 \\cdot 10^{-24} \\frac{J}{T}\n$$\n\nUnsere experimentell ermittelte Wert weicht also um 1,2 Sigma vom Literaturwert ab. Die Abweichung ist folglich nicht signifikant.",
92
  "page": 6
93
- },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  {
95
- "topic": "Kritische Betrachtung der Ergebnisse und Fehlerquellen",
96
- "text": "Erfreulicherweise scheint unsere experimentelle Methode keine signifikante Abweichung zwischen Literaturwert und experimentellem Wert des Bohrschen Magnetons zu ergeben. Wir befinden uns mit unserem Wert im niedirgen 2-SigmaIntervall. Dennoch ist kritisch anzumerken, dass wir einen vergleichsweise großen realtiven Fehler auf unser Messergebnis von $7,1 \\%$ erhalten. Das bedeutet, unsere Abweichung ist zwar nicht sigifikant, dennoch weicht unser experimenteller Wert um knapp $10 \\%$ vom Literaturwert ab. Der verwendete experimentelle Aufbau ist folglich nur bedingt für eine exakte Bestimmung des Bohrschen Magnetons geeigent.\n\nDie beiden dominierenden Fehlerquellen sind zum einen die Bestimmung des Magnetfeldes B am Ort der Cadmium Lampe (Inhomogenitäten, exakte Platzierung der Lampe) und zum anderen die Wahl der Fehler der Positionen der $\\pi$ - und $\\sigma$-Linien im Spektrum.\nZum Vergleich: Legt man den Fehler prinzipiell für alle Linien auf $1 p x$, also die maximale Auflösung der Kamera, fest und verzichtet auf eine Skalierung der Fehler, beträgt die Abweichung des exp. Werts zum Literaturwert schon 2,8 Sigma. Wählt man analog für den Fehler der Linien $2 p x$, da beispielsweise ein Maximum auch exakt zwischen zwei Pixelreihen liegen kann, liegt die Abweichung bei 1,4 Sigma.",
97
  "page": 7
98
- },
99
- {
100
- "topic": "Quantitative Spektrumsbetrachtung und Wellenlängenbestimmung der Cd-Linie",
101
- "text": "Zunächst wird der Untergrund von den Messdaten abgezogen, um Störungen durch Rauschen oder Sondereffekte wie kosmische Strahlung oder Umgebungsquellen zu eliminieren. Sollten sich in den Spektren negative Werte befinden, ist dies auf zufällige Unterschiede im Rauschen zurückzuführen. Anhand bekannter Linien des Neonspektrums werden den Pixeln nun Wellenlängen zugeordnet. Hierfür wurde der Bereich des Neonspektrums aufgenommen, in dem sich auch die rote Linie des Cadmiumspektrums befindet. In 7 sieht man das Neonspektrum und die Peaks, an die jeweils ein Voigt-Profil gelegt wurde. Jetzt kann man den identifizierten Linien ihre jeweilige Wellenlänge zuordnen und einen polynomiellen Zusammenhang finden. Wir haben uns für eine Gerade entschieden, die wie in Figure 8 zu sehen gut zu den Daten passt.\nSchließlich wird ein Voigt-Profil an die gemessene rote Cd-Linie gelegt, wie in Figure 9 gezeigt. Umrechnung anhand der Kalibrierung führt auf einen Wert von $\\lambda_{C d}=(643,842 \\pm 0,007) \\mathrm{nm}$. Dies befindet sich im $1 \\sigma$-Bereich des Literaturwertes von $\\lambda_{L i t}=643,84695 \\mathrm{~nm}$. Der Fehler ist Ergebnis der Gauß'schen Fehlerfortpflanzung.",
102
- "page": 8
103
- },
104
- {
105
- "topic": "Kritische Betrachtung der Genauigkeit und systematischer Fehler",
106
- "text": "Messwert und theoretische Vorhersage für die bestimmte Linie stimmen innerhalb statistischer Schwankungen überein. Dies ist umso interessanter, wenn man die Unsicherheit des Messergebnisses betrachtet, die kleiner als 0,002\\% ist. Der absolute Fehler ist, wenn man die Steigung der Kalibrationsgeraden betrachtet, kleiner als 1px. Er besteht ausschließlich aus Abweichungen der numerischen Fits. Berücksichtigt man Ungenauigkeiten des CMOS Sensors oder die Möglichkeit, dass je nach Lage des Messwerts auch eine Abweichung um weniger als 1px eine größere Messwertschwankung verursachen kann, da die Pixel nur diskrete Werte messen können, liegt eine nachträgliche Anpassung nahe. Skaliert man die Unsicherheit auf 1px, liegt der Fehler des Messwerts bei $0,012 \\mathrm{~nm}$. Damit ist der relative Fehler weiterhin kleiner $0,005 \\%$.\n\nZur hohen Genauigkeit trägt vor allem das gute Messverfahren bei. Spektrometer und Datenaufnahme per Computer lassen wenig Raum für Abweichungen. Wie die Daten zeigen, haben wir dabei eine Quelle für einen möglichen großen systematischen Fehler umgangen: Die Kamera wurde auf das Spektrometer nur locker aufgesteckt. Hätte sich deren Position zwischen Neon- und Cadmiummessung z.B. durch Erschütterung des Labortisches verändert, hätte die Energiekalibrierung nicht mehr zur Messung der Cadmiumlinie gepasst.",
107
- "page": 9
108
- },
109
- {
110
- "topic": "Unerwartetes Verhalten durch mögliche Restmagnetisierung",
111
- "text": "Abbildung 6 zeigt unerwartetes Verhalten. Obwohl der Magnet ausgeschaltet war, sind drei Maxima zu sehen, deren Flanken sehr steil abfallen. Vergleicht man mit den Messungen im Magnetfeld, ähneln sich die Strukturen. Möglich ist, dass die Eisenkernspule, in der sich die Lampe während der Messung befand eine Restmagnetisierung aufwies, die eine Aufspaltung herbeigeführt hat.",
112
- "page": 9
113
- }
114
  ];
115
 
116
  setDocumentData({
 
46
 
47
  // Use hardcoded chunks for the document
48
  const hardcodedChunks = [
49
+ {
50
+ "topic": "The Dominance of Recurrent Models",
51
+ "text": "Recurrent neural networks, long short-term memory [\\\[13\\\]](#page-10-0) and gated recurrent [\\\[7\\\]](#page-10-1) neural networks in particular, have been firmly established as state of the art approaches in sequence modeling and transduction problems such as language modeling and machine translation [\\\[35,](#page-11-0) [2,](#page-9-0) [5\\\]](#page-10-2). Numerous efforts have since continued to push the boundaries of recurrent language models and encoder-decoder architectures [\\\[38,](#page-11-1) [24,](#page-10-3) [15\\\]](#page-10-4).",
52
+ "page": 2
53
+ },
54
+ {
55
+ "topic": "The Sequential Bottleneck of RNNs",
56
+ "text": "Recurrent models typically factor computation along the symbol positions of the input and output sequences. Aligning the positions to steps in computation time, they generate a sequence of hidden states ht, as a function of the previous hidden state ht−<sup>1</sup> and the input for position t. This inherently sequential nature precludes parallelization within training examples, which becomes critical at longer sequence lengths, as memory constraints limit batching across examples. Recent work has achieved significant improvements in computational efficiency through factorization tricks [\\\[21\\\]](#page-10-5) and conditional computation [\\\[32\\\]](#page-11-2), while also improving model performance in case of the latter. The fundamental constraint of sequential computation, however, remains.",
57
+ "page": 2
58
+ },
59
+ {
60
+ "topic": "The Rise of Attention Mechanisms",
61
+ "text": "Attention mechanisms have become an integral part of compelling sequence modeling and transduction models in various tasks, allowing modeling of dependencies without regard to their distance in the input or output sequences [\\\[2,](#page-9-0) [19\\\]](#page-10-6). In all but a few cases [\\\[27\\\]](#page-11-3), however, such attention mechanisms are used in conjunction with a recurrent network.",
62
+ "page": 2
63
+ },
64
+ {
65
+ "topic": "Alternative Architectures to Reduce Sequential Computation",
66
+ "text": "The goal of reducing sequential computation also forms the foundation of the Extended Neural GPU [\\\[16\\\]](#page-10-7), ByteNet [\\\[18\\\]](#page-10-8) and ConvS2S [\\\[9\\\]](#page-10-9), all of which use convolutional neural networks as basic building block, computing hidden representations in parallel for all input and output positions. In these models, the number of operations required to relate signals from two arbitrary input or output positions grows in the distance between positions, linearly for ConvS2S and logarithmically for ByteNet. This makes it more difficult to learn dependencies between distant positions [\\\[12\\\]](#page-10-10). In the Transformer this is reduced to a constant number of operations, albeit at the cost of reduced effective resolution due to averaging attention-weighted positions, an effect we counteract with Multi-Head Attention as described in section [3.2.](#page-2-0)",
67
  "page": 2
68
+ },
69
  {
70
+ "topic": "Self-Attention (Intra-Attention)",
71
+ "text": "Self-attention, sometimes called intra-attention is an attention mechanism relating different positions of a single sequence in order to compute a representation of the sequence. Self-attention has been used successfully in a variety of tasks including reading comprehension, abstractive summarization, textual entailment and learning task-independent sentence representations [\\\[4,](#page-9-1) [27,](#page-11-3) [28,](#page-11-4) [22\\\]](#page-10-11). To the best of our knowledge, however, the Transformer is the first transduction model relying entirely on self-attention to compute representations of its input and output without using sequencealigned RNNs or convolution. In the following sections, we will describe the Transformer, motivate self-attention and discuss its advantages over models such as [\\\[17,](#page-10-12) [18\\\]](#page-10-8) and [\\\[9\\\]](#page-10-9).",
72
  "page": 2
73
+ },
74
  {
75
+ "topic": "The Standard Encoder-Decoder Structure",
76
+ "text": "Most competitive neural sequence transduction models have an encoder-decoder structure [\\\[5,](#page-10-2) [2,](#page-9-0) [35\\\]](#page-11-0). Here, the encoder maps an input sequence of symbol representations (x1, ..., xn) to a sequence of continuous representations z = (z1, ..., zn). Given z, the decoder then generates an output sequence (y1, ..., ym) of symbols one element at a time. At each step the model is auto-regressive [\\\[10\\\]](#page-10-13), consuming the previously generated symbols as additional input when generating the next.",
77
+ "page": 2
78
+ },
79
+ {
80
+ "topic": "Inside the Encoder and Decoder Stacks",
81
+ "text": "### 3.1 Encoder and Decoder Stacks\n\nEncoder: The encoder is composed of a stack of N = 6 identical layers. Each layer has two sub-layers. The first is a multi-head self-attention mechanism, and the second is a simple, positionwise fully connected feed-forward network. We employ a residual connection [\\\[11\\\]](#page-10-14) around each of the two sub-layers, followed by layer normalization [\\\[1\\\]](#page-9-2). That is, the output of each sub-layer is LayerNorm(x + Sublayer(x)), where Sublayer(x) is the function implemented by the sub-layer itself. To facilitate these residual connections, all sub-layers in the model, as well as the embedding layers, produce outputs of dimension dmodel = 512.\n\nDecoder: The decoder is also composed of a stack of N = 6 identical layers. In addition to the two sub-layers in each encoder layer, the decoder inserts a third sub-layer, which performs multi-head attention over the output of the encoder stack. Similar to the encoder, we employ residual connections around each of the sub-layers, followed by layer normalization. We also modify the self-attention sub-layer in the decoder stack to prevent positions from attending to subsequent positions. This masking, combined with fact that the output embeddings are offset by one position, ensures that the predictions for position i can depend only on the known outputs at positions less than i.",
82
+ "page": 3
83
+ },
84
+ {
85
+ "topic": "The Attention Function: Query, Key, Value",
86
+ "text": "### 3.2 Attention\n\nAn attention function can be described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and output are all vectors. The output is computed as a weighted sum\n\n![](_page_3_Figure_0.jpeg)\n\n<span id=\"page-3-0\"></span><span id=\"page-3-0\"></span>Figure 2: (left) Scaled Dot-Product Attention. (right) Multi-Head Attention consists of several attention layers running in parallel.\n\nof the values, where the weight assigned to each value is computed by a compatibility function of the query with the corresponding key.",
87
  "page": 3
88
+ },
89
  {
90
+ "topic": "Core Mechanism: Scaled Dot-Product Attention",
91
+ "text": "### 3.2.1 Scaled Dot-Product Attention\n\nWe call our particular attention \"Scaled Dot-Product Attention\" (Figure 2). The input consists of queries and keys of dimension $d_k$ , and values of dimension $d_v$ . We compute the dot products of the query with all keys, divide each by $\\sqrt{d_k}$ , and apply a softmax function to obtain the weights on the values.\n\nIn practice, we compute the attention function on a set of queries simultaneously, packed together into a matrix $Q$ . The keys and values are also packed together into matrices $K$ and $V$ . We compute the matrix of outputs as:\n\n$$Attention(Q, K, V) = softmax(\\frac{QK^{T}}{\\sqrt{d_{k}}})V$$\n(1)",
92
  "page": 4
93
+ },
94
  {
95
+ "topic": "Why Scaling is Crucial",
96
+ "text": "The two most commonly used attention functions are additive attention [2], and dot-product (multiplicative) attention. Dot-product attention is identical to our algorithm, except for the scaling factor of $\\frac{1}{\\sqrt{d_k}}$ . Additive attention computes the compatibility function using a feed-forward network with a single hidden layer. While the two are similar in theoretical complexity, dot-product attention is much faster and more space-efficient in practice, since it can be implemented using highly optimized matrix multiplication code.\n\nWhile for small values of $d_k$ the two mechanisms perform similarly, additive attention outperforms dot product attention without scaling for larger values of $d_k$ [3]. We suspect that for large values of $d_k$ , the dot products grow large in magnitude, pushing the softmax function into regions where it has extremely small gradients<sup>4</sup>. To counteract this effect, we scale the dot products by $\\frac{1}{\\sqrt{d}}$ .",
97
  "page": 4
98
+ },
99
+ {
100
+ "topic": "Innovation: Multi-Head Attention",
101
+ "text": "### 3.2.2 Multi-Head Attention\n\nInstead of performing a single attention function with $d_{\\text{model}}$ -dimensional keys, values and queries, we found it beneficial to linearly project the queries, keys and values $h$ times with different, learned linear projections to $d_k$ , $d_k$ and $d_v$ dimensions, respectively. On each of these projected versions of queries, keys and values we then perform the attention function in parallel, yielding $d_v$ -dimensional output values. These are concatenated and once again projected, resulting in the final values, as depicted in Figure [2.](#page-3-0)",
102
+ "page": 4
103
+ },
104
+ {
105
+ "topic": "The Power of Multi-Head Attention",
106
+ "text": "Multi-head attention allows the model to jointly attend to information from different representation subspaces at different positions. With a single attention head, averaging inhibits this.\n\n$$\\begin{aligned} \\text{MultiHead}(Q, K, V) &= \\text{Concat}(\\text{head}_1, ..., \\text{head}_h)W^O \\\\ \\text{where } \\text{head}_i &= \\text{Attention}(QW_i^Q, KW_i^K, VW_i^V) \\end{aligned}$$\n\nWhere the projections are parameter matrices W Q <sup>i</sup> <sup>∈</sup> <sup>R</sup> <sup>d</sup>model×d<sup>k</sup> , W <sup>K</sup> <sup>i</sup> ∈ R <sup>d</sup>model×d<sup>k</sup> , W<sup>V</sup> <sup>i</sup> ∈ R dmodel×d<sup>v</sup> and W<sup>O</sup> ∈ R hdv×dmodel .\n\nIn this work we employ h = 8 parallel attention layers, or heads. For each of these we use d<sup>k</sup> = d<sup>v</sup> = dmodel/h = 64. Due to the reduced dimension of each head, the total computational cost is similar to that of single-head attention with full dimensionality.",
107
+ "page": 5
108
+ },
109
  {
110
+ "topic": "Three Uses of Attention in the Model",
111
+ "text": "### 3.2.3 Applications of Attention in our Model\n\nThe Transformer uses multi-head attention in three different ways:\n\n- In \"encoder-decoder attention\" layers, the queries come from the previous decoder layer, and the memory keys and values come from the output of the encoder. This allows every position in the decoder to attend over all positions in the input sequence. This mimics the typical encoder-decoder attention mechanisms in sequence-to-sequence models such as [\\\[38,\\\](#page-11-1) [2,\\\](#page-9-0) [9\\\]](#page-10-9).\n- The encoder contains self-attention layers. In a self-attention layer all of the keys, values and queries come from the same place, in this case, the output of the previous layer in the encoder. Each position in the encoder can attend to all positions in the previous layer of the encoder.\n- Similarly, self-attention layers in the decoder allow each position in the decoder to attend to all positions in the decoder up to and including that position. We need to prevent leftward information flow in the decoder to preserve the auto-regressive property. We implement this inside of scaled dot-product attention by masking out (setting to −∞) all values in the input of the softmax which correspond to illegal connections. See Figure [2.](#page-3-0)",
112
  "page": 5
113
+ },
114
  {
115
+ "topic": "The Role of Position-wise Feed-Forward Networks",
116
+ "text": "### 3.3 Position-wise Feed-Forward Networks\n\nIn addition to attention sub-layers, each of the layers in our encoder and decoder contains a fully connected feed-forward network, which is applied to each position separately and identically. This consists of two linear transformations with a ReLU activation in between.\n\n$$FFN(x) = \\max(0, xW_1 + b_1)W_2 + b_2 \\tag{2}$$\n\nWhile the linear transformations are the same across different positions, they use different parameters from layer to layer. Another way of describing this is as two convolutions with kernel size 1. The dimensionality of input and output is dmodel = 512, and the inner-layer has dimensionality df f = 2048.",
117
+ "page": 5
118
+ },
119
+ {
120
+ "topic": "Input/Output: Embeddings and Softmax",
121
+ "text": "### 3.4 Embeddings and Softmax\n\nSimilarly to other sequence transduction models, we use learned embeddings to convert the input tokens and output tokens to vectors of dimension dmodel. We also use the usual learned linear transformation and softmax function to convert the decoder output to predicted next-token probabilities. In our model, we share the same weight matrix between the two embedding layers and the pre-softmax linear transformation, similar to [\\\[30\\\]](#page-11-6). In the embedding layers, we multiply those weights by <sup>√</sup> dmodel.",
122
+ "page": 5
123
+ },
124
+ {
125
+ "topic": "Solving Sequence Order: Positional Encodings",
126
+ "text": "### 3.5 Positional Encoding\n\nSince our model contains no recurrence and no convolution, in order for the model to make use of the order of the sequence, we must inject some information about the relative or absolute position of the tokens in the sequence. To this end, we add \"positional encodings\" to the input embeddings at the bottoms of the encoder and decoder stacks. The positional encodings have the same dimension $d_{\\text{model}}$ as the embeddings, so that the two can be summed. There are many choices of positional encodings, learned and fixed [9].",
127
+ "page": 6
128
+ },
129
+ {
130
+ "topic": "The Sinusoidal Positional Encoding Function",
131
+ "text": "In this work, we use sine and cosine functions of different frequencies:\n\n$$PE_{(pos,2i)} = sin(pos/10000^{2i/d_{\\text{model}}})$$\n$$PE_{(pos,2i+1)} = cos(pos/10000^{2i/d_{\\text{model}}})$$\n\nwhere $pos$ is the position and i is the dimension. That is, each dimension of the positional encoding corresponds to a sinusoid. The wavelengths form a geometric progression from $2\\pi$ to $10000 \\cdot 2\\pi$ . We chose this function because we hypothesized it would allow the model to easily learn to attend by relative positions, since for any fixed offset $k$ , $PE_{pos+k}$ can be represented as a linear function of $PE_{pos}$ .\n\nWe also experimented with using learned positional embeddings [9] instead, and found that the two versions produced nearly identical results (see Table 3 row $(\\bar{E})$ ). We chose the sinusoidal version because it may allow the model to extrapolate to sequence lengths longer than the ones encountered during training.",
132
+ "page": 6
133
+ },
134
+ {
135
+ "topic": "Why Self-Attention? The Three Desiderata",
136
+ "text": "#### Why Self-Attention 4\n\nIn this section we compare various aspects of self-attention layers to the recurrent and convolutional layers commonly used for mapping one variable-length sequence of symbol representations $(x_1,...,x_n)$ to another sequence of equal length $(z_1,...,z_n)$ , with $x_i,z_i\\in\\mathbb{R}^d$ , such as a hidden layer in a typical sequence transduction encoder or decoder. Motivating our use of self-attention we consider three desiderata.\n\nOne is the total computational complexity per layer. Another is the amount of computation that can be parallelized, as measured by the minimum number of sequential operations required.\n\nThe third is the path length between long-range dependencies in the network. Learning long-range dependencies is a key challenge in many sequence transduction tasks. One key factor affecting the ability to learn such dependencies is the length of the paths forward and backward signals have to traverse in the network. The shorter these paths between any combination of positions in the input and output sequences, the easier it is to learn long-range dependencies [12]. Hence we also compare the maximum path length between any two input and output positions in networks composed of the different layer types.",
137
  "page": 6
138
+ },
139
  {
140
+ "topic": "Comparing Layer Types by Key Metrics",
141
+ "text": "As noted in Table 1, a self-attention layer connects all positions with a constant number of sequentially executed operations, whereas a recurrent layer requires $O(n)$ sequential operations. In terms of computational complexity, self-attention layers are faster than recurrent layers when the sequence\n\n<span id=\"page-5-0\"></span><span id=\"page-5-0\"></span>Table 1: Maximum path lengths, per-layer complexity and minimum number of sequential operations for different layer types. $n$ is the sequence length, $d$ is the representation dimension, $k$ is the kernel size of convolutions and $r$ the size of the neighborhood in restricted self-attention.\n\n| Layer Type | Complexity per Layer | Sequential<br>Operations | Maximum Path Length |\n|-----------------------------|--------------------------|--------------------------|---------------------|\n| Self-Attention | $O(n^2 \\cdot d)$ | O(1) | O(1) |\n| Recurrent | $O(n \\cdot d^2)$ | O(n) | O(n) |\n| Convolutional | $O(k \\cdot n \\cdot d^2)$ | O(1) | $O(log_k(n))$ |\n| Self-Attention (restricted) | $O(r \\cdot n \\cdot d)$ | $\\mathcal{O}(1)$ | O(n/r) |\n\nlength n is smaller than the representation dimensionality d, which is most often the case with sentence representations used by state-of-the-art models in machine translations, such as word-piece [\\\[38\\\]](#page-11-1) and byte-pair [\\\[31\\\]](#page-11-7) representations. To improve computational performance for tasks involving very long sequences, self-attention could be restricted to considering only a neighborhood of size r in the input sequence centered around the respective output position. This would increase the maximum path length to O(n/r). We plan to investigate this approach further in future work.",
142
  "page": 6
143
+ },
144
+ {
145
+ "topic": "A Side Benefit: Interpretability",
146
+ "text": "As side benefit, self-attention could yield more interpretable models. We inspect attention distributions from our models and present and discuss examples in the appendix. Not only do individual attention heads clearly learn to perform different tasks, many appear to exhibit behavior related to the syntactic and semantic structure of the sentences.",
147
+ "page": 7
148
+ },
149
+ {
150
+ "topic": "Training Data, Batching, and Hardware",
151
+ "text": "### 5.1 Training Data and Batching\n\nWe trained on the standard WMT 2014 English-German dataset consisting of about 4.5 million sentence pairs. Sentences were encoded using byte-pair encoding [\\\[3\\\]](#page-9-3), which has a shared sourcetarget vocabulary of about 37000 tokens. For English-French, we used the significantly larger WMT 2014 English-French dataset consisting of 36M sentences and split tokens into a 32000 word-piece vocabulary [\\\[38\\\]](#page-11-1). Sentence pairs were batched together by approximate sequence length. Each training batch contained a set of sentence pairs containing approximately 25000 source tokens and 25000 target tokens.\n\n### 5.2 Hardware and Schedule\n\nWe trained our models on one machine with 8 NVIDIA P100 GPUs. For our base models using the hyperparameters described throughout the paper, each training step took about 0.4 seconds. We trained the base models for a total of 100,000 steps or 12 hours. For our big models,(described on the bottom line of table [3\\)](#page-8-0), step time was 1.0 seconds. The big models were trained for 300,000 steps (3.5 days).",
152
+ "page": 7
153
+ },
154
+ {
155
+ "topic": "The Adam Optimizer and Learning Rate Schedule",
156
+ "text": "### 5.3 Optimizer\n\nWe used the Adam optimizer [\\\[20\\\]](#page-10-16) with β<sup>1</sup> = 0.9, β<sup>2</sup> = 0.98 and ϵ = 10<sup>−</sup><sup>9</sup> . We varied the learning rate over the course of training, according to the formula:\n\n$$lrate = d_{\\text{model}}^{-0.5} \\cdot \\min(\\text{step\\_num}^{-0.5}, \\text{step\\_num} \\cdot \\text{warmup\\_steps}^{-1.5})$$\n (3)\n\nThis corresponds to increasing the learning rate linearly for the first warmup\\_steps training steps, and decreasing it thereafter proportionally to the inverse square root of the step number. We used warmup\\_steps = 4000.",
157
+ "page": 7
158
+ },
159
  {
160
+ "topic": "Regularization Techniques",
161
+ "text": "### 5.4 Regularization\n\nWe employ three types of regularization during training:\n\n**Residual Dropout** We apply dropout [33] to the output of each sub-layer, before it is added to the sub-layer input and normalized. In addition, we apply dropout to the sums of the embeddings and the positional encodings in both the encoder and decoder stacks. For the base model, we use a rate of $P_{drop} = 0.1.$\n\n**Label Smoothing** During training, we employed label smoothing of value $\\epsilon_{ls} = 0.1$ [36]. This hurts perplexity, as the model learns to be more unsure, but improves accuracy and BLEU score.",
162
  "page": 7
163
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  ];
165
 
166
  setDocumentData({
log.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ File /home/alleinzell/SokratesAI/log.txt
2
+
3
+ Errors :
4
+ 4 : there is no definition with the identity: 0
5
+ 7 : there is no definition with the identity: 0
6
+
7
+ Warnings :
8
+ 1 : the definition is not identified
9
+ 3 : the definition is not identified
10
+ 6 : the definition is not identified
11
+ 9 : the definition is not identified
12
+
13
+ Your trace has 2 errors and 4 warnings.