Views
No views yet
1from transformers import AutoModelForMaskedLM, AutoTokenizer
2import torch
3
4model = AutoModelForMaskedLM.from_pretrained("appleroll/coberta-base")
5tokenizer = AutoTokenizer.from_pretrained("appleroll/coberta-base")
6
7text = "The key to effective communication is to [MASK] clearly and listen actively."
8inputs = tokenizer(text, return_tensors="pt")
9
10with torch.no_grad():
11 outputs = model(**inputs)
12 predictions = outputs.logits
13
14# Get top predictions for [MASK]
15mask_token_index = torch.where(inputs.input_ids == tokenizer.mask_token_id)[1]
16mask_token_logits = predictions[0, mask_token_index, :]
17top_5_tokens = torch.topk(mask_token_logits, 5, dim=1).indices[0].tolist()
18
19for token in top_5_tokens:
20 print(f"{tokenizer.decode([token])}")1@misc{coberta,
2 title = {CoBERTa: Consumer-friendly Models that Punch Above Weight},
3 url = {https://huggingface.co/appleroll/coberta-base},
4 author = {Zhang, Ethan},
5 year = {2025}
6}