Instructions to use samyak152002/Tweet_Abortion_Analysis with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use samyak152002/Tweet_Abortion_Analysis with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="samyak152002/Tweet_Abortion_Analysis")# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("samyak152002/Tweet_Abortion_Analysis") model = AutoModel.from_pretrained("samyak152002/Tweet_Abortion_Analysis") - Notebooks
- Google Colab
- Kaggle
| import torch | |
| from transformers import DistilBertTokenizer, DistilBertModel | |
| # Load the tokenizer and model | |
| tokenizer = DistilBertTokenizer.from_pretrained("tokenizer_config.json") | |
| model = DistilBertModel.from_pretrained("pytorch_model.bin") | |
| # Define the inference function | |
| def predict(text): | |
| # Tokenize the input | |
| inputs = tokenizer(text, padding="max_length", truncation=True, return_tensors="pt") | |
| # Perform the inference | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| logits = outputs.logits | |
| # Convert logits to probabilities | |
| probabilities = torch.softmax(logits, dim=1).squeeze().tolist() | |
| return probabilities | |
| # Example usage | |
| text = "This is a sample input." | |
| probabilities = predict(text) | |
| print(probabilities) | |