Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BERT examples with/without HuggingFace? #37

Closed
apoorvnandan opened this issue May 15, 2020 · 3 comments
Closed

BERT examples with/without HuggingFace? #37

apoorvnandan opened this issue May 15, 2020 · 3 comments

Comments

@apoorvnandan
Copy link
Contributor

Regarding examples around BERT, do we use HuggingFace transformers and tokenizers? Because then finetuning and downstream tasks can be shown in small examples like this.

# create model : Input > BERT > Dense
bert = TFBertModel.from_pretrained(config.MODEL_PATH, config=BertConfig())
input_ids = layers.Input(shape=(config.maxlen,), dtype=tf.int32)
sequence_output = bert(input_ids)[0][:, 0, :]
out = layers.Dense(1, activation="sigmoid")(sequence_output)
classifier = models.Model(inputs=input_ids, outputs=out)

classifier.compile(
    optimizers.Adam(lr=3e-5), loss="binary_crossentropy", metrics=[metrics.AUC()]
)
train_history = classifier.fit(train_dataset, steps_per_epoch=150, epochs=30)

And then we can show that doing the same thing on TPU is as easy as adding

tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
strategy = tf.distribute.experimental.TPUStrategy(tpu)

and creating model under strategy.scope().

Does this feel like a good example?

@fchollet
Copy link
Member

Yes, I think demonstrating the use of the HuggingFace Transformers library would be useful. What task/dataset were you thinking of applying it to?

@apoorvnandan
Copy link
Contributor Author

I was thinking about the Question Answering task. SQuAD for data.

@apoorvnandan
Copy link
Contributor Author

Created a PR. Closing this issue.
#46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants