1 Using pretrained models
1.1 pipeline
1.1.1 from transformers import pipeline
camembert_fill_mask = pipeline("fill-mask", model="camembert-base")
results = camembert_fill_mask("Le camembert est <mask> :)")
1.2 instantiate the checkpoint using the model architecture directly
from transformers import CamembertTokenizer, CamembertForMaskedLMtokenizer = CamembertTokenizer.from_pretrained("camembert-base")
model = CamembertForMaskedLM.from_pretrained("camembert-base")
tokenizer and model must be same checkpoint
1.3 recommend using the Auto* classes instead, as these are by design architecture-agnostic(架构无关)
1.3.1 from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("camembert-base")
model = AutoModelForMaskedLM.from_pretrained("camembert-base")
2 Sharing pretrained models
2.1 creating new model repositories
2.1.1 Using the push_to_hub API
notebook_login()
training_args = TrainingArguments("bert-finetuned-mrpc", save_strategy="epoch", push_to_hub=True
)
the Trainer will then upload your model to the Hub each time it is saved (here every epoch)
model.push_to_hub("dummy-model")
tokenizer.push_to_hub("dummy-model", organization="huggingface", use_auth_token="<TOKEN>")
2.1.2 Using the huggingface_hub Python library
create_repo("dummy-model", organization="huggingface")
2.1.3 Using the web interface
from huggingface_hub import upload_fileupload_file("<path_to_file>/config.json",path_in_repo="config.json",repo_id="<namespace>/dummy-model",
)
2.2 The Repository class
2.2.1 Repository class manages a local repository in a git-like manner
2.2.2 repo.git_pull()
repo.git_add()
repo.git_commit()
repo.git_push()
repo.git_tag()
2.3 save the model and tokenizer files to local directory
2.3.1 model.save_pretrained(“<path_to_dummy_folder>”)
2.3.2 tokenizer.save_pretrained(“<path_to_dummy_folder>”)
2.4 use git direct
2.4.1 git clone https://huggingface.co//
3 Building a model card
3.1 sections
3.1.1 Model description
3.1.2 Intended uses & limitations
3.1.3 How to use
3.1.4 Limitations and bias
3.1.5 Training data
3.1.6 Training procedure
3.1.7 Evaluation results
4 objects of the transformers library can be directly shared on the Hub
4.1 tokenizer
4.2 model configuration
4.3 model
4.4 Trainer