pipeline_tag: sentence-similarity tags:
- sentence-transformers
- feature-extraction
- sentence-similarity
- transformers
{MODEL_NAME}
This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
Usage (Sentence-Transformers)
Using this model becomes easy when you have sentence-transformers installed:
pip install -U sentence-transformers
Then you can use the model like this:
from sentence_transformers import SentenceTransformer
sentences = ["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, 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.
from transformers import AutoTokenizer, AutoModel
import torch
#Mean Pooling - Take attention mask into account for correct averaging
def 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 for
sentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
model = AutoModel.from_pretrained('{MODEL_NAME}')
# Tokenize sentences
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
model_output = model(**encoded_input)
# Perform pooling. In this case, mean pooling.
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
Evaluation Results
For an automated evaluation of this model, see the Sentence Embeddings Benchmark: https://seb.sbert.net
Training
The model was trained with the parameters:
DataLoader:
torch.utils.data.dataloader.DataLoader of length 500 with parameters:
{'batch_size': 16, 'sampler': 'torch.utils.data.sampler.SequentialSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
Loss:
gpl.toolkit.loss.MarginDistillationLoss
Parameters of the fit()-Method:
{
"epochs": 1,
"evaluation_steps": 0,
"evaluator": "NoneType",
"max_grad_norm": 1,
"optimizer_class": "<class 'transformers.optimization.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": 500,
"warmup_steps": 1000,
"weight_decay": 0.01
}
Full Model Architecture
SentenceTransformer(
(0): Transformer({'max_seq_length': 350, 'do_lower_case': False}) with Transformer model: DistilBertModel
(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
Metadata
Release files for RelevanceAI-dev 2.1.0.2022.4.16.11.3.0.252001
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| RelevanceAI-dev-2.1.0.2022.4.16.11.3.0.252001.tar.gz | 201.6 kB | Without provenance | Details for RelevanceAI-dev-2.1.0.2022.4.16.11.3.0.252001.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| RelevanceAI_dev-2.1.0.2022.4.16.11.3.0.252001-py3-none-any.whl | Python 3 | none | any | Details for RelevanceAI_dev-2.1.0.2022.4.16.11.3.0.252001-py3-none-any.whl |
Total release size: 476.1 kB
Release files / RelevanceAI-dev-2.1.0.2022.4.16.11.3.0.252001.tar.gz
| Download URL | RelevanceAI-dev-2.1.0.2022.4.16.11.3.0.252001.tar.gz |
|---|---|
| Size | 201.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e1e81251609a5fa1dc7a8dc35520bd9c18bb69a254fcac21de3314bf0f36813
|
|
BLAKE2b-256 checksum How to use checksums |
ef7c86e12e6a9a997cda873d54add28941462fb31addc8f204013c450010ae10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Release files / RelevanceAI_dev-2.1.0.2022.4.16.11.3.0.252001-py3-none-any.whl
| Download URL | RelevanceAI_dev-2.1.0.2022.4.16.11.3.0.252001-py3-none-any.whl |
|---|---|
| Size | 274.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef38b9d13955103980581d6052a204a29614bec7a95e84b695d0d0e6c759e015
|
|
BLAKE2b-256 checksum How to use checksums |
9afd01d4d4898671e660db707d38b491063db47b1acaade4d1cbf456de964a24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Security for RelevanceAI-dev 2.1.0.2022.4.16.11.3.0.252001
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.