> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pinecone.io/llms.txt
> Use this file to discover all available pages before exploring further.

# CLIP-ViT-B-32-laion2B-s34B-b79K

> It's particularly well-suited for tasks like: - **Zero-Shot Image Classification:** Classify images based on text descriptions without further training.

export const ModelPageTabs = ({inferenceEnabled}) => {
  const showGuides = () => {
    document.querySelector('.model-page-guides').style.display = 'flex';
    document.querySelector('.model-page-playground').style.display = 'none';
    document.querySelector('.guides').classList.add('active');
    document.querySelector('.playground').classList.remove('active');
  };
  const showPlayground = () => {
    document.querySelector('.model-page-guides').style.display = 'none';
    document.querySelector('.model-page-playground').style.display = 'block';
    document.querySelector('.guides').classList.remove('active');
    document.querySelector('.playground').classList.add('active');
  };
  return <div className="model-page-body">
        <div className="model-page-tabs">
          <button className={`guides active ${inferenceEnabled ? "" : "cursor-default"}`} onClick={inferenceEnabled ? showGuides : null}>
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
              <path d="M6.5 16C7.28333 16 8.04583 16.0875 8.7875 16.2625C9.52917 16.4375 10.2667 16.7 11 17.05V7.2C10.3167 6.8 9.59167 6.5 8.825 6.3C8.05833 6.1 7.28333 6 6.5 6C5.9 6 5.30417 6.05833 4.7125 6.175C4.12083 6.29167 3.55 6.46667 3 6.7V16.6C3.58333 16.4 4.1625 16.25 4.7375 16.15C5.3125 16.05 5.9 16 6.5 16ZM13 17.05C13.7333 16.7 14.4708 16.4375 15.2125 16.2625C15.9542 16.0875 16.7167 16 17.5 16C18.1 16 18.6875 16.05 19.2625 16.15C19.8375 16.25 20.4167 16.4 21 16.6V6.7C20.45 6.46667 19.8792 6.29167 19.2875 6.175C18.6958 6.05833 18.1 6 17.5 6C16.7167 6 15.9417 6.1 15.175 6.3C14.4083 6.5 13.6833 6.8 13 7.2V17.05ZM12 20C11.2 19.3667 10.3333 18.875 9.4 18.525C8.46667 18.175 7.5 18 6.5 18C5.8 18 5.1125 18.0917 4.4375 18.275C3.7625 18.4583 3.11667 18.7167 2.5 19.05C2.15 19.2333 1.8125 19.225 1.4875 19.025C1.1625 18.825 1 18.5333 1 18.15V6.1C1 5.91667 1.04583 5.74167 1.1375 5.575C1.22917 5.40833 1.36667 5.28333 1.55 5.2C2.31667 4.8 3.11667 4.5 3.95 4.3C4.78333 4.1 5.63333 4 6.5 4C7.46667 4 8.4125 4.125 9.3375 4.375C10.2625 4.625 11.15 5 12 5.5C12.85 5 13.7375 4.625 14.6625 4.375C15.5875 4.125 16.5333 4 17.5 4C18.3667 4 19.2167 4.1 20.05 4.3C20.8833 4.5 21.6833 4.8 22.45 5.2C22.6333 5.28333 22.7708 5.40833 22.8625 5.575C22.9542 5.74167 23 5.91667 23 6.1V18.15C23 18.5333 22.8375 18.825 22.5125 19.025C22.1875 19.225 21.85 19.2333 21.5 19.05C20.8833 18.7167 20.2375 18.4583 19.5625 18.275C18.8875 18.0917 18.2 18 17.5 18C16.5 18 15.5333 18.175 14.6 18.525C13.6667 18.875 12.8 19.3667 12 20Z" fill="#1B17F5" />
            </svg>
            GUIDE
          </button>
          {false && <button className="playground" onClick={showPlayground}>
            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
              <path d="M10 16.5L16 12L10 7.5V16.5ZM12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM12 20C7.59 20 4 16.41 4 12C4 7.59 7.59 4 12 4C16.41 4 20 7.59 20 12C20 16.41 16.41 20 12 20Z" fill="#72788D" />
            </svg>
            PLAYGROUND
          </button>}
        </div>
      </div>;
};

export const ModelPageCard = ({image, title, company, inferenceEnabled, metric, dimension, seq, task, price}) => {
  return <div className="model-page-card">
        <div className="model-page-card-title">
          {image && image !== "null" && <div className="model-page-card-logo">
              <img src={image} className="pointer-events-none" />
            </div>}

        <h1><span className="font-semibold">{title}</span> {company !== "null" && "| " + company}</h1>

        {inferenceEnabled === "true" && <div className="model-page-card-inference">
            <svg className="shrink-0" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
              <path d="M11.9995 2.01953C6.48953 2.01953 2.01953 6.48953 2.01953 11.9995C2.01953 17.5095 6.48953 21.9795 11.9995 21.9795C17.5095 21.9795 21.9795 17.5095 21.9795 11.9995C21.9795 6.48953 17.5095 2.01953 11.9995 2.01953ZM11.9995 19.9795C7.59953 19.9795 4.01953 16.3995 4.01953 11.9995C4.01953 7.59953 7.59953 4.01953 11.9995 4.01953C16.3995 4.01953 19.9795 7.59953 19.9795 11.9995C19.9795 16.3995 16.3995 19.9795 11.9995 19.9795ZM12.7495 4.99953L8.24953 13.4995H11.3895V18.9995L15.7495 10.4995H12.7495V4.99953Z" fill="var(--text-primary)" />
            </svg>
            Hosted
          </div>}
        </div>

        <div className="model-page-card-stats">
          {!!metric && metric.length > 0 && <div>
            <span>METRIC</span>
            <p>{metric.join(", ")}</p>
          </div>}

          {!!dimension && dimension.length > 0 && <div>
            <span>DIMENSION</span>
            <p>{dimension.join(", ")}</p>
          </div>}

          {!!seq && seq.length > 0 && <div>
            <span>MAX INPUT TOKENS</span>
            <p>{seq}</p>
          </div>}

          {!!task && task.length > 0 && <div>
            <span>TASK</span>
            <p>{task}</p>
          </div>}

          {price && price.length > 0 && <div className="price">
            <span>PRICE</span>
            <p>${price}</p>
          </div>}
        </div>
      </div>;
};

