Downloads · 30 days
26
0% of all-time downloads
ehdwns1516/bert-base-uncased_SWAG
bert-base-uncased_SWAG is a multiple choice model from ehdwns1516. Use it for the multiple choice task on the model card, and read the license before you ship it in a product. It is set up for transformers.
This model has been trained as a SWAG dataset.
Downloads · 30 days
26
0% of all-time downloads
All-time downloads
8.4K
Public
Repo size
876 MB
Likes
1
Public
Click a slice to open those files.
.bin438 MB · 100%
From the Hugging Face model README
This model has been trained as a SWAG dataset.
Sentence Inference Multiple Choice DEMO: Ainize DEMO
Sentence Inference Multiple Choice API: Ainize API
Language model: bert-base-uncased
Language: English
Training data: SWAG dataset
Code: See Ainize Workspace
from transformers import AutoTokenizer, AutoModelForMultipleChoice
tokenizer = AutoTokenizer.from_pretrained("ehdwns1516/bert-base-uncased_SWAG")
model = AutoModelForMultipleChoice.from_pretrained("ehdwns1516/bert-base-uncased_SWAG")
def run_model(candicates_count, context: str, candicates: list[str]):
assert len(candicates) == candicates_count, "you need " + candicates_count + " candidates"
choices_inputs = []
for c in candicates:
text_a = "" # empty context
text_b = context + " " + c
inputs = tokenizer(
text_a,
text_b,
add_special_tokens=True,
max_length=128,
padding="max_length",
truncation=True,
return_overflowing_tokens=True,
)
choices_inputs.append(inputs)
input_ids = torch.LongTensor([x["input_ids"] for x in choices_inputs])
output = model(input_ids=input_ids)
return {"result": candicates[torch.argmax(output.logits).item()]}
items = list()
count = 4 # candicates count
context = "your context"
for i in range(int(count)):
items.append("sentence")
result = run_model(count, context, items)