KolmoPDF Solutions · Россия

Solutions

RAG пайплайны · Claude Code · Cursor · DeepSeek · Локальные LLM

Когда в кодовой базе PDF с формулами, а нейросеть просит чистый Markdown

Современные AI-ассистенты и корпоративные RAG-системы (Retrieval-Augmented Generation) великолепно оперируют чистым исходным кодом и текстом в формате Markdown, но спотыкаются о бинарные PDF-файлы: научные статьи с arXiv, математические публикации и спецификации теряют таблицы и формулы при стандартном извлечении текста через pypdf или pdfminer. KolmoPDF конвертирует сложные PDF в чистый, валидный Markdown с таблицами GFM и математикой KaTeX.

  1. 01

    1. Загрузка PDF статьи или документации

    Загрузите файл публикации с arXiv, IEEE или техническое описание протокола через веб-интерфейс или REST API.

  2. 02

    2. Структурный Layout-анализ

    Нейросеть распознает многоуровневые заголовки, математические матрицы, формулы в LaTeX, двухколоночный текст и таблицы.

  3. 03

    3. Прямая подача в Claude Code / Cursor / RAG

    Поместите сгенерированный файл .md в репозиторий проекта или векторную базу данных (Chroma, Qdrant, Milvus) для точного контекстного поиска без галлюцинаций.

Исходный PDF

Структурированный Markdown

Provided proper attribution is provided, Google hereby grants permission to reproduce the tables and figures in this paper solely for use in journalistic or scholarly works.

Attention Is All You Need

\textbf{Ashish Vaswani}^{*} Google Brain avaswani@google.com

\textbf{Llion Jones}^{*} Google Research llion@google.com

Noam Shazeer^{*} Google Brain noam@google.com

Aidan N. Gomez^{*} ^{\dagger} University of Toronto aidan@cs.toronto.edu

Niki Parmar^* Google Research nikip@google.com

Łukasz Kaiser* Google Brain lukaszkaiser@google.com

\textbf{Illia Polosukhin}^{*} \ddagger

illia.polosukhin@gmail.com

Jakob Uszkoreit^{\ast} Google Research usz@google.com

Abstract

The dominant sequence transduction models are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.

arXiv:1706.03762v7 [cs.CL] 2 Aug 2023

^{*}Equal contribution. Listing order is random. Jakob proposed replacing RNNs with self-attention and started the effort to evaluate this idea. Ashish, with Illia, designed and implemented the first Transformer models and has been crucially involved in every aspect of this work. Noam proposed scaled dot-product attention, multi-head attention and the parameter-free position representation and became the other person involved in nearly every detail. Niki designed, implemented, tuned and evaluated countless model variants in our original codebase and tensor2tensor. Llion also experimented with novel model variants, was responsible for our initial codebase, and efficient inference and visualizations. Lukasz and Aidan spent countless long days designing various parts of and implementing tensor2tensor, replacing our earlier codebase, greatly improving results and massively accelerating our research.

^{\dagger}Work performed while at Google Brain.

^{\ddagger}Work performed while at Google Research.

1 Introduction

Recurrent neural networks, long short-term memory [13] and gated recurrent [7] 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, 2, 5]. Numerous efforts have since continued to push the boundaries of recurrent language models and encoder-decoder architectures [38, 24, 15].

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 hth_t, as a function of the previous hidden state ht1h_{t-1} and the input for position tt. 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] and conditional computation [32], while also improving model performance in case of the latter. The fundamental constraint of sequential computation, however, remains.

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, 19]. In all but a few cases [27], however, such attention mechanisms are used in conjunction with a recurrent network.

In this work we propose the Transformer, a model architecture eschewing recurrence and instead relying entirely on an attention mechanism to draw global dependencies between input and output. The Transformer allows for significantly more parallelization and can reach a new state of the art in translation quality after being trained for as little as twelve hours on eight P100 GPUs.

2 Background

The goal of reducing sequential computation also forms the foundation of the Extended Neural GPU [16], ByteNet [18] and ConvS2S [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]. 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.

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, 27, 28, 22].

