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.0.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.0-py3-none-any.whl (38.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iterative_bert-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 9179765edcc33cb3a111fb6ec6126a9904b4f54e040e2bc44425d67ce7caf5dd
MD5 05e1a223dd3f4093d91d5da6942bf1ce
BLAKE2b-256 dbeed8c79b843616fb788460725581e264c698db58f340b7c1986672e0473034

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iterative_bert-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b53547b6ade89a0629bd7bcd533ffe17f99e5462dbb799720b1668013ef1d8a
MD5 2b9ba82fe15644f99488e9f681e5e871
BLAKE2b-256 f193396a1f2249171d902eaaf2bdae71d92f4727923422a8573fd4ee8b03753a

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