Instructions to use microsoft/colipri with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- COLIPRI
How to use microsoft/colipri with COLIPRI:
pip install colipri
from colipri import get_model from colipri import get_processor from colipri import load_sample_ct from colipri import ZeroShotImageClassificationPipeline model = get_model().cuda() processor = get_processor() pipeline = ZeroShotImageClassificationPipeline("microsoft/colipri", processor) image = load_sample_ct() pipeline(image, ["No lung nodules", "Lung nodules"]) - Notebooks
- Google Colab
- Kaggle
Type valid token masks explicitly
Browse filesCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8a255805-976d-4261-b430-561adafb3cc6
- src/colipri/pooling.py +3 -2
- src/colipri/types.py +2 -0
src/colipri/pooling.py
CHANGED
|
@@ -5,12 +5,13 @@ from torch import nn
|
|
| 5 |
from .types import TypePooledEmbeddings
|
| 6 |
from .types import TypeSequenceEmbeddings
|
| 7 |
from .types import TypeTextAttentionMask
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def _get_valid_token_mask(
|
| 11 |
sequence: TypeSequenceEmbeddings,
|
| 12 |
attention_mask: TypeTextAttentionMask | None,
|
| 13 |
-
) ->
|
| 14 |
"""Get a validated Boolean mask for valid sequence positions.
|
| 15 |
|
| 16 |
Args:
|
|
@@ -44,7 +45,7 @@ def _get_valid_token_mask(
|
|
| 44 |
|
| 45 |
def _compute_masked_mean(
|
| 46 |
sequence: TypeSequenceEmbeddings,
|
| 47 |
-
valid_mask:
|
| 48 |
) -> TypePooledEmbeddings:
|
| 49 |
"""Compute the sequence mean while excluding masked positions."""
|
| 50 |
if valid_mask is None:
|
|
|
|
| 5 |
from .types import TypePooledEmbeddings
|
| 6 |
from .types import TypeSequenceEmbeddings
|
| 7 |
from .types import TypeTextAttentionMask
|
| 8 |
+
from .types import TypeValidTokenMask
|
| 9 |
|
| 10 |
|
| 11 |
def _get_valid_token_mask(
|
| 12 |
sequence: TypeSequenceEmbeddings,
|
| 13 |
attention_mask: TypeTextAttentionMask | None,
|
| 14 |
+
) -> TypeValidTokenMask | None:
|
| 15 |
"""Get a validated Boolean mask for valid sequence positions.
|
| 16 |
|
| 17 |
Args:
|
|
|
|
| 45 |
|
| 46 |
def _compute_masked_mean(
|
| 47 |
sequence: TypeSequenceEmbeddings,
|
| 48 |
+
valid_mask: TypeValidTokenMask | None,
|
| 49 |
) -> TypePooledEmbeddings:
|
| 50 |
"""Compute the sequence mean while excluding masked positions."""
|
| 51 |
if valid_mask is None:
|
src/colipri/types.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
from typing import TypeAlias
|
| 3 |
|
| 4 |
import torchio as tio
|
|
|
|
| 5 |
from jaxtyping import Float
|
| 6 |
from jaxtyping import Int64
|
| 7 |
from torch import Tensor
|
|
@@ -25,6 +26,7 @@ TypeImagesTensor: TypeAlias = Float[Tensor, "batch 1 x_in y_in z_in"]
|
|
| 25 |
|
| 26 |
TypeTextTokenIds: TypeAlias = Int64[Tensor, "batch text_length"]
|
| 27 |
TypeTextAttentionMask: TypeAlias = Int64[Tensor, "batch text_length"]
|
|
|
|
| 28 |
|
| 29 |
# Outputs
|
| 30 |
TypeSequenceEmbeddings: TypeAlias = Float[Tensor, "batch sequence_length embed_dim"]
|
|
|
|
| 2 |
from typing import TypeAlias
|
| 3 |
|
| 4 |
import torchio as tio
|
| 5 |
+
from jaxtyping import Bool
|
| 6 |
from jaxtyping import Float
|
| 7 |
from jaxtyping import Int64
|
| 8 |
from torch import Tensor
|
|
|
|
| 26 |
|
| 27 |
TypeTextTokenIds: TypeAlias = Int64[Tensor, "batch text_length"]
|
| 28 |
TypeTextAttentionMask: TypeAlias = Int64[Tensor, "batch text_length"]
|
| 29 |
+
TypeValidTokenMask: TypeAlias = Bool[Tensor, "batch sequence_length"]
|
| 30 |
|
| 31 |
# Outputs
|
| 32 |
TypeSequenceEmbeddings: TypeAlias = Float[Tensor, "batch sequence_length embed_dim"]
|