What is the best way to batch some code like this? from transformers import…
- User
What is the best way to batch some code like this? from transformers import AutoModelForSequenceClassification, AutoTokenizer from tabulate import tabulate import torch import torch.nn.functional as F
Load the model and tokenizer from the Hugging Face Hub
model_name = "qingy2024/ActionBERT-109M" model = AutoModelForSequenceClassification.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name)
text = "A mushroom exploding in a forest."
inputs = tokenizer(text, truncation=True, max_length=512, padding=True, return_tensors="pt")
with torch.no_grad(): outputs = model(**inputs) action_probability, no_action_probability = F.softmax(outputs.logits[0], dim = 0).tolist()
codetable = [ ['Probability of Action', action_probability], ['Probability of No Action', no_action_probability] ] print(tabulate(table, tablefmt='rounded_grid'))For example if a HF dataset had a column called "name" and I wanted to run the model on all of the "name"s and add a new column called "classification"?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.