Text Classification
Transformers
Safetensors
English
distilbert
sentiment-analysis
Eval Results (legacy)
text-embeddings-inference
Instructions to use bmdavis/my-language-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bmdavis/my-language-model with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="bmdavis/my-language-model")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("bmdavis/my-language-model") model = AutoModelForSequenceClassification.from_pretrained("bmdavis/my-language-model", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| import torch | |
| # Load the pretrained sentiment model | |
| model_name = "distilbert-base-uncased-finetuned-sst-2-english" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForSequenceClassification.from_pretrained(model_name) | |
| # Function to classify sentiment | |
| def analyze_sentiment(text): | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True) | |
| outputs = model(**inputs) | |
| probs = torch.softmax(outputs.logits, dim=1) | |
| prediction = torch.argmax(probs).item() | |
| label = "positive" if prediction == 1 else "negative" | |
| return label, probs[0][prediction].item() | |
| # Try it out! | |
| if __name__ == "__main__": | |
| print("🧠 Sentiment Analyzer (type 'exit' to quit)\n") | |
| while True: | |
| sentence = input("Enter a sentence: ").strip() | |
| if sentence.lower() in ["exit", "quit"]: | |
| print("👋 Goodbye!") | |
| break | |
| sentiment, confidence = analyze_sentiment(sentence) | |
| print(f"🧠 Sentiment: {sentiment.capitalize()} (Confidence: {confidence:.2f})\n") |