|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "bda1f3f5", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Arxiv\n", |
| 9 | + "\n", |
| 10 | + "[arXiv](https://arxiv.org/) is an open-access archive for 2 million scholarly articles in the fields of physics, mathematics, computer science, quantitative biology, quantitative finance, statistics, electrical engineering and systems science, and economics.\n", |
| 11 | + "\n", |
| 12 | + "This notebook shows how to load scientific articles from `Arxiv.org` into a document format that we can use downstream." |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "markdown", |
| 17 | + "id": "1b7a1eef-7bf7-4e7d-8bfc-c4e27c9488cb", |
| 18 | + "metadata": {}, |
| 19 | + "source": [ |
| 20 | + "## Installation" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "markdown", |
| 25 | + "id": "2abd5578-aa3d-46b9-99af-8b262f0b3df8", |
| 26 | + "metadata": {}, |
| 27 | + "source": [ |
| 28 | + "First, you need to install `arxiv` python package." |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": null, |
| 34 | + "id": "b674aaea-ed3a-4541-8414-260a8f67f623", |
| 35 | + "metadata": { |
| 36 | + "tags": [] |
| 37 | + }, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "!pip install arxiv" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "markdown", |
| 45 | + "id": "094b5f13-7e54-4354-9d83-26d6926ecaa0", |
| 46 | + "metadata": { |
| 47 | + "tags": [] |
| 48 | + }, |
| 49 | + "source": [ |
| 50 | + "Second, you need to install `PyMuPDF` python package which transform PDF files from the `arxiv.org` site into the text fromat." |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": null, |
| 56 | + "id": "7cd91121-2e96-43ba-af50-319853695f86", |
| 57 | + "metadata": { |
| 58 | + "tags": [] |
| 59 | + }, |
| 60 | + "outputs": [], |
| 61 | + "source": [ |
| 62 | + "!pip install pymupdf" |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "markdown", |
| 67 | + "id": "95f05e1c-195e-4e2b-ae8e-8d6637f15be6", |
| 68 | + "metadata": {}, |
| 69 | + "source": [ |
| 70 | + "## Examples" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "markdown", |
| 75 | + "id": "e29b954c-1407-4797-ae21-6ba8937156be", |
| 76 | + "metadata": {}, |
| 77 | + "source": [ |
| 78 | + "`ArxivLoader` has these arguments:\n", |
| 79 | + "- `query`: free text which used to find documents in the Arxiv\n", |
| 80 | + "- optional `load_max_docs`: default=100. Use it to limit number of downloaded documents. It takes time to download all 100 documents, so use a small number for experiments.\n", |
| 81 | + "- optional `load_all_available_meta`: default=False. By defaul only the most important fields downloaded: `Published` (date when document was published/last updated), `Title`, `Authors`, `Summary`. If True, other fields also downloaded." |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "code", |
| 86 | + "execution_count": null, |
| 87 | + "id": "9bfd5e46", |
| 88 | + "metadata": {}, |
| 89 | + "outputs": [], |
| 90 | + "source": [ |
| 91 | + "from langchain.document_loaders.base import Document\n", |
| 92 | + "from langchain.document_loaders import ArxivLoader" |
| 93 | + ] |
| 94 | + }, |
| 95 | + { |
| 96 | + "cell_type": "code", |
| 97 | + "execution_count": null, |
| 98 | + "id": "700e4ef2", |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [], |
| 101 | + "source": [ |
| 102 | + "docs = ArxivLoader(query=\"1605.08386\", load_max_docs=2).load()\n", |
| 103 | + "len(docs)" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "code", |
| 108 | + "execution_count": 2, |
| 109 | + "id": "8977bac0-0042-4f23-9754-247dbd32439b", |
| 110 | + "metadata": { |
| 111 | + "tags": [] |
| 112 | + }, |
| 113 | + "outputs": [ |
| 114 | + { |
| 115 | + "data": { |
| 116 | + "text/plain": [ |
| 117 | + "{'Published': '2016-05-26',\n", |
| 118 | + " 'Title': 'Heat-bath random walks with Markov bases',\n", |
| 119 | + " 'Authors': 'Caprice Stanley, Tobias Windisch',\n", |
| 120 | + " 'Summary': 'Graphs on lattice points are studied whose edges come from a finite set of\\nallowed moves of arbitrary length. We show that the diameter of these graphs on\\nfibers of a fixed integer matrix can be bounded from above by a constant. We\\nthen study the mixing behaviour of heat-bath random walks on these graphs. We\\nalso state explicit conditions on the set of moves so that the heat-bath random\\nwalk, a generalization of the Glauber dynamics, is an expander in fixed\\ndimension.'}" |
| 121 | + ] |
| 122 | + }, |
| 123 | + "execution_count": 2, |
| 124 | + "metadata": {}, |
| 125 | + "output_type": "execute_result" |
| 126 | + } |
| 127 | + ], |
| 128 | + "source": [ |
| 129 | + "doc[0].metadata # meta-information of the Document" |
| 130 | + ] |
| 131 | + }, |
| 132 | + { |
| 133 | + "cell_type": "code", |
| 134 | + "execution_count": 5, |
| 135 | + "id": "46969806-45a9-4c4d-a61b-cfb9658fc9de", |
| 136 | + "metadata": { |
| 137 | + "tags": [] |
| 138 | + }, |
| 139 | + "outputs": [ |
| 140 | + { |
| 141 | + "data": { |
| 142 | + "text/plain": [ |
| 143 | + "'arXiv:1605.08386v1 [math.CO] 26 May 2016\\nHEAT-BATH RANDOM WALKS WITH MARKOV BASES\\nCAPRICE STANLEY AND TOBIAS WINDISCH\\nAbstract. Graphs on lattice points are studied whose edges come from a finite set of\\nallowed moves of arbitrary length. We show that the diameter of these graphs on fibers of a\\nfixed integer matrix can be bounded from above by a constant. We then study the mixing\\nbehaviour of heat-b'" |
| 144 | + ] |
| 145 | + }, |
| 146 | + "execution_count": 5, |
| 147 | + "metadata": {}, |
| 148 | + "output_type": "execute_result" |
| 149 | + } |
| 150 | + ], |
| 151 | + "source": [ |
| 152 | + "doc[0].page_content[:400] # all pages of the Document content\n" |
| 153 | + ] |
| 154 | + } |
| 155 | + ], |
| 156 | + "metadata": { |
| 157 | + "kernelspec": { |
| 158 | + "display_name": "Python 3 (ipykernel)", |
| 159 | + "language": "python", |
| 160 | + "name": "python3" |
| 161 | + }, |
| 162 | + "language_info": { |
| 163 | + "codemirror_mode": { |
| 164 | + "name": "ipython", |
| 165 | + "version": 3 |
| 166 | + }, |
| 167 | + "file_extension": ".py", |
| 168 | + "mimetype": "text/x-python", |
| 169 | + "name": "python", |
| 170 | + "nbconvert_exporter": "python", |
| 171 | + "pygments_lexer": "ipython3", |
| 172 | + "version": "3.10.6" |
| 173 | + } |
| 174 | + }, |
| 175 | + "nbformat": 4, |
| 176 | + "nbformat_minor": 5 |
| 177 | +} |
0 commit comments