Downloads · 30 days
36
2% of all-time downloads
vivianhuang88/bert_twitter_hashtag
bert_twitter_hashtag is a fill-mask model from vivianhuang88. Use it when you need the model to fill a missing word. It is set up for transformers. The card lists the license as afl-3.0.
This model is based on bert-base-uncased model and trained on more than 30k tweets that scraped from Twitter. By inputing some sentences with a '[MASK]' indicating the location you would like to fill in with a hashtag…
Downloads · 30 days
36
2% of all-time downloads
All-time downloads
1.7K
Public
Repo size
4.8 GB
Likes
0
Public
Click a slice to open those files.
.bin441 MB · 100%
From the Hugging Face model README
This model is based on bert-base-uncased model and trained on more than 30k tweets that scraped from Twitter. By inputing some sentences with a '[MASK]' indicating the location you would like to fill in with a hashtag, our model can generate potential related trending topics according to your tweet context.
trending_topics = [Your choice of topics]
from transformers import pipeline, BertTokenizer
import numpy as np
MODEL = "vivianhuang88/bert_twitter_hashtag"
fill_mask = pipeline("fill-mask", model=MODEL, tokenizer=MODEL)
tokenizer = BertTokenizer.from_pretrained(MODEL, additional_special_tokens=trending_topics)
def print_candidates(text, candidates):
for i in range(5):
token = tokenizer.decode(candidates[i]['token'])
topic = ''.join(token.split())
output = text.replace("[MASK]", topic)
print(output)
text = "Bruce has an electric guitar set in [MASK]. "
candidates = fill_mask(text, targets = trending_topics)
print_candidates(text, candidates)