export const ModelPageHeader = () => {
  return <div style={{
    marginBottom: "2.1875rem"
  }}>
      <a href="/models" style={{
    display: "inline-flex",
    gap: "0.5rem",
    alignItems: "center",
    color: "#121142"
  }}>
        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" style={{
    flexShrink: 0
  }}>
          <path d="M10.4703 4.94L9.53027 4L5.53027 8L9.53027 12L10.4703 11.06L7.41694 8L10.4703 4.94Z" fill="var(--brand-blue)" />
        </svg>
        Back to all models
      </a>
    </div>;
};

<div className="not-prose">
  <ModelPageHeader />

  <ModelPageCard image="https://cdn.sanity.io/images/vr8gru94/production/b2321891279aa398768300b9d5da615779fd492d-1466x1507.svg" title="CLIP-ViT-B-32-laion2B-s34B-b79K" company="Laion" inferenceEnabled="false" metric={["cosine"]} dimension={["512"]} seq="" task="embedding" price="" />

  <ModelPageTabs inferenceEnabled="false" />
</div>

<div className="model-page-guides">
  <div className="model-page-content">
    ### Overview

    Excels at understanding relationships between text and images. Its training set is the English subset of Laion-5B (Laion2B-en). It's particularly well-suited for tasks like:

    * **Zero-Shot Image Classification:** Classify images based on text descriptions without further training.
    * **Image-Text Retrieval:** Search for similar images or text descriptions within a dataset.
    * **Image Segmentation:** Identify and segment different objects within an image based on their semantic meaning.

    **Key benefits for developers:**

    * **Open-source and accessible:** Train and fine-tune the model for your specific needs.

    * **Great performance:** Can achieve high accuracy on various text-image tasks.

    * **Versatile:** Applicable to diverse applications, from image search to image generation.

    ### Using the model

    For best results, use a Jupyter Notebook to interact with this dataset.

    #### Installation:

    ```python theme={null}
    !pip install pinecone datasets transformers
    ```

    ### Create Index

    ```python theme={null}
    from pinecone import Pinecone, ServerlessSpec

    pc = Pinecone(api_key="API_KEY")

    # Create Index
    index_name = "clip-vit-b-32-laion2b-s34b-b79k"

    if not pc.has_index(index_name):
      pc.create_index(
          name=index_name,
          dimension=768,
          metric="cosine",
          spec=ServerlessSpec(
              cloud='aws',
              region='us-east-1'
          )
      )

    index = pc.Index(index_name)
    ```

    ### Embed & Upsert

    ```python theme={null}

    # Embed data
    # We'll use an example dataset of images of animals and cities:

    from datasets import load_dataset

    data = load_dataset(
        "jamescalam/image-text-demo",
        split="train"
    )

    from transformers import CLIPProcessor, CLIPVisionModel
    import torch

    model_id = "laion/CLIP-ViT-B-32-laion2B-s34B-b79K"

    processor = CLIPProcessor.from_pretrained(model_id)
    model = CLIPVisionModel.from_pretrained(model_id)

    # move model to device if possible
    device = 'cuda' if torch.cuda.is_available() else 'cpu'
    model.to(device)


    ### ClIP allows for both text and image embeddings
    import torch

    def create_image_embeddings(image):
      with torch.no_grad():
        vals = processor(
            text=None,
            images=image,
            return_tensors='pt').to(device)
        image_embedding = model(**vals).pooler_output
      return image_embedding[0]


    # We can embed the images and search with them too!

    from IPython.display import Image 

    def apply_vectorization(data):

      data["image_embeddings"] = create_image_embeddings(data["image"])
      return data


    data = data.map(apply_vectorization)
    ids = [str(i) for i in range(0, data.num_rows)]
    data = data.add_column("id", ids)



    vectors = []
    for i in range(0, data.num_rows):
      d = data[i]
      vectors.append({
          "id": d["id"],
          "values": d["image_embeddings"],
          "metadata": {"caption": d["text"]}
      })

    index.upsert(
        vectors=vectors,
        namespace="ns1"
    )


    ```

    ### Query

    ```python theme={null}


    def id_to_image_helper(id, data):
      # given id, renders the images and captions
      # resizes in order to speed up showing the image

      image = data[int(id)]
      print(image["text"])
      return image["image"].resize((500, 500))


    # we choose the first image, which is a city

    query = data[int(1)]["image"]

    x = create_image_embeddings(query).tolist()

    results = index.query(
        namespace="ns1",
        vector=x,
        top_k=3,
        include_values=False,
        include_metadata=True
    )

    print(results)

    #view the results visually
    id_to_image_helper(results["matches"][0]["id"], data)


    ```
  </div>

  <div className="model-page-sidebar">
    <div className="iframe-placeholder">
      <iframe className="" src="https://www.pinecone.io/tools/index-creation/?indexName=CLIP-ViT-B-32-laion2B-s34B-b79K&metrics=cosine&dimensions=512&cloud=aws&region=us-east-1" width="100%" height="1000px" allow="clipboard-write allow-popups" allowTransparency="true" />
    </div>
  </div>
</div>

<div className="model-page-playground not-prose">
  Lorem Ipsum
</div>
