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", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 762 Bytes
02fd376 bc9b616 02fd376 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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)
|