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
Usage
After installing the package you may use extend-context scripts for embeddings interpolation. The script modifies 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.
Recommended option is to set --interpolation_type=cubic as this provides smooth interpolation in contrast to linear interpolation. For models like RoBERTa that use special tokens in the first few positions, remember to set appropriate --offset argument. Too big --max_seq_length argument values may result in performance degradation.
Use extend-context --help to see all available options and parameters.
Spline Interpolation
Use this for smooth, nonlinear interpolation:
extend-context \
--model_name_or_path="intfloat/e5-large-v2" \
--max_seq_length=1024 \
--embeddings_attr_name="embeddings.position_embeddings" \
--offset=0 \
--interpolation_type=cubic \
--output_dir="intfloat/e5-large-v2-ctx1024-spline"
Linear Interpolation
Use this for linear interpolation:
extend-context \
--model_name_or_path="intfloat/e5-large-v2" \
--max_seq_length=1024 \
--embeddings_attr_name="embeddings.position_embeddings" \
--offset=0 \
--interpolation_type=linear \
--output_dir="intfloat/e5-large-v2-ctx1024-linear"
Metadata
Release files for context-extension 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| context_extension-0.1.3.tar.gz | 9.5 kB | With provenance | Details for context_extension-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| context_extension-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for context_extension-0.1.3-py3-none-any.whl |
Total release size: 20.9 kB
Release files / context_extension-0.1.3.tar.gz
| Download URL | context_extension-0.1.3.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
284d01b0a871f5a5b48f5c6f8bb2e8f5583591db3818d406e5caaae7633769ea
|
|
BLAKE2b-256 checksum How to use checksums |
2fa4af7ff6041c86b5744caf65ddb9c1c3130c5f279c5d4fe9afd2cbc318bf32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 8, 2025.
Transparency logRelease files / context_extension-0.1.3-py3-none-any.whl
| Download URL | context_extension-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
772370eedd6b6c3da554cb9a42c277b2aca0c72b18aadc6eca92bf4f968aa680
|
|
BLAKE2b-256 checksum How to use checksums |
4b7d6cdfcc6e7defa1d69f39dee74785eea9d5c04ff8c6e0d8e1e0e05c00fceb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 8, 2025.
Transparency logSecurity for context-extension 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for context_extension-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 8, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.