<jupyter_start><jupyter_text>1. download pre_trained bert model<jupyter_code>from keras_bert import get_pretrained, PretrainedList, get_checkpoint_paths

model_path = get_pretrained(PretrainedList.multi_cased_base)# 600M
paths = get_checkpoint_paths(model_path)
print(paths.config, paths.checkpoint, paths.vocab)<jupyter_output>Downloading data from https://storage.googleapis.com/bert_models/2018_11_23/multi_cased_L-12_H-768_A-12.zip
662904832/662903077 [==============================] - 271s 0us/step
/root/.keras/datasets/multi_cased_L-12_H-768_A-12/bert_config.json /root/.keras/datasets/multi_cased_L-12_H-768_A-12/bert_model.ckpt /root/.keras/datasets/multi_cased_L-12_H-768_A-12/vocab.txt<jupyter_text>2. extract embeddings<jupyter_code>from keras_bert import extract_embeddings, POOL_NSP, POOL_MAX


texts = [
    ('all work and no play'),
    ('makes jack a dull boy'),
]

embeddings = extract_embeddings(model_path, texts, output_layer_num=4, poolings=[POOL_NSP, POOL_MAX])
import numpy as np

embeddings = np.array(embeddings)
embeddings.shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13167587476979742, 'fraction_numerical': 0.058931860036832415, 'mean_word_length': 7.234848484848484, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '352415', 'license': 'MIT', 'n_tokens_mistral': 457, 'n_tokens_neox': 411, 'n_words': 58, 'path': 'bert/keras_bert_pretrained_model.ipynb', 'repo_name': 'ybdesire/machinelearning', 'size': '1086'}