Instructions to use Arjun24420/BERT-FakeNews-BinaryClassification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Arjun24420/BERT-FakeNews-BinaryClassification with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Arjun24420/BERT-FakeNews-BinaryClassification")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Arjun24420/BERT-FakeNews-BinaryClassification") model = AutoModelForSequenceClassification.from_pretrained("Arjun24420/BERT-FakeNews-BinaryClassification", device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from Arjun24420/BERT-FakeNews-BinaryClassification: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/Arjun24420/BERT-FakeNews-BinaryClassification/resolve/main/README.md
- Command line
-
hf download hf://Arjun24420/BERT-FakeNews-BinaryClassification/README.md
-
curl -L -o README.md https://huggingface.co/Arjun24420/BERT-FakeNews-BinaryClassification/resolve/main/README.md
2.12 kB
| language: | |
| - en | |
| ### Model Description | |
| This model is a Binary classification model trained on the Liar Dataset using the BERT (bert-base-uncased) architecture. The primary task is to classify news articles into different categories, making it suitable for fake news detection. | |
| BERT (Bidirectional Encoder Representations from Transformers) is a transformer-based model known for its effectiveness in natural language processing tasks. | |
| The model classifies the input text into 2 classes, True (Real News) or False (Fake News). | |
| The original labels include 'true', 'mostly-true', 'half-true', 'barely-true', 'false', and 'pants-fire'. | |
| In this custom mapping, statements labeled as 'true', 'mostly-true', and 'half-true' are all categorized as 'true', while 'barely-true', 'false', and 'pants-fire' are grouped under the 'false' category. | |
| This mapping simplifies the classification task into a binary problem, aiming to distinguish between truthful and non-truthful statements. | |
| Bias: The model may inherit biases present in the training data, and it's important to be aware of potential biases in the predictions. | |
| ## Code Implementation | |
| ```python | |
| # Load model directly | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| # Load the pre-trained model and tokenizer | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| "Arjun24420/BERT-FakeNews-BinaryClassification") | |
| model = AutoModelForSequenceClassification.from_pretrained( | |
| "Arjun24420/BERT-FakeNews-BinaryClassification") | |
| def predict(text): | |
| # Tokenize the input text and move tensors to the GPU if available | |
| inputs = tokenizer(text, padding=True, truncation=True, | |
| max_length=512, return_tensors="pt") | |
| # Get model output (logits) | |
| outputs = model(**inputs) | |
| probs = outputs.logits.softmax(1) | |
| # Get the probabilities for each class | |
| class_probabilities = {class_mapping[i]: probs[0, i].item() | |
| for i in range(probs.shape[1])} | |
| return class_probabilities | |
| # Define class labels mapping | |
| class_mapping = { | |
| 0: 'reliable', | |
| 1: 'unreliable', | |
| } | |
| ``` | |