Add model files directly in the repo

#1
by nthngdy - opened

You can integrate code in the repo and then use the model via AutoModel.
Following the format of: https://huggingface.co/THUDM/chatglm-6b/tree/main

nthngdy changed pull request title from Add configuration file to Add model files directly in the repo

Should work now!
Here is a code snippet to try it out:

from transformers import AutoModel, AutoTokenizer

#Will remove revision=... if PR is merged
tokenizer = AutoTokenizer.from_pretrained("helboukkouri/character-bert", revision="pr/1", trust_remote_code=True)
model = AutoModel.from_pretrained("helboukkouri/character-bert", revision="pr/1", trust_remote_code=True)

text = "Paris is the capital of [MASK] ."
results = model(**tokenizer([text], return_tensors="pt")).prediction_logits
pred_ids = results.argmax(-1)

pred_str = ' '.join([tokenizer.ids_to_tokens[el.item()] for el in pred_ids[0]][1:-1])
# Outputs "paris is the capital of france ."
helboukkouri changed pull request status to merged

Hey @nthngdy , thanks for the contribution ! I was not aware that we could add source files directly to the repo. Very welcome update :)

I've applied the same changes to the character-bert-medical repo as well. Thanks again :)

You're welcome! :)

Sign up or log in to comment