Buckets:

hf-doc-build/doc-dev / transformers /pr_37396 /en /tasks /visual_document_retrieval.html
rtrm's picture
download
raw
26.1 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Visual document retrieval&quot;,&quot;local&quot;:&quot;visual-document-retrieval&quot;,&quot;sections&quot;:[],&quot;depth&quot;:1}">
<link href="/docs/transformers/pr_37396/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/entry/start.3e00b6da.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/scheduler.18a86fab.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/singletons.240f24f3.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/index.40ab8126.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/paths.2edea311.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/entry/app.e7a7eda8.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/index.98837b22.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/nodes/0.78534817.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/nodes/499.5ef318a6.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/Tip.77304350.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/CodeBlock.8d0c2e8a.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/Heading.7e7e0c5b.js">
<link rel="modulepreload" href="/docs/transformers/pr_37396/en/_app/immutable/chunks/index.f01015d9.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Visual document retrieval&quot;,&quot;local&quot;:&quot;visual-document-retrieval&quot;,&quot;sections&quot;:[],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="visual-document-retrieval" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#visual-document-retrieval"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Visual document retrieval</span></h1> <p data-svelte-h="svelte-10qzjz4">Documents can contain multimodal data if they include charts, tables, and visuals in addition to text. Retrieving information from these documents is challenging because text retrieval models alone can’t handle visual data and image retrieval models lack the granularity and document processing capabilities.</p> <p data-svelte-h="svelte-1t9gk3d">Visual document retrieval can help retrieve information from all types of documents, including multimodal retrieval augmented generation (RAG). These models accept documents (as images) and texts and calculates the similarity scores between them.</p> <p data-svelte-h="svelte-xgcmqq">This guide demonstrates how to index and retrieve documents with <a href="../model_doc/colpali">ColPali</a>.</p> <div class="course-tip bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400"><p data-svelte-h="svelte-1ty4hkx">For large scale use cases, you may want to index and retrieve documents with a vector database.</p></div> <p data-svelte-h="svelte-fb0qzh">Make sure Transformers and Datasets is installed.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->pip install -q datasets transformers<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1vp4ogz">We will index a dataset of documents related to UFO sightings. We filter the examples where our column of interest is missing. It contains several columns, we are interested in the column <code>specific_detail_query</code> where it contains short summary of the document, and <code>image</code> column that contains our documents.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
dataset = load_dataset(<span class="hljs-string">&quot;davanstrien/ufo-ColPali&quot;</span>)
dataset = dataset[<span class="hljs-string">&quot;train&quot;</span>]
dataset = dataset.<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> example: example[<span class="hljs-string">&quot;specific_detail_query&quot;</span>] <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>)
dataset<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-title function_ invoke__">Dataset</span>({
<span class="hljs-attr">features</span>: [<span class="hljs-string">&#x27;image&#x27;</span>, <span class="hljs-string">&#x27;raw_queries&#x27;</span>, <span class="hljs-string">&#x27;broad_topical_query&#x27;</span>, <span class="hljs-string">&#x27;broad_topical_explanation&#x27;</span>, <span class="hljs-string">&#x27;specific_detail_query&#x27;</span>, <span class="hljs-string">&#x27;specific_detail_explanation&#x27;</span>, <span class="hljs-string">&#x27;visual_element_query&#x27;</span>, <span class="hljs-string">&#x27;visual_element_explanation&#x27;</span>, <span class="hljs-string">&#x27;parsed_into_json&#x27;</span>],
<span class="hljs-attr">num_rows</span>: <span class="hljs-number">2172</span>
})<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1sbq1d0">Let’s load the model and the tokenizer.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> ColPaliForRetrieval, ColPaliProcessor
model_name = <span class="hljs-string">&quot;vidore/colpali-v1.2-hf&quot;</span>
processor = ColPaliProcessor.from_pretrained(model_name)
model = ColPaliForRetrieval.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map=<span class="hljs-string">&quot;cuda&quot;</span>,
).<span class="hljs-built_in">eval</span>()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-xrdu44">Pass the text query to the processor and return the indexed text embeddings from the model. For image-to-text search, replace the <code>text</code> parameter in <a href="/docs/transformers/pr_37396/en/model_doc/colpali#transformers.ColPaliProcessor">ColPaliProcessor</a> with the <code>images</code> parameter to pass images.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->inputs = processor(text=<span class="hljs-string">&quot;a document about Mars expedition&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)
<span class="hljs-keyword">with</span> torch.no_grad():
text_embeds = model(**inputs, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).embeddings<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-r0q688">Index the images offline, and during inference, return the query text embeddings to get its closest image embeddings.</p> <p data-svelte-h="svelte-anvmq7">Store the image and image embeddings by writing them to the dataset with <a href="https://huggingface.co/docs/datasets/main/en/package_reference/main_classes#datasets.Dataset.map" rel="nofollow">map</a> as shown below. Add an <code>embeddings</code> column that contains the indexed embeddings. ColPali embeddings take up a lot of storage, so remove them from the GPU and store them in the CPU as NumPy vectors.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->ds_with_embeddings = dataset.<span class="hljs-built_in">map</span>(<span class="hljs-keyword">lambda</span> example: {<span class="hljs-string">&#x27;embeddings&#x27;</span>: model(**processor(images=example[<span class="hljs-string">&quot;image&quot;</span>]).to(<span class="hljs-string">&quot;cuda&quot;</span>), return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).embeddings.to(torch.float32).detach().cpu().numpy()})<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-s8v7ww">For online inference, create a function to search the image embeddings in batches and retrieve the k-most relevant images. The function below returns the indices in the dataset and their scores for a given indexed dataset, text embeddings, number of top results, and the batch size.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">def</span> <span class="hljs-title function_">find_top_k_indices_batched</span>(<span class="hljs-params">dataset, text_embedding, processor, k=<span class="hljs-number">10</span>, batch_size=<span class="hljs-number">4</span></span>):
scores_and_indices = []
<span class="hljs-keyword">for</span> start_idx <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-built_in">len</span>(dataset), batch_size):
end_idx = <span class="hljs-built_in">min</span>(start_idx + batch_size, <span class="hljs-built_in">len</span>(dataset))
batch = dataset[start_idx:end_idx]
batch_embeddings = [torch.tensor(emb[<span class="hljs-number">0</span>], dtype=torch.float32) <span class="hljs-keyword">for</span> emb <span class="hljs-keyword">in</span> batch[<span class="hljs-string">&quot;embeddings&quot;</span>]]
scores = processor.score_retrieval(text_embedding.to(<span class="hljs-string">&quot;cpu&quot;</span>).to(torch.float32), batch_embeddings)
<span class="hljs-keyword">if</span> <span class="hljs-built_in">hasattr</span>(scores, <span class="hljs-string">&quot;tolist&quot;</span>):
scores = scores.tolist()[<span class="hljs-number">0</span>]
<span class="hljs-keyword">for</span> i, score <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(scores):
scores_and_indices.append((score, start_idx + i))
sorted_results = <span class="hljs-built_in">sorted</span>(scores_and_indices, key=<span class="hljs-keyword">lambda</span> x: -x[<span class="hljs-number">0</span>])
topk = sorted_results[:k]
indices = [idx <span class="hljs-keyword">for</span> _, idx <span class="hljs-keyword">in</span> topk]
scores = [score <span class="hljs-keyword">for</span> score, _ <span class="hljs-keyword">in</span> topk]
<span class="hljs-keyword">return</span> indices, scores<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-dr294z">Generate the text embeddings and pass them to the function above to return the dataset indices and scores.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">with</span> torch.no_grad():
text_embeds = model(**processor(text=<span class="hljs-string">&quot;a document about Mars expedition&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>), return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).embeddings
indices, scores = find_top_k_indices_batched(ds_with_embeddings, text_embeds, processor, k=<span class="hljs-number">3</span>, batch_size=<span class="hljs-number">4</span>)
<span class="hljs-built_in">print</span>(indices, scores)<!-- HTML_TAG_END --></pre></div> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->([<span class="hljs-name">440</span>, <span class="hljs-number">442</span>, <span class="hljs-number">443</span>],
[<span class="hljs-name">14.370786666870117</span>,
<span class="hljs-number">13.675487518310547</span>,
<span class="hljs-number">12.9899320602417</span>])<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-sfwoi">Display the images to view the Mars related documents.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> indices:
display(dataset[i][<span class="hljs-string">&quot;image&quot;</span>])<!-- HTML_TAG_END --></pre></div> <div style="display: flex; align-items: center;" data-svelte-h="svelte-11pj4z2"><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/doc_1.png" alt="Document 1" style="height: 200px; object-fit: contain; margin-right: 10px;"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/doc_2.png" alt="Document 2" style="height: 200px; object-fit: contain;"> <img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/doc_3.png" alt="Document 3" style="height: 200px; object-fit: contain;"></div> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers/blob/main/docs/source/en/tasks/visual_document_retrieval.md" target="_blank"><span data-svelte-h="svelte-1kd6by1">&lt;</span> <span data-svelte-h="svelte-x0xyl0">&gt;</span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_1s09dg7 = {
assets: "/docs/transformers/pr_37396/en",
base: "/docs/transformers/pr_37396/en",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/transformers/pr_37396/en/_app/immutable/entry/start.3e00b6da.js"),
import("/docs/transformers/pr_37396/en/_app/immutable/entry/app.e7a7eda8.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 499],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
26.1 kB
·
Xet hash:
3c32972c6fc7bc37d2d1e181028ba1c8d9c52bf710748f902c053a6f8786ddb4

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.