File size: 1,261 Bytes
5840657 a572b3d 336f4ff 4382ddc 1cf6297 8b678e0 1cf6297 8b678e0 4f60dd3 8b678e0 4f60dd3 8b678e0 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 |
---
license: apache-2.0
datasets:
- webis/tldr-17
language:
- en
library_name: transformers
pipeline_tag: text-classification
widget:
- text: "Biden says US is at tipping point on gun control: We will ban assault weapons in this country"
example_title: "classification"
---
## Reddit post classification
This model predicts the subreddit of a provided post
The transformers library is required
```
pip install 'transformers[torch]'
```
```py
from transformers import pipeline
pipe = pipeline('text-classification', model='traberph/RedBERT')
pipe("Biden says US is at tipping point on gun control: We will ban assault weapons in this country")
```
## Class Labels
To translate the labels back to subreddit names you need to download the `subreddits.json` file from this repo manually
```py
import json
s_count = 0
s_data = []
with open('subreddits.json', 'r') as file:
s_data = json.load(file)
s_count = len(s_data)
labels = list(s_data.keys())
def translate(d):
d['label'] = s_data[ labels[ int( d['label'].split('_')[1]) ]]
return d
```
Now the class labels can be translated back to subreddits
```py
list(map(translate, pipe("Biden says US is at tipping point on gun control: We will ban assault weapons in this country")))
``` |