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/zh-CN/chapter2/section8_pt.ipynb
Views: 2549
Kernel: Unknown Kernel

章末小测验 (PyTorch)

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

!pip install datasets evaluate transformers[sentencepiece]
from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained("bert-base-cased") result = tokenizer.tokenize("Hello!")
from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("bert-base-cased") model = AutoModel.from_pretrained("gpt2") encoded = tokenizer("Hey!", return_tensors="pt") result = model(**encoded)