Instructions to use traberph/RedBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use traberph/RedBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="traberph/RedBERT")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("traberph/RedBERT") model = AutoModelForSequenceClassification.from_pretrained("traberph/RedBERT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from traberph/RedBERT: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/traberph/RedBERT/resolve/refs%2Fpr%2F1/README.md
- Command line
-
hf download hf://traberph/RedBERT@refs/pr/1/README.md
-
curl -L -o README.md https://huggingface.co/traberph/RedBERT/resolve/refs%2Fpr%2F1/README.md
1.26 kB
| 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"))) | |
| ``` |