Instructions to use Vydiant/mesh-pipeline with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Vydiant/mesh-pipeline with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Vydiant/mesh-pipeline")# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("Vydiant/mesh-pipeline") model = AutoModel.from_pretrained("Vydiant/mesh-pipeline", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Dennis Minn commited on
Commit ·
67bbd8f
1
Parent(s): 49955eb
added pretrained pipeline
Browse files- config.json +44 -0
- mesh_embeddings.pt +3 -0
- mesh_pipeline.py +44 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +22 -0
- vocab.txt +0 -0
config.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "DennisOneHealth/mesh-encoder",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"BertModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"custom_pipelines": {
|
| 9 |
+
"disease-normalization": {
|
| 10 |
+
"default": {
|
| 11 |
+
"model": {
|
| 12 |
+
"pt": [
|
| 13 |
+
"DennisOneHealth/mesh-encoder",
|
| 14 |
+
"166966f"
|
| 15 |
+
]
|
| 16 |
+
}
|
| 17 |
+
},
|
| 18 |
+
"impl": "mesh_pipeline.MeshPipeline",
|
| 19 |
+
"pt": [
|
| 20 |
+
"AutoModelForSequenceClassification"
|
| 21 |
+
],
|
| 22 |
+
"tf": [],
|
| 23 |
+
"type": "text"
|
| 24 |
+
}
|
| 25 |
+
},
|
| 26 |
+
"gradient_checkpointing": false,
|
| 27 |
+
"hidden_act": "gelu",
|
| 28 |
+
"hidden_dropout_prob": 0.1,
|
| 29 |
+
"hidden_size": 768,
|
| 30 |
+
"initializer_range": 0.02,
|
| 31 |
+
"intermediate_size": 3072,
|
| 32 |
+
"layer_norm_eps": 1e-12,
|
| 33 |
+
"max_position_embeddings": 512,
|
| 34 |
+
"model_type": "bert",
|
| 35 |
+
"num_attention_heads": 12,
|
| 36 |
+
"num_hidden_layers": 12,
|
| 37 |
+
"pad_token_id": 0,
|
| 38 |
+
"position_embedding_type": "absolute",
|
| 39 |
+
"torch_dtype": "float32",
|
| 40 |
+
"transformers_version": "4.33.3",
|
| 41 |
+
"type_vocab_size": 2,
|
| 42 |
+
"use_cache": true,
|
| 43 |
+
"vocab_size": 28998
|
| 44 |
+
}
|
mesh_embeddings.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a4b0571afbed3415179ff6a86544e0db088289ae3b4ef28269527b4efd1862d
|
| 3 |
+
size 26902763
|
mesh_pipeline.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import Pipeline
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class MeshPipeline(Pipeline):
|
| 6 |
+
def __init__(self, *args, **kwargs):
|
| 7 |
+
super().__init__(*args, **kwargs)
|
| 8 |
+
mesh_ordered_dictionary = torch.load('./mesh_embeddings.pt')
|
| 9 |
+
|
| 10 |
+
mesh_records = mesh_ordered_dictionary.keys()
|
| 11 |
+
self.mesh_records = list(mesh_records)
|
| 12 |
+
|
| 13 |
+
mesh_embeddings = mesh_ordered_dictionary.values()
|
| 14 |
+
mesh_embeddings = torch.stack(list(mesh_embeddings), dim=0)
|
| 15 |
+
self.mesh_embeddings = mesh_embeddings
|
| 16 |
+
|
| 17 |
+
def _sanitize_parameters(self, **kwargs):
|
| 18 |
+
preprocess_kwargs = {}
|
| 19 |
+
_forward_kwargs = {}
|
| 20 |
+
postprocess_kwargs = {}
|
| 21 |
+
return preprocess_kwargs, _forward_kwargs, postprocess_kwargs
|
| 22 |
+
|
| 23 |
+
def preprocess(self, annotation):
|
| 24 |
+
text, start, end = annotation.values()
|
| 25 |
+
model_inputs = self.tokenizer(text, return_tensors='pt')
|
| 26 |
+
token_indices = [
|
| 27 |
+
model_inputs.char_to_token(char_idx)
|
| 28 |
+
for char_idx in range(start, end)
|
| 29 |
+
if model_inputs.char_to_token(char_idx) is not None
|
| 30 |
+
]
|
| 31 |
+
model_inputs['token_type_ids'][0, token_indices] = 1
|
| 32 |
+
|
| 33 |
+
return model_inputs
|
| 34 |
+
|
| 35 |
+
def _forward(self, model_inputs):
|
| 36 |
+
return self.model(**model_inputs)
|
| 37 |
+
|
| 38 |
+
def postprocess(self, model_outputs):
|
| 39 |
+
text_embeddings = model_outputs.last_hidden_state[:, 0, :]
|
| 40 |
+
mesh_embeddings = self.mesh_embeddings.to(text_embeddings.device)
|
| 41 |
+
scores = text_embeddings.matmul(mesh_embeddings.T)
|
| 42 |
+
labels = torch.argmax(scores, dim=1)
|
| 43 |
+
labels = [self.mesh_records[label] for label in labels]
|
| 44 |
+
return {'labels': labels, 'scores': scores}
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:25aa68a3276a2cd7c4a6990f1d659984d1e84a7a5d9e19730d2b9237746c7407
|
| 3 |
+
size 433312179
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"clean_up_tokenization_spaces": true,
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_basic_tokenize": true,
|
| 5 |
+
"do_lower_case": false,
|
| 6 |
+
"mask_token": "[MASK]",
|
| 7 |
+
"max_length": 200,
|
| 8 |
+
"model_max_length": 512,
|
| 9 |
+
"never_split": null,
|
| 10 |
+
"pad_to_multiple_of": null,
|
| 11 |
+
"pad_token": "[PAD]",
|
| 12 |
+
"pad_token_type_id": 0,
|
| 13 |
+
"padding_side": "right",
|
| 14 |
+
"sep_token": "[SEP]",
|
| 15 |
+
"stride": 0,
|
| 16 |
+
"strip_accents": null,
|
| 17 |
+
"tokenize_chinese_chars": true,
|
| 18 |
+
"tokenizer_class": "BertTokenizer",
|
| 19 |
+
"truncation_side": "right",
|
| 20 |
+
"truncation_strategy": "longest_first",
|
| 21 |
+
"unk_token": "[UNK]"
|
| 22 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|