Skip to main content

Zero-Training Context Extension for Transformer Encoders via Nonlinear Absolute Positional Embeddings Interpolation

Project description

Zero-Training Context Extension for Transformer Encoders via Nonlinear Absolute Positional Embeddings Interpolation

Official implementation of "Zero-Training Context Extension for Transformer Encoders via Nonlinear Absolute Positional Embeddings Interpolation". Paper preprint is coming soon.

This implementation currently supports only models compatible with Sentence Transformers library.

Models

Models are available at HuggingFace:

Model Context length Language
idanylenko/e5-large-v2-ctx1024 1024 English

Installation

To install the package, use pip:

pip install "context-extension>=0.1.1"

Usage

After installing the package you may use extend-context-spline (recommended) or extend-context-linear scripts for embeddings interpolation.

Spline Interpolation

Use this for smooth, nonlinear interpolation to support arbitrary context lengths:

extend-context-spline \
  --model_name_or_path="intfloat/e5-large-v2" \
  --max_seq_length=1024 \
  --embeddings_attr_name="embeddings.position_embeddings" \
  --offset=0 \
  --output_dir="intfloat/e5-large-v2-ctx1024-spline"

Linear Interpolation

Use this to double the model's positional embedding range using linear averaging between consecutive embeddings:

extend-context-linear \
  --model_name_or_path="intfloat/e5-large-v2" \
  --embeddings_attr_name="embeddings.position_embeddings" \
  --offset=0 \
  --output_dir="intfloat/e5-large-v2-ctx1024-linear"

Both commands modify the positional embeddings of a model and save the updated model to the specified directory. You can then upload the resulting model to Hugging Face or use it locally for inference.

For models like RoBERTa that use special tokens in the first few positions, remember to set appropriate --offset argument.

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

context_extension-0.1.2.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

context_extension-0.1.2-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file context_extension-0.1.2.tar.gz.

File metadata

  • Download URL: context_extension-0.1.2.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for context_extension-0.1.2.tar.gz
Algorithm Hash digest
SHA256 eb998c90f4117f98ab6a8f73db827615cc3401c95b24b12b3cd603bd30e329df
MD5 a02f35e75f0e9a71f2c04017d44bc294
BLAKE2b-256 b8a7cf54543207597a7e6ed4f5b76f911b410209ba9f5cb22e5e35a0d50c9eb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_extension-0.1.2.tar.gz:

Publisher: python-publish.yml on Kowd-PauUh/encoders-context-extension

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file context_extension-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for context_extension-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 83d78ea0a00b48cae977ccc914aedad17480ff21dbd42e24d993eac9be35555c
MD5 a1d22a3e476c76322ef54751ff0915c2
BLAKE2b-256 dc9c81c33d0e854d390e053ed8db0486d775c75429d18608aeaf8fd147bfb405

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_extension-0.1.2-py3-none-any.whl:

Publisher: python-publish.yml on Kowd-PauUh/encoders-context-extension

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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