{"id":13534924,"url":"https://github.com/Separius/BERT-keras","last_synced_at":"2025-04-02T00:31:01.806Z","repository":{"id":93627940,"uuid":"154273863","full_name":"Separius/BERT-keras","owner":"Separius","description":"Keras implementation of BERT with pre-trained weights","archived":true,"fork":false,"pushed_at":"2019-07-26T09:36:13.000Z","size":565,"stargazers_count":813,"open_issues_count":7,"forks_count":196,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-11-02T22:32:53.098Z","etag":null,"topics":["keras","language-modeling","nlp","pretrained-models","tensorflow","theano","transfer-learning","transformer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Separius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-23T06:26:07.000Z","updated_at":"2024-10-15T14:51:12.000Z","dependencies_parsed_at":"2023-05-03T22:31:06.172Z","dependency_job_id":null,"html_url":"https://github.com/Separius/BERT-keras","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Separius%2FBERT-keras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Separius%2FBERT-keras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Separius%2FBERT-keras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Separius%2FBERT-keras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Separius","download_url":"https://codeload.github.com/Separius/BERT-keras/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246734975,"owners_count":20825211,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["keras","language-modeling","nlp","pretrained-models","tensorflow","theano","transfer-learning","transformer"],"created_at":"2024-08-01T08:00:46.791Z","updated_at":"2025-04-02T00:31:01.760Z","avatar_url":"https://github.com/Separius.png","language":"Python","funding_links":[],"categories":["Pretrained Language Model","implement of BERT besides tensorflow:","Transformer Implementations By Communities","APIs and Libraries"],"sub_categories":["Repository","Keras","Knowledge Graphs"],"readme":"**Status:** Archive (code is provided as-is, no updates expected)\n\n# BERT-keras\nKeras implementation of Google BERT(Bidirectional Encoder Representations from Transformers) and OpenAI's Transformer LM capable of loading pretrained models with a finetuning API. \n\n*Update*: With TPU support both for inference and training like [this colab notebook](https://colab.research.google.com/gist/HighCWu/3a02dc497593f8bbe4785e63be99c0c3/bert-keras-tutorial.ipynb) thanks to [@HighCWu](https://github.com/HighCWu)\n\n## How to use it?\n```python\n# this is a pseudo code you can read an actual working example in tutorial.ipynb or the colab notebook\ntext_encoder = MyTextEncoder(**my_text_encoder_params) # you create a text encoder (sentence piece and openai's bpe are included)\nlm_generator = lm_generator(text_encoder, **lm_generator_params) # this is essentially your data reader (single sentence and double sentence reader with masking and is_next label are included)\ntask_meta_datas = [lm_task, classification_task, pos_task] # these are your tasks (the lm_generator must generate the labels for these tasks too)\nencoder_model = create_transformer(**encoder_params) # or you could simply load_openai() or you could write your own encoder(BiLSTM for example)\ntrained_model = train_model(encoder_model, task_meta_datas, lm_generator, **training_params) # it does both pretraing and finetuning\ntrained_model.save_weights('my_awesome_model') # save it\nmodel = load_model('my_awesome_model', encoder_model) # load it later and use it!\n```\n\n## Notes\n* The general idea of this library is to use OpenAI's/Google's pretrained model for transfer learning\n* In order to see how the BERT model works, you can check [this colab notebook](https://colab.research.google.com/gist/HighCWu/3a02dc497593f8bbe4785e63be99c0c3/bert-keras-tutorial.ipynb)\n* In order to be compatible with both BERT and OpenAI I had to assume a standard ordering for the vocabulary, I'm using OpenAI's so in the loading function of BERT there is a part to change the ordering; but this is an implementation detail and you can ignore it!\n* Loading OpenAI model is tested with both tensorflow and theano as backend\n* Loading a Bert model is not possible on theano backend yet but the tf version is working and it has been tested\n* Training and fine-tuning a model is not possible with theano backend but works perfectly fine with tensorflow\n* You can use the data generator and task meta data for most of the NLP tasks and you can use them in other frameworks\n* There are some unit tests for both dataset and transformer model (read them if you are not sure about something)\n* Even tough I don't like my keras code, it's readable :)\n* You can use other encoders, like LSTM or BiQRNN for training if you follow the model contract (have the same inputs and outputs as transformer encoder)\n* Why should I use this instead of the official release?, first this one is in Keras and second it has a nice abstraction over token-level and sentence-level NLP tasks which is framework independent\n* Why keras? pytorch version is already out! (BTW you can use this data generator for training and fine-tuning that model too)\n* I strongly advise you to read the tutorial.ipynb (I don't like notebooks so this is a poorly designed notebook, but read it anyway)\n\n## Important code concepts\n* Task: there are two general tasks, sentence level tasks(like is_next and sentiment analysis), and token level tasks(like PoS and NER)\n* Sentence: a sentence represents an example with it's labels and everything, for each task it provides a target(single one for sentence level tasks and per token label for token level tasks) and a mask, for token levels we need to not only ignore paddings but also we might want to predict class on first char of a word (like the BERT paper(first piece of a multi piece word)) and for sentence levels we want a extraction point(like start token in BERT paepr)\n* TaskWeightScheduler: for training we might want to start with language modeling and smoothly move to classification, they can be easily implemented with this class\n* attention_mask: with this you can 1.make your model causal 2.ignore paddings 3.do your crazy idea :D\n* special_tokens: pad, start, end, delimiter, mask\n\n## Ownership\n[Neiron](https://www.neiron.ai)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSeparius%2FBERT-keras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSeparius%2FBERT-keras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSeparius%2FBERT-keras/lists"}