Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sentence_generalized_pooling-0.9.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sentence_generalized_pooling-0.9.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file sentence_generalized_pooling-0.9.0.tar.gz.

File metadata

File hashes

Hashes for sentence_generalized_pooling-0.9.0.tar.gz
Algorithm Hash digest
SHA256 a4cd1a938e07af46d7e622beeedebd8e658d2fe203c6f3b831e9514b9693bfc8
MD5 908b94674f9cf83ebe47d4b36889a7f4
BLAKE2b-256 ccb0bda3300abc37ad0e515ab7498c96e4b5f5cfd3124c6d35d70a1b45ad5640

See more details on using hashes here.

File details

Details for the file sentence_generalized_pooling-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sentence_generalized_pooling-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3784144cffddc5c6dccb9c2dd7ddb25c2be91efe1b867a22a199927ac1bc040a
MD5 275f277397a96863730a893c646a9ff2
BLAKE2b-256 2fdf3bb4a51ba04b23d933e9511e1dd407415339f9982f90e84b6f383376fcc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page