A library implementing generalized pooling for sentence transformers
Project description
Sentence Generalized Pooling
This library implements generalized pooling methods for sentence embeddings, based on the research paper "Enhancing Sentence Embedding with Generalized Pooling" by Qian Chen, Zhen-Hua Ling, and Xiaodan Zhu (COLING 2018).
Installation
pip install sentence-generalized-pooling
Usage
from sentence_transformers import SentenceTransformer
from sentence_generalized_pooling import GeneralizedSentenceTransformerMaker
# Load a base model
base_model = SentenceTransformer('all-MiniLM-L6-v2')
# Create a model with generalized pooling
maker = GeneralizedSentenceTransformerMaker(
model_name=base_model,
pooling_type=0, # ADDITIVE pooling
initalize=0, # MEAN initialization
device='cpu'
)
# Get the modified model
model = maker.get_model()
# Use the model
embeddings = model.encode(['Your sentence here'])
Features
- Supports both additive and dot-product pooling mechanisms
- Multiple initialization strategies: mean, noised, and random
- Multi-head attention mechanism
- Compatible with all sentence-transformer models
Citation
If you use this library in your research, please cite:
@inproceedings{chen-etal-2018-enhancing,
title = "Enhancing Sentence Embedding with Generalized Pooling",
author = "Chen, Qian and
Ling, Zhen-Hua and
Zhu, Xiaodan",
booktitle = "Proceedings of the 27th International Conference on Computational Linguistics",
year = "2018",
url = "https://aclanthology.org/C18-1154",
pages = "1815--1826",
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sentence_generalized_pooling-0.2.6.tar.gz.
File metadata
- Download URL: sentence_generalized_pooling-0.2.6.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c443e2ffa03d8b823b6b7c58234cf87ab46f4817a7073a2d7d5b4d980ee375a0
|
|
| MD5 |
d88ba52a01f2de67e130b159a65e518e
|
|
| BLAKE2b-256 |
d55f9bbbdbaf7bb07fb131f1faad8cc4985aa8b2085ccdc1535bd7334306ebce
|
File details
Details for the file sentence_generalized_pooling-0.2.6-py3-none-any.whl.
File metadata
- Download URL: sentence_generalized_pooling-0.2.6-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e77b927fe5b5199a9f8be4358498fcaf14fc8a9df523fd27c38752c457c091d8
|
|
| MD5 |
94c3017b7a17cb3509abb42b2ba7e21a
|
|
| BLAKE2b-256 |
8dd94d49ca12ea4a2c62c1193d47bf97820fdb3d5083dfb1925a10643ad7264e
|