google-research / bert

TensorFlow code and pre-trained models for BERT
https://arxiv.org/abs/1810.04805
Apache License 2.0
38.23k stars 9.62k forks source link

bert loading #1391

Open namai-dev opened 1 year ago

namai-dev commented 1 year ago

why is it cant work

import tensorflow as tf from transformers import BertTokenizer, TFBertForSequenceClassification

bert_base_dir = "/path/to/bert/uncased_L-12_H-768_A-12" model_path = bert_base_dir + "/bert_model.ckpt" config_path = bert_base_dir + "/bert_config.json" vocab_path = bert_base_dir + "/vocab.txt"

tokenizer = BertTokenizer.from_pretrained(vocab_path)

model = TFBertForSequenceClassification.from_pretrained( config_path, num_labels=2,
from_pt=True )