Feature Extraction
Transformers
Safetensors
Italian
radgraph_it
radiology
information-extraction
named-entity-recognition
relation-extraction
medical
radgraph
custom_code
Instructions to use radgraphIT/Radgraph-IT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use radgraphIT/Radgraph-IT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="radgraphIT/Radgraph-IT", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("radgraphIT/Radgraph-IT", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 1,078 Bytes
0c48771 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | """Mention pruner: score every span, keep the top-k, in original span order.
Port of `radgraph.dygie.models.entity_beam_pruner.Pruner`'s default path (no entity_beam, no
gold_beam -- this project's relation module never sets either, see relation_head.py).
Simplified for batch_size=1: no masking, no batch dimension.
"""
from typing import Tuple
import torch
from torch import nn
class Pruner(nn.Module):
def __init__(self, scorer: nn.Module):
super().__init__()
self.scorer = scorer # (num_spans, dim) -> (num_spans, 1)
def forward(self, span_embeddings: torch.Tensor, num_items_to_keep: int
) -> Tuple[torch.Tensor, torch.LongTensor, torch.Tensor]:
scores = self.scorer(span_embeddings).squeeze(-1) # (num_spans,)
k = max(1, min(num_items_to_keep, span_embeddings.size(0)))
_, top_indices = scores.topk(k)
top_indices, _ = torch.sort(top_indices)
top_scores = scores[top_indices]
top_embeddings = span_embeddings[top_indices]
return top_embeddings, top_indices, top_scores
|