Skip to main content

Iterative refinement BERT encoder based on Tiny Recursive Models

Project description

iterative-bert

An iterative refinement BERT encoder based on Tiny Recursive Models.

Installation

pip install iterative-bert

Usage

Load a pre-trained encoder from HuggingFace Hub

from iterative_bert.model import IterativeBert

# Load encoder from HuggingFace Hub
encoder = IterativeBert.from_pretrained("your-username/your-model")

# Run inference
import torch
input_ids = torch.tensor([[101, 2054, 2003, 2023, 102]])  # Example tokens
attention_mask = torch.ones_like(input_ids)
outputs = encoder(input_ids, attention_mask=attention_mask)
hidden_states = outputs.last_hidden_state

Create a new encoder from config

from iterative_bert.model import IterativeBert, IterativeBertConfig

config = IterativeBertConfig(
    vocab_size=30522,
    hidden_size=768,
    num_hidden_layers=1,
    num_attention_heads=12,
    intermediate_size=3072,
    h_cycles=1,
    l_cycles=8,
    use_rope=True,
)

encoder = IterativeBert(config)

Features

  • Iterative Refinement: Applies transformer layers multiple times with residual connections
  • RoPE Support: Rotary Position Embeddings for better length generalization
  • Flash Attention: Optional Flash Attention 2/3 support for efficiency
  • HuggingFace Compatible: Works with from_pretrained and save_pretrained

License

Apache 2.0

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

iterative_bert-0.1.1.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

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

iterative_bert-0.1.1-py3-none-any.whl (38.7 kB view details)

Uploaded Python 3

File details

Details for the file iterative_bert-0.1.1.tar.gz.

File metadata

  • Download URL: iterative_bert-0.1.1.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iterative_bert-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b57e549e994086d362015143c323dc8a6bd372ae1634379c051ee2c847029346
MD5 fe9e5cda325bce1f0754ddcc920b17aa
BLAKE2b-256 1ecdffac7c9827e57d04ab1304038c6b356e59c1f7802092657989561986fe30

See more details on using hashes here.

File details

Details for the file iterative_bert-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: iterative_bert-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 38.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iterative_bert-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8747a8054dafafdbac8a6f7ca1052f40b22968448938b2a0e7702abcc0b92119
MD5 9dbc5b0fbff90cf8019baecfd0bb7c91
BLAKE2b-256 5ef1329b8874ad7a2fe229b51e783177d99ffcecf6f05b445bf3652dee3736b0

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