YAML Metadata
Warning:
empty or missing yaml metadata in repo card
(https://huggingface.co/docs/hub/model-cards#model-card-metadata)
We have finetuned BERT base on Brown corpus to predict if a text was written using a non-fiction straight forward style or a fictional descriptive style. Here fiction and non-fiction only refers to the writing style and not to factual correctness of whats written in the text. For more details, please see this blog and the referenced paper: https://bekushal.medium.com/fictometer-a-simple-and-explainable-algorithm-for-sentiment-analysis-31186d2a8c7e
from transformers import AutoModelForSequenceClassification, AutoTokenizer
# Load the model
model_name = "bekushal/FictoBERT"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Example input text
input_text = "It is a sunny day with a nice wind blowing and I am feeling very happy."
# Preprocess the input
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
# Perform inference
outputs = model(**inputs)
# Get predicted class probabilities
predicted_probabilities = outputs.logits.softmax(dim=-1)
# Get predicted class label
predicted_label = predicted_probabilities.argmax().item()
# Convert predicted label to human-readable format
predicted_class = "fiction" if predicted_label == 1 else "non-fiction"
# Display results
print("Predicted class:", predicted_class)
print("Predicted class probabilities [non-fiction, fiction]:", predicted_probabilities)```
---
license: apache-2.0
---
- Downloads last month
- 2