Update README.md
Browse files
README.md
CHANGED
|
@@ -8,6 +8,36 @@ library_name: transformers
|
|
| 8 |
pipeline_tag: text-classification
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
This model predicts the subreddit of a provided post
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
pipeline_tag: text-classification
|
| 9 |
---
|
| 10 |
|
| 11 |
+
## Reddit post classification
|
| 12 |
|
| 13 |
+
This model predicts the subreddit of a provided post
|
| 14 |
+
|
| 15 |
+
```py
|
| 16 |
+
from transformers import pipeline
|
| 17 |
+
pipe = pipeline('text-classification', model='traberph/RedBERT')
|
| 18 |
+
pipe("Biden says US is at tipping point on gun control: We will ban assault weapons in this country")
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## Class Labels
|
| 22 |
+
|
| 23 |
+
To translate the labels back to subreddit names you need to download the subreddits.json file from this repo manually
|
| 24 |
+
|
| 25 |
+
```py
|
| 26 |
+
import json
|
| 27 |
+
s_count = 0
|
| 28 |
+
s_data = []
|
| 29 |
+
with open('subreddits.json', 'r') as file:
|
| 30 |
+
s_data = json.load(file)
|
| 31 |
+
s_count = len(s_data)
|
| 32 |
+
labels = list(s_data.keys())
|
| 33 |
+
|
| 34 |
+
def translate(d):
|
| 35 |
+
d['label'] = s_data[ labels[ int( d['label'].split('_')[1]) ]]
|
| 36 |
+
return d
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Now the class labels can be translated back to subreddits
|
| 40 |
+
|
| 41 |
+
```py
|
| 42 |
+
list(map(translate, pipe("Biden says US is at tipping point on gun control: We will ban assault weapons in this country")))
|
| 43 |
+
```
|