mirror of
https://github.com/run-llama/llama_cloud_services.git
synced 2026-07-01 21:44:37 -04:00
239 lines
11 KiB
Plaintext
239 lines
11 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"# LlamaParse Usage\n",
|
||
"\n",
|
||
"This notebook walks through the basic usage of LlamaParse.\n",
|
||
"\n",
|
||
"Status:\n",
|
||
"| Last Executed | Version | State |\n",
|
||
"|---------------|---------|------------|\n",
|
||
"| Aug-18-2025 | 0.6.61 | Maintained |"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"> **⚠️ DEPRECATION NOTICE**>> This example uses the deprecated `llama-cloud-services` package, which will be maintained until **May 1, 2026**.>> **Please migrate to:**> - **Python**: `pip install llama-cloud>=1.0` ([GitHub](https://github.com/run-llama/llama-cloud-py))> - **New Package Documentation**: https://docs.cloud.llamaindex.ai/>> The new package provides the same functionality with improved performance and support."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"%pip install \"llama-index>=0.13.2<0.14.0\" llama-cloud-services"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"!wget \"https://arxiv.org/pdf/1706.03762.pdf\" -O \"./attention.pdf\""
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os\n",
|
||
"\n",
|
||
"os.environ[\"LLAMA_CLOUD_API_KEY\"] = \"llx-...\""
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"Started parsing the file under job_id ebc7e76e-addb-429b-8666-bee9c5832a84\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"from llama_cloud_services import LlamaParse\n",
|
||
"\n",
|
||
"result = await LlamaParse(\n",
|
||
" parse_mode=\"parse_page_with_agent\",\n",
|
||
" model=\"openai-gpt-4-1-mini\",\n",
|
||
" high_res_ocr=True,\n",
|
||
" adaptive_long_table=True,\n",
|
||
" outlined_table_extraction=True,\n",
|
||
" output_tables_as_HTML=True,\n",
|
||
").aparse(\"./attention.pdf\")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"1 Introduction\n",
|
||
"\n",
|
||
"Recurrent neural networks, long short-term memory [13] and gated recurrent [7] neural networks\n",
|
||
"in particular, have been firmly established as state of the art approaches in sequence modeling and\n",
|
||
"transduction problems such as language modeling and machine translation [35, 2, 5]. Numerous\n",
|
||
"efforts have since continued to push the boundaries of recurrent language models and encoder-decoder\n",
|
||
"architectures [38, 24, 15].\n",
|
||
"Recurrent models typically factor computation along the symbol positions of the input and output\n",
|
||
"sequences. Aligning the positions to steps in computation time, they generate a sequence of hidden\n",
|
||
"states ht, as a function of the previous hidden state ht−1 and the input for position t. This inherently\n",
|
||
"sequential nature precludes parallelization within training examples, which becomes critical at longer\n",
|
||
"sequence lengths, as memory constraints limit batching across examples. Recent work has achieved\n",
|
||
"significant improvements in computational efficiency through factorization tricks [21] and conditional\n",
|
||
"computation [32], while also improving model performance in case of the latter. The fundamental\n",
|
||
"constraint of sequential computation, however, remains.\n",
|
||
"Attention mechanisms have become an integral part of compelling sequence modeling and transduc-\n",
|
||
"tion models in various tasks, allowing modeling of dependencies without regard to their distance in\n",
|
||
"the input or output sequences [2, 19]. In all but a few cases [27], however, such attention mechanisms\n",
|
||
"are used in conjunction with a recurrent network.\n",
|
||
"In this work we propose the Transformer, a model architecture eschewing recurrence and instead\n",
|
||
"relying entirely on an attention mechanism to draw global dependencies between input and output.\n",
|
||
"The Transformer allows for significantly more parallelization and can reach a new state of the art in\n",
|
||
"translation quality after being trained for as little as twelve hours on eight P100 GPUs.\n",
|
||
"\n",
|
||
"2 Background\n",
|
||
"\n",
|
||
"The goal of reducing sequential computation also forms the foundation of the Extended Neural GPU\n",
|
||
"[16], ByteNet [18] and ConvS2S [9], all of which use convolutional neural networks as basic building\n",
|
||
"block, computing hidden representations in parallel for all input and output positions. In these models,\n",
|
||
"the number of operations required to relate signals from two arbitrary input or output positions grows\n",
|
||
"in the distance between positions, linearly for ConvS2S and logarithmically for ByteNet. This makes\n",
|
||
"it more difficult to learn dependencies between distant positions [12]. In the Transformer this is\n",
|
||
"reduced to a constant number of operations, albeit at the cost of reduced effective resolution due\n",
|
||
"to averaging attention-weighted positions, an effect we counteract with Multi-Head Attention as\n",
|
||
"described in section 3.2.\n",
|
||
"Self-attention, sometimes called intra-attention is an attention mechanism relating different positions\n",
|
||
"of a single sequence in order to compute a representation of the sequence. Self-attention has been\n",
|
||
"used successfully in a variety of tasks including reading comprehension, abstractive summarization,\n",
|
||
"textual entailment and learning task-independent sentence representations [4, 27, 28, 22].\n",
|
||
"End-to-end memory networks are based on a recurrent attention mechanism instead of sequence-\n",
|
||
"aligned recurrence and have been shown to perform well on simple-language question answering and\n",
|
||
"language modeling tasks [34].\n",
|
||
"To the best of our knowledge, however, the Transformer is the first transduction model relying\n",
|
||
"entirely on self-attention to compute representations of its input and output without using sequence-\n",
|
||
"aligned RNNs or convolution. In the following sections, we will describe the Transformer, motivate\n",
|
||
"self-attention and discuss its advantages over models such as [17, 18] and [9].\n",
|
||
"\n",
|
||
"3 Model Architecture\n",
|
||
"\n",
|
||
"Most competitive neural sequence transduction models have an encoder-decoder structure [5, 2, 35].\n",
|
||
"Here, the encoder maps an input sequence of symbol representations (x1, ..., xn) to a sequence\n",
|
||
"of continuous representations z = (z1, ..., zn). Given z, the decoder then generates an output\n",
|
||
"sequence (y1, ..., ym) of symbols one element at a time. At each step the model is auto-regressive\n",
|
||
"[10], consuming the previously generated symbols as additional input when generating the next.\n",
|
||
"\n",
|
||
" 2\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"documents = result.get_text_documents(split_by_page=True)\n",
|
||
"print(documents[1].text)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"\n",
|
||
"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.\n",
|
||
"\n",
|
||
"# Attention Is All You Need\n",
|
||
"\n",
|
||
"**Ashish Vaswani*** \n",
|
||
"Google Brain \n",
|
||
"avaswani@google.com \n",
|
||
"\n",
|
||
"**Noam Shazeer*** \n",
|
||
"Google Brain \n",
|
||
"noam@google.com \n",
|
||
"\n",
|
||
"**Niki Parmar*** \n",
|
||
"Google Research \n",
|
||
"nikip@google.com \n",
|
||
"\n",
|
||
"**Jakob Uszkoreit*** \n",
|
||
"Google Research \n",
|
||
"usz@google.com \n",
|
||
"\n",
|
||
"**Llion Jones*** \n",
|
||
"Google Research \n",
|
||
"llion@google.com \n",
|
||
"\n",
|
||
"**Aidan N. Gomez* †** \n",
|
||
"University of Toronto \n",
|
||
"aidan@cs.toronto.edu \n",
|
||
"\n",
|
||
"**Łukasz Kaiser*** \n",
|
||
"Google Brain \n",
|
||
"lukaszkaiser@google.com \n",
|
||
"\n",
|
||
"**Illia Polosukhin* ‡** \n",
|
||
"illia.polosukhin@gmail.com \n",
|
||
"\n",
|
||
"## Abstract\n",
|
||
"\n",
|
||
"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.\n",
|
||
"\n",
|
||
"----\n",
|
||
"\n",
|
||
"*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. \n",
|
||
"† Work performed while at Google Brain. \n",
|
||
"‡ Work performed while at Google Research.\n",
|
||
"\n",
|
||
"31st Conference on Neural Information Processing Systems (NIPS 2017), Long Beach, CA, USA.\n",
|
||
"\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"documents = result.get_markdown_documents(split_by_page=True)\n",
|
||
"print(documents[0].text)"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": ".venv",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 4
|
||
}
|