đ keyphrase-mpnet-v1
This is a sentence-transformers model specialized for phrases. It maps phrases to a 768-dimensional dense vector space and can be used for tasks such as clustering or semantic search. In the original paper, this model is used for calculating semantic-based evaluation metrics of keyphrase models. This model is based on sentence-transformers/all-mpnet-base-v2 and further fine-tuned on 1 million keyphrase data with SimCSE.
đ Quick Start
This model is designed to map phrases to a 768-dimensional dense vector space, enabling tasks like clustering and semantic search. It's based on sentence-transformers/all-mpnet-base-v2 and fine - tuned on keyphrase data.
⨠Features
- Specialized for phrases, mapping them to a 768-dimensional dense vector space.
- Applicable for clustering and semantic search tasks.
- Used for calculating semantic-based evaluation metrics of keyphrase models in the original paper.
đĻ Installation
Using this model becomes easy when you have sentence-transformers installed:
pip install -U sentence-transformers
đģ Usage Examples
Basic Usage
from sentence_transformers import SentenceTransformer
phrases = ["information retrieval", "text mining", "natural language processing"]
model = SentenceTransformer('uclanlp/keyphrase-mpnet-v1')
embeddings = model.encode(phrases)
print(embeddings)
Advanced Usage
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
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
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)
phrases = ["information retrieval", "text mining", "natural language processing"]
tokenizer = AutoTokenizer.from_pretrained('uclanlp/keyphrase-mpnet-v1')
model = AutoModel.from_pretrained('uclanlp/keyphrase-mpnet-v1')
encoded_input = tokenizer(phrases, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Phrase embeddings:")
print(sentence_embeddings)
đ Documentation
Training
The model is trained on phrases from four keyphrase datasets covering a wide range of domains.
Property |
Details |
Dataset Name |
KP20k (Science, 715369 phrases), KPTimes (News, 113456 phrases), StackEx (Online Forum, 8149 phrases), OpenKP (Web, 200335 phrases), Total: 1030309 phrases |
DataLoader |
torch.utils.data.dataloader.DataLoader of length 2025 with parameters: {'batch_size': 512, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'} |
Loss |
sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss with parameters: {'scale': 20.0, 'similarity_fct': 'cos_sim'} |
Fit() - Method Parameters |
{ "epochs": 1, "evaluation_steps": 0, "evaluator": "NoneType", "max_grad_norm": 1, "optimizer_class": "<class 'torch.optim.adamw.AdamW'>", "optimizer_params": { "lr": 1e-06 }, "scheduler": "WarmupLinear", "steps_per_epoch": null, "warmup_steps": 203, "weight_decay": 0.01 } |
Full Model Architecture
SentenceTransformer(
(0): Transformer({'max_seq_length': 12, 'do_lower_case': False}) with Transformer model: MPNetModel
(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})
)
đ License
Citing & Authors
Paper: KPEval: Towards Fine-grained Semantic-based Keyphrase Evaluation
@inproceedings{wu-etal-2024-kpeval,
title = "{KPE}val: Towards Fine-Grained Semantic-Based Keyphrase Evaluation",
author = "Wu, Di and
Yin, Da and
Chang, Kai-Wei",
editor = "Ku, Lun-Wei and
Martins, Andre and
Srikumar, Vivek",
booktitle = "Findings of the Association for Computational Linguistics ACL 2024",
month = aug,
year = "2024",
address = "Bangkok, Thailand and virtual meeting",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2024.findings-acl.117",
pages = "1959--1981",
}