File size: 1,205 Bytes
718739b
 
 
69b917f
b8bbe7e
 
4188199
69b917f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
license: afl-3.0
---

# Overview

This model is based on [bert-base-uncased](https://huggingface.co/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. 

# Define a list of trending topics
```python
trending_topics = [Your choice of topics]
```

# Download the model
```python
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)
```

# Get the output
```python
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)

```