Vibescribe built with Hugging Face Transformers, fine-tuned on IMDB reviews.
1git clone https://github.com/your-username/sentiment-analysis
2cd sentiment-analysis
1python -m venv venv
2source venv/bin/activate # On Windows: venv\Scripts\activate
sentiment-analysis/
├── requirements.txt
├── train.py
├── inference.py
├── utils.py
└── README.md
transformers==4.37.2
datasets==2.16.1
torch==2.1.2
scikit-learn==1.4.0
1from sklearn.metrics import accuracy_score, precision_recall_fscore_support
2
3def compute_metrics(pred):
4 labels = pred.label_ids
5 preds = pred.predictions.argmax(-1)
6 precision, recall, f1, _ = precision_recall_fscore_support(labels, preds, average='binary')
7 return {
8 'accuracy': accuracy_score(labels, preds),
9 'f1': f1,
10 'precision': precision,
11 'recall': recall
12 }
1from transformers import pipeline
2
3def load_model(model_path):
4 return pipeline("sentiment-analysis", model=model_path)
5
6def predict(classifier, text):
7 return classifier(text)
8
9if __name__ == "__main__":
10 model_path = "your-username/sentiment-analysis-model"
11 classifier = load_model(model_path)
12
13 # Example prediction
14 text = "This movie was really great!"
15 result = predict(classifier, text)
16 print(f"Text: {text}\nSentiment: {result}")
1training_args = TrainingArguments(
2 output_dir="sentiment-analysis-model",
3 hub_model_id="your-username/sentiment-analysis-model", # Change this
4 ...
5)
1from inference import load_model, predict
2
3classifier = load_model("your-username/sentiment-analysis-model")
4result = predict(classifier, "Your text here")