Skip to content

Instantly share code, notes, and snippets.

@RayWilliam46
Last active February 5, 2021 17:02
Show Gist options
  • Save RayWilliam46/46a3adba467b73396b26ae0be370ff47 to your computer and use it in GitHub Desktop.
Save RayWilliam46/46a3adba467b73396b26ae0be370ff47 to your computer and use it in GitHub Desktop.
Imports the base DistilBERT architecture from the Hugging Face library
from transformers import TFDistilBertModel, DistilBertConfig
DISTILBERT_DROPOUT = 0.2
DISTILBERT_ATT_DROPOUT = 0.2
# Configure DistilBERT's initialization
config = DistilBertConfig(dropout=DISTILBERT_DROPOUT,
attention_dropout=DISTILBERT_ATT_DROPOUT,
output_hidden_states=True)
# The bare, pre-trained DistilBERT transformer model outputting raw hidden-states
# and without any specific head on top.
distilBERT = TFDistilBertModel.from_pretrained('distilbert-base-uncased', config=config)
# Make DistilBERT layers untrainable
for layer in distilBERT.layers:
layer.trainable = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment