CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
huggingface

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: huggingface/notebooks
Path: blob/main/course/fa/chapter2/section3_tf.ipynb
Views: 2555
Kernel: Unknown Kernel

مدل‌ها (TensorFlow)

Install the Transformers, Datasets, and Evaluate libraries to run this notebook.

!pip install datasets evaluate transformers[sentencepiece]
from transformers import BertConfig, TFBertModel # Building the config config = BertConfig() # Building the model from the config model = TFBertModel(config)
print(config)
BertConfig { [...] "hidden_size": 768, "intermediate_size": 3072, "max_position_embeddings": 512, "num_attention_heads": 12, "num_hidden_layers": 12, [...] }
from transformers import BertConfig, TFBertModel config = BertConfig() model = TFBertModel(config) # Model is randomly initialized!
from transformers import TFBertModel model = TFBertModel.from_pretrained("bert-base-cased")
model.save_pretrained("directory_on_my_computer")
sequences = ["Hello!", "Cool.", "Nice!"]
encoded_sequences = [ [101, 7592, 999, 102], [101, 4658, 1012, 102], [101, 3835, 999, 102], ]
import tensorflow as tf model_inputs = tf.constant(encoded_sequences)
output = model(model_inputs)