End-to-end memory networks are based on a recurrent attention mechanism instead of sequence-aligned recurrence and have been shown to perform well on simple-language question answering and language modeling tasks [34].

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 sequence-aligned RNNs or convolution. In the following sections, we will describe the Transformer, motivate self-attention and discuss its advantages over models such as [17, 18] and [9].

3 Model Architecture

Most competitive neural sequence transduction models have an encoder-decoder structure [5, 2, 35]. Here, the encoder maps an input sequence of symbol representations (x1,...,xn)(x_1, ..., x_n) to a sequence of continuous representations z=(z1,...,zn)\mathbf{z} = (z_1, ..., z_n). Given z\mathbf{z}, the decoder then generates an output sequence (y1,...,ym)(y_1, ..., y_m) of symbols one element at a time. At each step the model is auto-regressive [10], consuming the previously generated symbols as additional input when generating the next.

Код изображения
<img src="images/3-1.png" style="zoom: 70%; display: block; margin: 0 auto;" />

Figure 1: The Transformer - model architecture.

The Transformer follows this overall architecture using stacked self-attention and point-wise, fully connected layers for both the encoder and decoder, shown in the left and right halves of Figure 1, respectively.

3.1 Encoder and Decoder Stacks

Encoder: The encoder is composed of a stack of N=6N = 6 identical layers. Each layer has two sub-layers. The first is a multi-head self-attention mechanism, and the second is a simple, position-wise fully connected feed-forward network. We employ a residual connection [11] around each of the two sub-layers, followed by layer normalization [1]. That is, the output of each sub-layer is LayerNorm(x+Sublayer(x))\text{LayerNorm}(x + \text{Sublayer}(x)), where Sublayer(x)\text{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=512d_{\text{model}} = 512.

Decoder: The decoder is also composed of a stack of N=6N = 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 ii can depend only on the known outputs at positions less than ii.

3.2 Attention

An 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

Код изображения
<img src="images/4-3.png" style="zoom: 70%; display: block; margin: 0 auto;" />

Figure 2: (left) Scaled Dot-Product Attention. (right) Multi-Head Attention consists of several attention layers running in parallel.

of the values, where the weight assigned to each value is computed by a compatibility function of the query with the corresponding key.

3.2.1 Scaled Dot-Product Attention

We call our particular attention "Scaled Dot-Product Attention" (Figure 2). The input consists of queries and keys of dimension dkd_k, and values of dimension dvd_v. We compute the dot products of the query with all keys, divide each by dk\sqrt{d_k}, and apply a softmax function to obtain the weights on the values.

In practice, we compute the attention function on a set of queries simultaneously, packed together into a matrix QQ. The keys and values are also packed together into matrices KK and VV. We compute the matrix of outputs as:

Attention(Q,K,V)=softmax(QKTdk)V(1)\text{Attention}(Q, K, V) = \text{softmax}(\frac{QK^T}{\sqrt{d_k}})V \tag{1}

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 1dk\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.

While for small values of dkd_k the two mechanisms perform similarly, additive attention outperforms dot product attention without scaling for larger values of dkd_k [3]. We suspect that for large values of dkd_k, the dot products grow large in magnitude, pushing the softmax function into regions where it has extremely small gradients 4^4. To counteract this effect, we scale the dot products by 1dk\frac{1}{\sqrt{d_k}}.

3.2.2 Multi-Head Attention

Instead of performing a single attention function with dmodeld_{\text{model}}-dimensional keys, values and queries, we found it beneficial to linearly project the queries, keys and values hh times with different, learned linear projections to dkd_k, dkd_k and dvd_v dimensions, respectively. On each of these projected versions of queries, keys and values we then perform the attention function in parallel, yielding dvd_v-dimensional

4^4To illustrate why the dot products get large, assume that the components of qq and kk are independent random variables with mean 0 and variance 1. Then their dot product, qk=i=1dkqikiq \cdot k = \sum_{i=1}^{d_k} q_i k_i, has mean 0 and variance dkd_k.

Почему pypdf, pdfminer и стандартные парсеры ломают RAG-пайплайны

Разработчики RAG-систем (Retrieval-Augmented Generation) и пользователи современных CLI-ассистентов (Claude Code, Cursor, Aider, Windsurf) регулярно сталкиваются с деградацией качества ответов модели при попытке передать ей сложный научный PDF.

Типовые проблемы классических библиотек извлечения текста (pypdf, pdfminer, PyMuPDF): 1. Потеря пространственного контекста: в двухколоночных статьях строки из левой и правой колонок склеиваются горизонтально, и LLM путает постановку задачи с выводами. 2. Искажение математических формул и индексов: греческие буквы ($mu, Omega, pi$) и степени ($10^6$) превращаются в пробелы или битые байты UTF-8. Модель генерирует код с грубейшими ошибками в формулах. 3. Разрушение структуры таблиц: таблицы с метриками (BLEU, точность, задержка) перемешиваются между строками, полностью сбивая семантический контекст эмбеддингов.

Преимущества чистого Markdown для семантического чанкинга и эмбеддингов

Когда на входе векторной базы данных (Qdrant, Chroma, PGvector) находится структурированный Markdown, качество поиска и генерации ответов возрастает на порядок: 1. Семантический чанкинг по заголовкам: заголовки H1, H2, H3 сохраняют строгую иерархию документа, позволяя алгоритму резать текст на логически завершенные блоки без разрыва разделов. 2. Валидные таблицы GFM: строковые таблицы в синтаксисе Markdown передают зависимости между колонками целиком, сохраняя контекст для поиска по конкретным метрикам. 3. Формулы в синтаксисе LaTeX: строгие математические выражения в синтаксисе $...$ и $$...$$ корректно воспринимаются рассуждающими моделями (DeepSeek-V3/R1, Claude 3.5 Sonnet, GPT-4o) для инженерных расчетов и верификации алгоритмов.

Интеграция в рабочий процесс разработчика и AI-агентов (Claude Code & Cursor)

Как устроен идеальный пайплайн работы с исследовательской статьей в кодовой базе: 1. Быстрый конверт входящей публикации: превратите 15-страничный PDF статьи Transformer в `docs/attention-paper.md`. 2. Контекстная ссылка в коде: используйте `@attention-paper.md` в Cursor или передайте файл агенту Claude Code с промптом: «Реализуй Multi-Head Attention строго в соответствии с формулами в разделе 3.2.2». 3. Безошибочная кодогенерация: агент видит точные размерности матриц ($W_i^Q, W_i^K, W_i^V$) и масштабирующий коэффициент $ rac{1}{sqrt{d_k}}$, генерируя рабочий PyTorch / JAX код с первой попытки.

Сравнение с альтернативами (Docling, LlamaParse, MinerU)

В отличие от тяжелых локальных библиотек, требующих развертывания выделенных GPU-серверов с десятками гигабайт памяти, KolmoPDF предоставляет легкий облачный API и веб-интерфейс с мгновенной обработкой многостраничных документов, гарантируя стабильную работу даже на слабых рабочих машинах разработчиков.

Частые вопросы

Как Claude Code работает с Markdown файлами?

Claude Code читает файлы Markdown нативно в контексте проекта. Достаточно положить сконвертированный .md файл в репозиторий, и агент сможет ссылаться на него через @file или встроенный инструмент поиска.

Поддерживается ли REST API для автоматизации RAG пайплайнов?

Да, KolmoPDF предоставляет REST API для автоматического парсинга входящих PDF-документов прямо в потоке индексации векторных баз данных (ETL-пайплайны).

Как обрабатываются формулы и специальные символы?

Математические уравнения переводятся в стандартный LaTeX, а специальные инженерные символы (микроамперы, омы, градусы) сохраняются в UTF-8 или математическом синтаксисе без потери точности.

Можно ли распарсить скан технической статьи или отчета?

Да, встроенная модель оптического распознавания (OCR) эффективно обрабатывает как цифровые векторные PDF, так и сканированные архивные публикации со сложной графикой и таблицами.