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.2.tar.gz (34.5 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.2-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: iterative_bert-0.1.2.tar.gz
  • Upload date:
  • Size: 34.5 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.2.tar.gz
Algorithm Hash digest
SHA256 575588df0f81e24c042cf6c653be4f5b826ca16354ef6e4c6e7999d2d6fd1f43
MD5 1f0cda81c2adb5e7d669860794bb5f5b
BLAKE2b-256 a90b9949aa1f6b5f9b1c3a414a059a3996254ae4b4150e27dac8f9a6802183da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: iterative_bert-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 38.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 df430763fff68077daa0b5cc6270b8cfeabe8d81292e59de63954712964c2c62
MD5 e26a8d247a77a33345d69e3e23c4b67c
BLAKE2b-256 c5da1338eac5da8594a23f79eb1b4d70e31af395565b624cedd883555e061ffa

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