Sentence Similarity
sentence-transformers
PyTorch
Transformers
bert
feature-extraction
text-embeddings-inference
Run this model with HF Jobs
Run fogomg/BioBert on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/fogomg/BioBert. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/fogomg/BioBert on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use fogomg/BioBert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use fogomg/BioBert with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("fogomg/BioBert") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Transformers
How to use fogomg/BioBert with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("fogomg/BioBert") model = AutoModel.from_pretrained("fogomg/BioBert", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit ·
b4128fe
1
Parent(s): 0e0d770
Initial Commit
Browse filesFiles changed (13)
- 1_Pooling/config.jsonAdded+7
- README.mdAdded+126
- config.jsonAdded+24
- config_sentence_transformers.jsonAdded+7
- eval/similarity_evaluation_sts-dev_results.csvAdded+5
- modules.jsonAdded+14
- pytorch_model.binAdded+3
- sentence_bert_config.jsonAdded+4
- similarity_evaluation_sts-test_results.csvAdded+2
- special_tokens_map.jsonAdded+1
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+1
- vocab.txtAdded
1234567{ "word_embedding_dimension": 768, "pooling_mode_cls_token": false, "pooling_mode_mean_tokens": true, "pooling_mode_max_tokens": false, "pooling_mode_mean_sqrt_len_tokens": false}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126---pipeline_tag: sentence-similaritytags:- sentence-transformers- feature-extraction- sentence-similarity- transformers---
# {MODEL_NAME}
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
<!--- Describe your model here -->
## Usage (Sentence-Transformers)
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
```pip install -U sentence-transformers```
Then you can use the model like this:
```pythonfrom sentence_transformers import SentenceTransformersentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('{MODEL_NAME}')embeddings = model.encode(sentences)print(embeddings)```
## Usage (HuggingFace Transformers)Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
```pythonfrom transformers import AutoTokenizer, AutoModelimport torch
#Mean Pooling - Take attention mask into account for correct averagingdef mean_pooling(model_output, attention_mask): token_embeddings = model_output[0] #First element of model_output contains all token embeddings input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float() return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
# Sentences we want sentence embeddings forsentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hubtokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')model = AutoModel.from_pretrained('{MODEL_NAME}')
# Tokenize sentencesencoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddingswith torch.no_grad(): model_output = model(**encoded_input)
# Perform pooling. In this case, max pooling.sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")print(sentence_embeddings)```
## Evaluation Results
<!--- Describe how your model was evaluated -->
For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
## TrainingThe model was trained with the parameters:
**DataLoader**:
`torch.utils.data.dataloader.DataLoader` of length 90 with parameters:```{'batch_size': 64, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}```
**Loss**:
`sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss`
Parameters of the fit()-Method:```{ "callback": null, "epochs": 4, "evaluation_steps": 1000, "evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator", "max_grad_norm": 1, "optimizer_class": "<class 'transformers.optimization.AdamW'>", "optimizer_params": { "lr": 2e-05 }, "scheduler": "WarmupLinear", "steps_per_epoch": null, "warmup_steps": 36, "weight_decay": 0.01}```
## Full Model Architecture```SentenceTransformer( (0): Transformer({'max_seq_length': 75, 'do_lower_case': False}) with Transformer model: BertModel (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False}))```
## Citing & Authors
<!--- Describe where people can find more information -->123456789101112131415161718192021222324{ "_name_or_path": "/content/output/biobert_nli/", "architectures": [ "BertModel" ], "attention_probs_dropout_prob": 0.1, "gradient_checkpointing": false, "hidden_act": "gelu", "hidden_dropout_prob": 0.1, "hidden_size": 768, "initializer_range": 0.02, "intermediate_size": 3072, "layer_norm_eps": 1e-12, "max_position_embeddings": 512, "model_type": "bert", "num_attention_heads": 12, "num_hidden_layers": 12, "pad_token_id": 0, "position_embedding_type": "absolute", "transformers_version": "4.8.2", "type_vocab_size": 2, "use_cache": true, "vocab_size": 28996}1234567{ "__version__": { "sentence_transformers": "2.0.0", "transformers": "4.8.2", "pytorch": "1.9.0+cu102" }}12345epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman0,-1,0.8588853124878933,0.857367073884574,0.8489334962620573,0.8533174483140835,0.8479834735468323,0.8520743773038099,0.8330949368191999,0.83018036473127671,-1,0.8608137425739952,0.8588505029705045,0.851771160191481,0.8566758306531675,0.850738856403224,0.8554488109949241,0.8389133480952646,0.83596386975881582,-1,0.862498225734459,0.8607444676744243,0.8531134965292494,0.8582894598791949,0.852096127001669,0.8569850859485606,0.8426112828620612,0.83979889805952073,-1,0.8623952488942723,0.860698831646548,0.8535218186546497,0.8584680116036802,0.8525241029020164,0.8572703328422709,0.8429631275009771,0.83988730128855321234567891011121314[ { "idx": 0, "name": "0", "path": "", "type": "sentence_transformers.models.Transformer" }, { "idx": 1, "name": "1", "path": "1_Pooling", "type": "sentence_transformers.models.Pooling" }]123version https://git-lfs.github.com/spec/v1oid sha256:a6fa8fa30da7a285b73d88a7d67c9d3b8b76a8d0445a80e36be7d23aebfb3bbcsize 4333224171234{ "max_seq_length": 75, "do_lower_case": false}12epoch,steps,cosine_pearson,cosine_spearman,euclidean_pearson,euclidean_spearman,manhattan_pearson,manhattan_spearman,dot_pearson,dot_spearman-1,-1,0.8372631363001866,0.834704023438753,0.8261134995087104,0.8264020788932519,0.826851359548798,0.8271963936424541,0.8152392240287768,0.80711209914258961{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}1{"do_lower_case": false, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": "/root/.cache/huggingface/transformers/118da8438a7854000cfcf052566f83ae4f4159ac25796e49e16c3b18746041b4.dd8bd9bfd3664b530ea4e645105f557769387b3da9f79bdb55ed556bdd80611d", "name_or_path": "/content/output/biobert_nli/", "do_basic_tokenize": true, "never_split": null, "tokenizer_class": "BertTokenizer"}1_Pooling/config.jsonAdded+7
README.mdAdded+126
config.jsonAdded+24
config_sentence_transformers.jsonAdded+7
eval/similarity_evaluation_sts-dev_results.csvAdded+5
modules.jsonAdded+14
pytorch_model.binAdded+3
sentence_bert_config.jsonAdded+4
similarity_evaluation_sts-test_results.csvAdded+2
special_tokens_map.jsonAdded+1
tokenizer.jsonAdded
tokenizer_config.jsonAdded+1
vocab.txtAdded