--- pipeline_tag: fill-mask license: apache-2.0 base_model: google-bert/bert-large-uncased library_name: kerasformers tags: - keras - kerasformers - bert - uncased - fill-mask - text-encoder - arxiv:1810.04805 - pytorch - jax - tf --- ## ***See [our collection](https://huggingface.co/collections/kerasformers/bert-6a6e8ea40d45e759626f2ab3) for all versions of BERT.*** # Run BERT with Keras 3: JAX, PyTorch, or TensorFlow [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-black?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-BERT-blue)](https://imvision12.github.io/KerasFormers/bert/) [![Collection](https://img.shields.io/badge/HF-BERT%20collection-yellow)](https://huggingface.co/collections/kerasformers/bert-6a6e8ea40d45e759626f2ab3) # kerasformers/bert_large_uncased Paper: [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding (arXiv:1810.04805)](https://arxiv.org/abs/1810.04805) · [HF Papers](https://huggingface.co/papers/1810.04805) BERT is Google's bidirectional transformer text encoder, pretrained with masked LM and next-sentence prediction. WordPiece tokenizer; mask token `[MASK]`. Uncased variants lower-case the input; cased variants preserve case. For more details on the model, please go to the upstream [model card](https://huggingface.co/google-bert/bert-large-uncased). Pure-**Keras 3** conversion of [`google-bert/bert-large-uncased`](https://huggingface.co/google-bert/bert-large-uncased) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**. This is a **fill-mask / encoder** checkpoint (`BertMaskedLM`, large uncased). Task heads (sequence/token classify, QA, NSP, …) load via `hf:` fine-tunes. ## ✨ Quick start (fill-mask) ```python import os os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" from kerasformers.models.bert import BertMaskedLM, BertTokenizer mlm = BertMaskedLM.from_weights("kerasformers/bert_large_uncased") tokenizer = BertTokenizer.from_weights("kerasformers/bert_large_uncased") inputs = tokenizer("the capital of france is [MASK].") logits = mlm(inputs) # (1, L, vocab_size) mask = int((inputs["input_ids"][0] == tokenizer.mask_token_id).argmax()) print(tokenizer.ids_to_tokens[int(logits[0, mask].argmax())]) ``` Load any BERT variant the same way with `from_weights("kerasformers/")`: | Variant | Hub | Casing | |---|---|---| | `bert_base_uncased` | [`kerasformers/bert_base_uncased`](https://huggingface.co/kerasformers/bert_base_uncased) | uncased | | `bert_large_uncased` | [`kerasformers/bert_large_uncased`](https://huggingface.co/kerasformers/bert_large_uncased) | uncased | | `bert_base_cased` | [`kerasformers/bert_base_cased`](https://huggingface.co/kerasformers/bert_base_cased) | cased | | `bert_large_cased` | [`kerasformers/bert_large_cased`](https://huggingface.co/kerasformers/bert_large_cased) | cased | ## Tips - Set `KERAS_BACKEND` **before** importing Keras / kerasformers. - Prefer `BertTokenizer.from_weights(...)` so WordPiece casing matches. - Use `[MASK]` (not ``). - See [BERT docs](https://imvision12.github.io/KerasFormers/bert/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/). - Community / upstream safetensors still work via the `hf:` prefix, e.g. `BertMaskedLM.from_weights("hf:google-bert/bert-large-uncased")`. ## Special Thanks A huge thank you to the Google BERT authors for creating and releasing these models. License: Apache 2.0.