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.2.7.tar.gz (5.5 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.2.7-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for sentence_generalized_pooling-0.2.7.tar.gz
Algorithm Hash digest
SHA256 29747b20dcbfe264635dd500a783e26b528d48aa2328e55f5fdeb050ba838e9d
MD5 7c7d0af0f131e3d4bada1222d46abe98
BLAKE2b-256 2c436c745411ea87f644d866ab423920b5f3c7117f6c69666e8b8b5274617204

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sentence_generalized_pooling-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c890fa639731ea320d8b8387667265449a29a3b650f90c39e305cf95654ee7fb
MD5 4f7d8a5821ac0cbad6a7516a7730727c
BLAKE2b-256 6829b81335e6adf4346dc50ebad5499eb557bab3829d70d635eaba286b0dee5d

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